0
votes

I'm working on developing a workflow for making scenes in Maya, exporting them with the ThreeJS JSON exporter and loading them via JSONLoader.

I want it to be set up so that I can have multiple objects, materials, and animations all stored in one JSON file with little to no code manipulation per scene.

Right now I'm running into a problem where some materials need to use an environment map. Actually, that's not the problem. The problem is that I can't figure out a good way to set the "reflectivity" value.

Currently, I have it set up so that if I have "Reflective" in the name of the material in maya, the loader will automatically apply an envMap.

        loader.load( "./3Dobjects/Materials.js", function( geometry, materials ) {
            materials[ 0 ].morphTargets = true;
            for (var k in materials){
                materials[k].skinning = true;
            }

            //In Maya, add the word "Reflective" to any material that should have environment reflections.
            for(var i = 0; i < materials.length; i++){
                    if(materials[i].name.indexOf("Reflective")>-1 ){
                        materials[i].envMap = envTexBlurred;
                    }
            }

            jsonMesh = new THREE.SkinnedMesh( geometry, new THREE.MeshFaceMaterial( materials ) );
            scene.add( jsonMesh );

            animation = new THREE.Animation( jsonMesh, geometry.animations[0] );
            animation.play();

        });

As far as I can tell, the ThreeJS maya exporter doesn't read the reflectivity value from any given material (lambert, phong, etc). I'm ok with adding this value to the JSON file, but it doesn't seem to get passed into the material when it gets created by the loader.

for example, in this excerpt from the JSON file, I've added a value for "reflectivity" but it gets ignored.

{
  "DbgName": "phongReflective", 
  "blending": "NormalBlending", 
  "colorAmbient": [
    0.0, 
    1.0, 
    0.0
  ], 
  "colorDiffuse": [
    1, 
    1, 
    1
  ], 
  "colorSpecular": [
    0.5, 
    0.5, 
    0.5
  ], 
  "reflectivity": 0.1,
  "depthTest": true, 
  "depthWrite": true, 
  "shading": "Phong", 
  "specularCoef": 20, 
  "opacity": 1.0, 
  "transparent": false, 
  "vertexColors": false
}

I'm not super good with Javascript or web development in general. I'm a 3D artist, so I apologize if this is a super basic question. How can I parse through the JSON file to automatically apply whatever reflectivity value I've added into the JSON file?

1

1 Answers

0
votes
<script>
json = [{
  "DbgName": "phongReflective", 
  "blending": "NormalBlending", 
  "colorAmbient": [
    0.0, 
    1.0, 
    0.0
  ], 
  "colorDiffuse": [
    1, 
    1, 
    1
  ], 
  "colorSpecular": [
    0.5, 
    0.5, 
    0.5
  ], 
  "reflectivity": 0.1,
  "depthTest": true, 
  "depthWrite": true, 
  "shading": "Phong", 
  "specularCoef": 20, 
  "opacity": 1.0, 
  "transparent": false, 
  "vertexColors": false
}];
console.log(json[0]["reflectivity"]);

//// OR

var reflectivity = json[0]["reflectivity"];


</script>