Previous Thread  Next Thread

chat icon blender materials and x3d exporter

undeuxtroisquattre

Posted: Sun Feb 03, 2013 4:42 pm
Joined: 03 Feb 2013
Posts: 4
Hello,

Can anyone explain the material property mapping used to export x3d scenes.

The writeMaterial function tweaks blender material properties a lot before exporting them and these tweaks cannot be inverted.

export_x3d.py :
Code:

def writeMaterial(ident, material, world):
        material_id = quoteattr(unique_name(material, MA_ + material.name, uuid_cache_material, clean_func=clean_def, sep="_"))

        # look up material name, use it if available
        if material.tag:
            fw('%s<Material USE=%s />\n' % (ident, material_id))
        else:
            material.tag = True

            emit = material.emit
            ambient = material.ambient / 3.0
            diffuseColor = material.diffuse_color[:]
            if world:
                ambiColor = ((material.ambient * 2.0) * world.ambient_color)[:]
            else:
                ambiColor = 0.0, 0.0, 0.0

            emitColor = tuple(((c * emit) + ambiColor[i]) / 2.0 for i, c in enumerate(diffuseColor))
            shininess = material.specular_hardness / 512.0
            specColor = tuple((c + 0.001) / (1.25 / (material.specular_intensity + 0.001)) for c in material.specular_color)
            transp = 1.0 - material.alpha

            if material.use_shadeless:
                ambient = 1.0
                shininess = 0.0
                specColor = emitColor = diffuseColor

            ident_step = ident + (' ' * (-len(ident) + \
            fw('%s<Material ' % ident)))
            fw('DEF=%s\n' % material_id)
            fw(ident_step + 'diffuseColor="%.3f %.3f %.3f"\n' % clamp_color(diffuseColor))
            fw(ident_step + 'specularColor="%.3f %.3f %.3f"\n' % clamp_color(specColor))
            fw(ident_step + 'emissiveColor="%.3f %.3f %.3f"\n' % clamp_color(emitColor))
            fw(ident_step + 'ambientIntensity="%.3f"\n' % ambient)
            fw(ident_step + 'shininess="%.3f"\n' % shininess)
            fw(ident_step + 'transparency="%s"\n' % transp)
            fw(ident_step + '/>\n')


Thank's
Reply with quote


stiv

Posted: Sun Feb 03, 2013 5:31 pm
Joined: 05 Aug 2003
Posts: 3493
Not sure what you are referring to specifically, but I suspect the 'tweaks' are to translate from one set of metaphors to another.

The main issue with import/export is not converting the numbers, but translating from the way one program looks at the world to another's view. Examples might be simple, like converting from Z pointing up to Z pointing into the screen. A more complex example might be converting from Blender's view of Materials and Textures being separate entities to one where Material encapsulates both concepts.
Reply with quote


undeuxtroisquattre

Posted: Sun Feb 03, 2013 6:04 pm
Joined: 03 Feb 2013
Posts: 4
My main problem is I can't reproduce blender rendering using data from x3d export.

X3D specification doesn't suggest these tweaks are required and I think there are wrong. However I'm not a blender specialist and maybe I'm misunderstanding something.

http://www.web3d.org/files/specifications/19775-1/V3.2/Part01/components/lighting.html#Lightingmodel

X3D just uses a standard Blinn model with light attenuation and Blender seems to use the exact same one (if we configure materials with Lambert+Blinn).

The most disturbing parts of writeMaterial are the emissive color and the specular color :

Code:

emitColor = tuple(((c * emit) + ambiColor[i]) / 2.0 for i, c in enumerate(diffuseColor))


Code:

specColor = tuple((c + 0.001) / (1.25 / (material.specular_intensity + 0.001)) for c in material.specular_color)


Why not :

Code:

emitColor = emit * diffuseColor


Code:

specColor = material.specular_color * material.specular_intensity
Reply with quote


undeuxtroisquattre

Posted: Mon Feb 04, 2013 8:28 pm
Joined: 03 Feb 2013
Posts: 4
Should I move this question in another section ? Confused
Reply with quote


CoDEmanX

Posted: Mon Feb 04, 2013 9:17 pm
Joined: 05 Apr 2009
Posts: 696
i don't think that's a problem, rather no one can give you an answer. Maybe try to find a dev who knows (probably ideasman42) on IRC, freenode.net #blendercoders
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Reply with quote


undeuxtroisquattre

Posted: Tue Feb 05, 2013 11:45 am
Joined: 03 Feb 2013
Posts: 4
CoDEmanX wrote:
i don't think that's a problem, rather no one can give you an answer. Maybe try to find a dev who knows (probably ideasman42) on IRC, freenode.net #blendercoders


Thank's !
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group