简体   繁体   中英

Three.js material creation from exported blender source

I exported a simple white material with my geometry from blender. Three.js loader somehow created a MeshPhongMaterial "type" object from the source JSON file:

     ...
     "materials":[{
        "colorEmissive":[0,0,0],
        "colorDiffuse":[0.8,0.8,0.8],
        "DbgName":"Material",
        "wireframe":false,
        "opacity":1,
        "shading":"phong",
        "colorSpecular":[0.5,0.5,0.5],
        "blending":1,
        "transparent":false,
        "specularCoef":50,
        "doubleSided":false,
        "DbgIndex":0,
        "DbgColor":15658734,
        "depthTest":true,
        "depthWrite":true,
        "visible":true
    }],
    ...

I want to clone then reuse the geometry in different colors but I did not found how the loader manage to build the object from the source. I read the documentation but I have not found anything that could help me. The settable properties on Material and PhongMaterial are not similar to this source. Could you help me with this, please? :) I am far from the expert in this so sorry if it was a silly question ^^

Thanks your answers and time! :)

If you are using JSONLoader, your code might look like this:

jsonLoader.load("model.json", function (geometry, materials) {
    var mesh = new THREE.Mesh(geometry, materials);
});

If your mesh have only one material and you want to use it for other geometries, you can create a variable with it and than use clone() :

var gMaterial;
jsonLoader.load("model.json", function (geometry, materials) {
    var mesh = new THREE.Mesh(geometry, materials);
    gMaterial = materials[0];
    mesh1.material = gMaterial.clone();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM