三ejs场景从搅拌机和访问对象

Threejs scene from blender and access to objects

本文关键字:访问 对象 搅拌机 ejs      更新时间:2023-09-26

以下情况:
我在blender中创建了一个场景,并使用io_three插件将其导出。如果我勾选导出器中的场景选项,生成的json文件包含所有对象。
如果我不打勾,它将只导出当前选中的对象(而不是所有对象)。

问题:
我找不到一种方法来显示整个场景与三个ejs。我只看到我的背景,没有场景。我的加载器是这样的:

var loader = new THREE.JSONLoader();
loader.load('test.json', function(geometry, material){
    var materials = new THREE.MeshFaceMaterial(material);
    mesh = new THREE.Mesh(geometry, materials);
    scene.add(mesh);
});

我得到一个错误:

Uncaught TypeError: Cannot read property 'length' of undefined(anonymous function) @ three.min.js:268THREE.JSONLoader.parse @ three.min.js:271f.onreadystatechange @ three.min.js:266

生成的json文件(2个带有纹理的基本立方体):

{
    "textures": [{
        "image": "E30E1CC2-2152-3E22-8467-D5845ECA8529",
        "anisotropy": 1,
        "repeat": [1,1],
        "magFilter": "LinearFilter",
        "mapping": "UVMapping",
        "uuid": "F7F25B99-8709-3776-8D32-B0774203CF6B",
        "type": "Geometry",
        "name": "Tex",
        "wrap": ["RepeatWrapping","RepeatWrapping"],
        "minFilter": "LinearMipMapLinearFilter"
    }],
    "images": [{
        "uuid": "E30E1CC2-2152-3E22-8467-D5845ECA8529",
        "type": "Geometry",
        "name": "brick01.jpg",
        "url": "brick01.jpg"
    }],
    "object": {
        "matrix": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
        "uuid": "048B5D01-9785-45B0-AA12-2E95F912E9B2",
        "type": "Scene",
        "children": [{
            "type": "Mesh",
            "name": "Cube",
            "uuid": "F29D1AC4-D789-3D8E-BAB5-59DC1B758FE2",
            "matrix": [-1.1386,0,0,0,0,0,1.1386,0,0,1.1386,0,0,0.460104,-0.303026,0.456013,1],
            "visible": true,
            "material": "FC9C3C1C-87E7-3748-8148-105003E5F3D5",
            "castShadow": true,
            "receiveShadow": true,
            "geometry": "FE46F7EB-A263-3807-8987-EB40ABE18EAA"
        },{
            "type": "Mesh",
            "name": "Cube.001",
            "uuid": "7E8B5B6C-C1E8-35F8-8CAD-F6CC57432E76",
            "matrix": [-3.01607,0,0,0,0,0,3.01607,0,0,3.01607,0,0,-2.49361,4.47873,-4.95054,1],
            "visible": true,
            "material": "FC9C3C1C-87E7-3748-8148-105003E5F3D5",
            "castShadow": true,
            "receiveShadow": true,
            "geometry": "177A9EDE-9E89-3179-879D-52C39352875C"
        }]
    },
    "geometries": [{
        "uuid": "FE46F7EB-A263-3807-8987-EB40ABE18EAA",
        "type": "Geometry",
        "materials": [{
            "mapDiffuse": "brick01.jpg",
            "DbgName": "Material",
            "colorAmbient": [0.8,0.8,0.8],
            "shading": "lambert",
            "opacity": 1,
            "colorDiffuse": [0.8,0.8,0.8],
            "wireframe": false,
            "colorEmissive": [0,0,0],
            "DbgIndex": 0,
            "mapDiffuseRepeat": [1,1],
            "mapDiffuseAnisotropy": 1,
            "depthWrite": true,
            "depthTest": true,
            "blending": "NormalBlending",
            "DbgColor": 15658734,
            "mapDiffuseWrap": ["RepeatWrapping","RepeatWrapping"],
            "visible": true,
            "transparent": false
        }],
        "data": {
            "faces": [43,0,1,2,3,0,0,1,2,3,0,1,2,3,43,4,7,6,5,0,4,1,5,6,4,5,6,7,43,0,4,5,1,0,7,8,9,10,0,4,7,1,43,1,5,6,2,0,11,12,13,14,1,7,6,2,43,2,6,7,3,0,15,16,17,18,2,6,5,3,43,4,0,3,7,0,4,19,20,21,4,0,3,5],
            "uvs": [[0,0.666667,0.333333,0.666667,0.333333,1,0,1,0.333333,0.333333,0,0.666667,0,0.333333,0.666667,0.333333,0.333333,0.333333,0.333333,0,0.666667,0,0,0.333333,0,0,0.333333,0,0.333333,0.333333,1,0.333333,0.666667,0.333333,0.666667,0,1,0,0.666667,0.333333,0.666667,0.666667,0.333333,0.666667]],
            "vertices": [1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,1,0.999999,1,0.999999,-1,1,-1,-1,1,-1,1,1],
            "name": "CubeGeometry",
            "normals": [0.577349,0.577349,-0.577349,0.577349,-0.577349,-0.577349,-0.577349,-0.577349,-0.577349,-0.577349,0.577349,-0.577349,0.577349,0.577349,0.577349,-0.577349,0.577349,0.577349,-0.577349,-0.577349,0.577349,0.577349,-0.577349,0.577349],
            "metadata": {
                "faces": 6,
                "generator": "io_three",
                "normals": 8,
                "vertices": 8,
                "version": 3,
                "materials": 1,
                "uvs": 1
            }
        }
    },{
        "uuid": "177A9EDE-9E89-3179-879D-52C39352875C",
        "type": "Geometry",
        "materials": [{
            "mapDiffuse": "brick01.jpg",
            "DbgName": "Material",
            "colorAmbient": [0.8,0.8,0.8],
            "shading": "lambert",
            "opacity": 1,
            "colorDiffuse": [0.8,0.8,0.8],
            "wireframe": false,
            "colorEmissive": [0,0,0],
            "DbgIndex": 0,
            "mapDiffuseRepeat": [1,1],
            "mapDiffuseAnisotropy": 1,
            "depthWrite": true,
            "depthTest": true,
            "blending": "NormalBlending",
            "DbgColor": 15658734,
            "mapDiffuseWrap": ["RepeatWrapping","RepeatWrapping"],
            "visible": true,
            "transparent": false
        }],
        "data": {
            "faces": [43,0,1,2,3,0,0,1,2,3,0,1,2,3,43,4,7,6,5,0,4,1,5,6,4,5,6,7,43,0,4,5,1,0,7,8,9,10,0,4,7,1,43,1,5,6,2,0,11,12,13,14,1,7,6,2,43,2,6,7,3,0,15,16,17,18,2,6,5,3,43,4,0,3,7,0,4,19,20,21,4,0,3,5],
            "uvs": [[0,0.666667,0.333333,0.666667,0.333333,1,0,1,0.333333,0.333333,0,0.666667,0,0.333333,0.666667,0.333333,0.333333,0.333333,0.333333,0,0.666667,0,0,0.333333,0,0,0.333333,0,0.333333,0.333333,1,0.333333,0.666667,0.333333,0.666667,0,1,0,0.666667,0.333333,0.666667,0.666667,0.333333,0.666667]],
            "vertices": [1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,1,0.999999,1,0.999999,-1,1,-1,-1,1,-1,1,1],
            "name": "Cube.001Geometry.1",
            "normals": [0.577349,0.577349,-0.577349,0.577349,-0.577349,-0.577349,-0.577349,-0.577349,-0.577349,-0.577349,0.577349,-0.577349,0.577349,0.577349,0.577349,-0.577349,0.577349,0.577349,-0.577349,-0.577349,0.577349,0.577349,-0.577349,0.577349],
            "metadata": {
                "faces": 6,
                "generator": "io_three",
                "normals": 8,
                "vertices": 8,
                "version": 3,
                "materials": 1,
                "uvs": 1
            }
        }
    }],
    "materials": [{
        "map": "F7F25B99-8709-3776-8D32-B0774203CF6B",
        "depthWrite": true,
        "depthTest": true,
        "blending": "NormalBlending",
        "emissive": 0,
        "color": 13421772,
        "uuid": "FC9C3C1C-87E7-3748-8148-105003E5F3D5",
        "type": "MeshLambertMaterial",
        "name": "Material",
        "vertexColors": false,
        "ambient": 13421772
    }],
    "metadata": {
        "generator": "io_three",
        "version": 4.3,
        "type": "Object",
        "sourceFile": "test.blend"
    }
}

我也尝试了'test.js', OBJLoader, OBJMTLLoader,并寻找其他问题相同的问题,但没有任何帮助。有人能告诉我我做错了什么和/或给我一个基本的例子,它在哪里工作或应该工作。当我取一个立方体而不是两个并且不使用场景选项时,它会起作用。但我怎么能加载我的场景(多个对象)与json和显示它与三个ejs?

你可以用SceneLoader加载一个完整的场景:https://github.com/dirkk0/fps0/blob/master/scene.html l542

查看完整示例:https://github.com/dirkk0/fps0

最好的,德克