gpt4 book ai didi

javascript - Blender 的 TypeError : vertices is undefined - three. js 导出器

转载 作者:行者123 更新时间:2023-11-30 15:13:37 25 4
gpt4 key购买 nike

加载 three.js exporter for Blender 生成的 JSON 文件时出现问题, 随附 three.js r.86。

设置完成没有问题。为了测试这个导出器,我打开了 Blender,并使用了包含立方体的 untitled Blender 文件:

Screenshot Blender v2.78

在不做任何调整的情况下导出它,它会生成以下 JSON 文件:

{
"metadata":{
"generator":"io_three",
"normal":36,
"position":36,
"version":3,
"type":"BufferGeometry"
},
"data":{
"index":{
"array":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],
"itemSize":1,
"type":"Uint16Array"
},
"attributes":{
"normal":{
"array":[-7.10543e-15,-1,2.98023e-08,-7.10543e-15,-1,2.98023e-08,-7.10543e-15,-1,2.98023e-08,7.10543e-15,1,-2.98023e-08,7.10543e-15,1,-2.98023e-08,7.10543e-15,1,-2.98023e-08,1,-2.38419e-07,7.10543e-15,1,-2.38419e-07,7.10543e-15,1,-2.38419e-07,7.10543e-15,-5.96046e-08,-2.98023e-07,1,-5.96046e-08,-2.98023e-07,1,-5.96046e-08,-2.98023e-07,1,-1,-1.49012e-07,-2.38419e-07,-1,-1.49012e-07,-2.38419e-07,-1,-1.49012e-07,-2.38419e-07,2.38419e-07,1.78814e-07,-1,2.38419e-07,1.78814e-07,-1,2.38419e-07,1.78814e-07,-1,-1.77636e-15,-1,2.98023e-08,-1.77636e-15,-1,2.98023e-08,-1.77636e-15,-1,2.98023e-08,1.5099e-14,1,-2.98023e-08,1.5099e-14,1,-2.98023e-08,1.5099e-14,1,-2.98023e-08,1,3.27825e-07,5.66244e-07,1,3.27825e-07,5.66244e-07,1,3.27825e-07,5.66244e-07,-5.0664e-07,1.49012e-07,1,-5.0664e-07,1.49012e-07,1,-5.0664e-07,1.49012e-07,1,-1,-1.19209e-07,-2.08616e-07,-1,-1.19209e-07,-2.08616e-07,-1,-1.19209e-07,-2.08616e-07,2.38419e-07,1.78814e-07,-1,2.38419e-07,1.78814e-07,-1,2.38419e-07,1.78814e-07,-1],
"itemSize":3,
"type":"Float32Array"
},
"position":{
"array":[1,-1,-1,-1,-1,1,-1,-1,-1,-1,1,-1,0.999999,1,1,1,1,-1,1,1,-1,1,-1,1,1,-1,-1,0.999999,1,1,-1,-1,1,1,-1,1,-1,-1,1,-1,1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,0.999999,1,1,1,1,-1,0.999999,1,1,1,-1,1,0.999999,1,1,-1,1,1,-1,-1,1,-1,-1,1,-1,1,1,-1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1],
"itemSize":3,
"type":"Float32Array"
}
}
}
}

我已将 JSON 文件上传到服务器,并尝试通过基本设置将其加载到场景中:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My first three.js app</title>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="assets/js/three.js"></script>
<script>

/* Scene
*/
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );

var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );

camera.position.z = 5;

cube.rotation.x = 2;
cube.rotation.y = 2;

renderer.render(scene, camera);

/* Load the JSON
*/
var loader = new THREE.JSONLoader();

loader.load(

'https://www.example.com/blender-cube.json',

function ( geometry, materials ) {

var material = materials[ 0 ];
var object = new THREE.Mesh( geometry, material );

scene.add( object );

}
);
</script>
</body>
</html>

