2016-08-19 11 views
2

我可以将几何体转换为缓冲区几何体,并且发现几何体和材质都良好,但模型没有显示在窗口中。缓冲区几何网格在使用网络工作时不加载

这里是我的代码:

var myWorker = new Worker("js/respond.js"); 
myWorker.postMessage("horse.js"); 

myWorker.onmessage = function(e) { 
    geometry = new THREE.BufferGeometry(); 
    var colorattribute = new THREE.BufferAttribute(e.data.color, 3, false); 
    var uv = new THREE.BufferAttribute(e.data.uv, 3, false);//created buffer attribute with worker data 
    var normal = new THREE.BufferAttribute(e.data.normal, 3, false); 
    var position = new THREE.BufferAttribute(e.data.position, 3, false); 
    var morph = new THREE.BufferAttribute(e.data.morphAttributes, 3, false); 
    geometry.addAttribute('color', colorattribute); 
    geometry.addAttribute('uv', uv); 
    geometry.addAttribute('normal', normal); 
    geometry.addAttribute('position', position); 
    geometry.addGroup(e.data.groups[0].start, e.data.groups[0].count, e.data.groups[0].materialIndex); 
    geometry.morphAttributes.position = []; 
    geometry.morphAttributes.position.push(morph); 
    //console.log(e.data.morphAttributes); 

    // mixer = new THREE.AnimationMixer(mesh); 
    // clip = THREE.AnimationClip.CreateFromMorphTargetSequence('static', geometry.morphAttributes, 30); 
    console.log(geometry); 
    mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({color: 0xffffff, morphTargets: true})); 
    console.log(mesh); 
    scene.add(mesh); 
+0

你的问题是缺少什么库你使用的geomethry信息。对于大多数的图书馆来说,都有一个特殊的标签,知道他们的人会遵循这些标签。添加正确的库标签比添加正确的语言标签要重要得多。我冒昧地添加了正确的标签。另请注意,英文句子中只有一个“。”或三个“...”点是有效的,而不是八个。 –

回答

1

这是不可能使用库,例如​​在网络工作者three.js所。

可以做的是在一个工人中构建你的几何图形,然后将其输入THREE.js中。从网络工作者,您可以根据需要返回包含TypedArraysUInt32ArraysFloat32Arrays的对象以填充所有属性。

这会导致性能提升,因为数据已经以THREE.BufferGeometry的格式组织。