0
A
回答
0
這是一些代碼,我只是很快寫下來,並沒有testet。但這將是我如何做到的方法。也許這是一開始。
var geo = mesh.geometry; // assuming this Geometry and not BufferGeometry
var verts = geo.vertices;
var faces = geo.faces;
// vertices are used in multiple faces with different normals
// we want to translate the vertex along the average normal
// first, I collect all normals for each vertex
// (it's a bit quick and dirty as I add a normals property to the Vector3 object)
for(var i=0; i<faces.length; i++) {
// vertex a
var va = verts[faces[i].a];
if(va.normals) va.normals.push(faces[i].vertexNormals[0]); // add normal to collection
else va.normals = [ faces[i].vertexNormals[0] ]; // otherwise create array with first element
// vertex b
var vb = verts[faces[i].b];
if(vb.normals) vb.normals.push(faces[i].vertexNormals[1]);
else vb.normals = [ faces[i].vertexNormals[1] ];
// vertex c
var vc = verts[faces[i].c];
if(vc.normals) vc.normals.push(faces[i].vertexNormals[2]);
else vc.normals = [ faces[i].vertexNormals[2] ];
}
// then iterate over vertices, compute average normal, and translate vertex
for(i=0; i<verts.length; i++) {
var v = verts[i];
var normal = computeAverageNormal(v.normals);
normal.multiplyScalar(offsetAmount);
v.add(normal);
}
geo.verticesNeedUpdate = true;
function computeAverageNormal(normals) {
var n = new THREE.Vector3();
for(var i=0; i<normals.length; i++) {
n.add(normals[i]);
}
n.normalize();
return n;
}
相關問題
- 1. XNA中網格的偏移
- 2. 從網格偏移Div
- 3. 引導網格偏移量
- 4. 在網格中找到偏移
- 5. JQuery ...調整網格偏移中拖動
- 6. Three.js移動相機平行於網格
- 7. 引導網格偏移量差距
- 8. 引導網格和列偏移
- 9. 在three.js中定位網格
- 10. Three.js - 2D + 3D網格
- 11. 將位移貼圖應用於當前Three.js中的網格?
- 12. 偏移表格單元格
- 13. 在three.js中規格化網格
- 14. Bootstrap網格系統中推/拉和偏移的作用
- 15. 無法更改GIMP中的網格間距和偏移量
- 16. 爲什麼我的網格在這個例子中偏移?
- 17. 更新Three.js中的網格幾何?
- 18. 在Three.js中繪製網格的邊線
- 19. Three.js中的交互式網格
- 20. Three.js組中的網格動畫
- 21. three.js中的LOD(合併網格)
- 22. 如何用three.js在不同的方向移動多個網格?
- 23. Three.js網格不AnimationHandler動畫
- 24. 在Three.js上選擇網格
- 25. THREE.js +網格修改器
- 26. 從點生成網格Three.js
- 27. 嵌套格造型偏移
- 28. NSOutlineView單元格偏移
- 29. 偏移二進制格式
- 30. 在Three.js中合併紋理網格
可以想像,THREE.FaceNormalsHelper或THREE.VertexNormalsHelper。 – VVK