can't load blender model on threeJS 场景未定义
Posted
技术标签:
【中文标题】can\'t load blender model on threeJS 场景未定义【英文标题】:can't load blender model on threeJS scene is undefinedcan't load blender model on threeJS 场景未定义 【发布时间】:2018-05-23 12:05:11 【问题描述】:我已经关注了一些关于 SO 的问题来解决这个问题,但我仍然无法加载外部对象(搅拌机)。
基本上我将它导出为 ThreeJS JSON 文件,这是我的 JSON 文件:
"textures":[],
"animations":[
"fps":24,
"tracks":[],
"name":"default"
],
"geometries":[
"materials":[
"colorEmissive":[0,0,0],
"DbgName":"Material.113",
"DbgIndex":0,
"shading":"phong",
"specularCoef":50,
"transparent":false,
"visible":true,
"blending":1,
"depthWrite":true,
"DbgColor":15658734,
"doubleSided":false,
"wireframe":false,
"colorSpecular":[0.5,0.5,0.5],
"opacity":1,
"depthTest":true,
"colorDiffuse":[0.0396404,0.0396404,0.0396404]
,
"colorEmissive":[0,0,0],
"DbgName":"Material.112",
"DbgIndex":1,
"shading":"lambert",
"transparent":false,
"visible":true,
"blending":1,
"depthWrite":true,
"DbgColor":15597568,
"doubleSided":false,
"wireframe":false,
"opacity":1,
"depthTest":true,
"colorDiffuse":[0.8,0.443066,0.182712]
,
"colorEmissive":[0,0,0],
"DbgName":"Material.114",
"DbgIndex":2,
"shading":"phong",
"specularCoef":50,
"transparent":false,
"visible":true,
"blending":1,
"depthWrite":true,
"DbgColor":60928,
"doubleSided":false,
"wireframe":false,
"colorSpecular":[0.5,0.5,0.5],
"opacity":1,
"depthTest":true,
"colorDiffuse":[0.8,0.614231,0.407028]
],
"data":
"uvs":[],
"normals":[-0,0,1,-1,-0,0,1,-0,-0,-0,-1,0,-1,4.76837e-07,0,-1,-0,0,-2.38419e-07,-1,2.38419e-07,-2.38419e-07,-1,2.38419e-07,-2.38419e-07,-1,2.38419e-07 ,
"type":"Geometry",
"uuid":"639CD2C2-56FB-4D8F-B53B-B8C3E040803C",
"name":"Cube.111Geometry.4"
],
"object":
"children":[
"name":"Cube.001",
"uuid":"1213E565-1F93-497F-B4F0-843C1F17BCAD",
"matrix":[-0.6,0,0,0,0,0,0.6,0,0,0.6,0,0,-0.866864,0.6,2.6259,1],
"visible":true,
"type":"Mesh",
"material":["87C3E87D-CD72-4A6F-963A-84474DFE4059","FABD8A0F-02B0-4665-A21E-5CD1E4DDD518","E4331AC2-6CAC-4BCE-A5BD-89A811DD4D76"],
"castShadow":true,
"receiveShadow":true,
"geometry":"639CD2C2-56FB-4D8F-B53B-B8C3E040803C"
],
"matrix":[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
"type":"Scene",
"uuid":"23736546-1486-4089-967C-6DA05CB3F49C"
,
"materials":[
"vertexColors":0,
"color":13398062,
"uuid":"FABD8A0F-02B0-4665-A21E-5CD1E4DDD518",
"depthWrite":true,
"depthTest":true,
"type":"MeshLambertMaterial",
"blending":1,
"emissive":0,
"name":"Material.112"
,
"vertexColors":0,
"shininess":50,
"color":657930,
"uuid":"87C3E87D-CD72-4A6F-963A-84474DFE4059",
"specular":8355711,
"depthWrite":true,
"depthTest":true,
"type":"MeshPhongMaterial",
"blending":1,
"emissive":0,
"name":"Material.113"
,
"vertexColors":0,
"shininess":50,
"color":13409383,
"uuid":"E4331AC2-6CAC-4BCE-A5BD-89A811DD4D76",
"specular":8355711,
"depthWrite":true,
"depthTest":true,
"type":"MeshPhongMaterial",
"blending":1,
"emissive":0,
"name":"Material.114"
],
"metadata":
"generator":"io_three",
"sourceFile":"DAMA1.blend",
"version":4.4,
"type":"Object"
,
"images":[]
我省略了法线数组上的一些数据,但基本上我尝试像这样加载它:
var objLoader =new THREE.ObjectLoader();
objLoader.load('assets/dama.json', function (geometry)
this.scene.add(geometry);
);
它找到了文件,但我收到这样的错误:无法读取未定义的属性“场景”
也许它与导出的设置有关,但我已经将缓冲几何更改为几何并添加了场景复选框,我做错了什么?:S
【问题讨论】:
【参考方案1】:我不确定。不过你可以试试这个,
var scope = this;
var objLoader =new THREE.ObjectLoader();
objLoader.load('assets/dama.json', function (geometry)
scope.scene.add(geometry);
);
我希望您的场景是对象的属性,这可能就是您将其称为this.scene
的原因。问题在于,当您在 load 函数中调用 this 时,它将引用 THREE.ObjectLoader。因此,如果您需要使用 this 引用底层对象,则应先对其进行复制,然后再使用它。
如果您不使用对象来保存场景,只需调用scene.add(geometry)
而不是scope.scene.add()
和this.scene.add()
【讨论】:
以上是关于can't load blender model on threeJS 场景未定义的主要内容,如果未能解决你的问题,请参考以下文章
json.load() 函数给出奇怪的 'UnicodeDecodeError: 'ascii' codec can't decode' 错误
Delphi Can't load package 找不到指定的模块
Can't load Assembly System.Net.Http.Formatting in .Net 解决方案
Spring Security 错误:java.lang.IllegalStateException: Can't configure anyRequest after itself
popBackStack 导致 java.lang.IllegalStateException: Can't perform this action after onSaveInstanceState
使用 ViewPager#setCurrentItem() 时出现“java.lang.IllegalStateException: Can't change tag of fragment”错误