blender materials and x3d exporter

The interface, modeling, 3d editing tools, import/export, feature requests, etc

Moderators: jesterKing, stiv

undeuxtroisquattre
Posts: 4
Joined: Sun Feb 03, 2013 4:33 pm

blender materials and x3d exporter

Postby undeuxtroisquattre » Sun Feb 03, 2013 4:42 pm

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: Select all

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

stiv
Posts: 3646
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Postby stiv » Sun Feb 03, 2013 5:31 pm

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.

undeuxtroisquattre
Posts: 4
Joined: Sun Feb 03, 2013 4:33 pm

Postby undeuxtroisquattre » Sun Feb 03, 2013 6:04 pm

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: Select all

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


Code: Select all

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


Why not :

Code: Select all

emitColor = emit * diffuseColor


Code: Select all

specColor = material.specular_color * material.specular_intensity

undeuxtroisquattre
Posts: 4
Joined: Sun Feb 03, 2013 4:33 pm

Postby undeuxtroisquattre » Mon Feb 04, 2013 8:28 pm

Should I move this question in another section ? :?

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Mon Feb 04, 2013 9:17 pm

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...

undeuxtroisquattre
Posts: 4
Joined: Sun Feb 03, 2013 4:33 pm

Postby undeuxtroisquattre » Tue Feb 05, 2013 11:45 am

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 !


Return to “Interface & Tools”

Who is online

Users browsing this forum: No registered users and 1 guest