使用上面的代码,我从示例页面中提取了绿色立方体 ,但是当到达 Load the JSON 部分时 ,浏览器控制台显示如下错误:

TypeError: vertices is undefined
three.js:33296.5

提到的错误行在 parseModel( json, geometry ) 函数中。

在我看来,Blender 的 three.js 导出器在生成 JSON 文件时丢失了一些东西。 parseModel() 函数需要生成的 JSON 文件中不存在的 vertices 属性。

一个工作片段,对 Load the JSON 部分稍作调整,将 JSON 文件放在 JavaScript 变量中:

/* Scene
*/
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

var geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshBasicMaterial({
color: 0x00ff00
});
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);

camera.position.z = 5;

cube.rotation.x = 2;
cube.rotation.y = 2;

renderer.render(scene, camera);

/* Load the JSON
*/
var loader = new THREE.JSONLoader();

var blenderCubeObject = {
"metadata": {
"generator": "io_three",
"normal": 36,
"position": 36,
"version": 3,
"type": "BufferGeometry"
},
"data": {
"index": {
"array": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35],
"itemSize": 1,
"type": "Uint16Array"
},
"attributes": {
"normal": {
"array": [-7.10543e-15, -1, 2.98023e-08, -7.10543e-15, -1, 2.98023e-08, -7.10543e-15, -1, 2.98023e-08, 7.10543e-15, 1, -2.98023e-08, 7.10543e-15, 1, -2.98023e-08, 7.10543e-15, 1, -2.98023e-08, 1, -2.38419e-07, 7.10543e-15, 1, -2.38419e-07, 7.10543e-15, 1, -2.38419e-07, 7.10543e-15, -5.96046e-08, -2.98023e-07, 1, -5.96046e-08, -2.98023e-07, 1, -5.96046e-08, -2.98023e-07, 1, -1, -1.49012e-07, -2.38419e-07, -1, -1.49012e-07, -2.38419e-07, -1, -1.49012e-07, -2.38419e-07, 2.38419e-07, 1.78814e-07, -1, 2.38419e-07, 1.78814e-07, -1, 2.38419e-07, 1.78814e-07, -1, -1.77636e-15, -1, 2.98023e-08, -1.77636e-15, -1, 2.98023e-08, -1.77636e-15, -1, 2.98023e-08, 1.5099e-14, 1, -2.98023e-08, 1.5099e-14, 1, -2.98023e-08, 1.5099e-14, 1, -2.98023e-08, 1, 3.27825e-07, 5.66244e-07, 1, 3.27825e-07, 5.66244e-07, 1, 3.27825e-07, 5.66244e-07, -5.0664e-07, 1.49012e-07, 1, -5.0664e-07, 1.49012e-07, 1, -5.0664e-07, 1.49012e-07, 1, -1, -1.19209e-07, -2.08616e-07, -1, -1.19209e-07, -2.08616e-07, -1, -1.19209e-07, -2.08616e-07, 2.38419e-07, 1.78814e-07, -1, 2.38419e-07, 1.78814e-07, -1, 2.38419e-07, 1.78814e-07, -1],
"itemSize": 3,
"type": "Float32Array"
},
"position": {
"array": [1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, 0.999999, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, 0.999999, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 0.999999, 1, 1, 1, 1, -1, 0.999999, 1, 1, 1, -1, 1, 0.999999, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, -1],
"itemSize": 3,
"type": "Float32Array"
}
}
}
};

var model = loader.parse(blenderCubeObject);

mesh = new THREE.Mesh(model.geometry, model.materials[0]);

scene.add(mesh);
body {
margin: 0;
}

canvas {
width: 100%;
height: 100%
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/86/three.js"></script>

关于正在发生的事情或我做错了什么的任何线索?

最佳答案

尝试更改 apply modifier to geometry 的类型而不是 buffergeometry,看看是否有帮助。

关于javascript - Blender 的 TypeError : vertices is undefined - three. js 导出器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44786742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com