0
THREE.JS의 메쉬 지오메트리를 주어진 간격/간격으로 오프셋 할 수있는 방법이 있습니까?THREE.js의 오프셋 메쉬
그것은 간단한 스케일링 아니다. 알고리즘은 법선을 기반으로해야한다는 제안은 스케일링 에지의 방향을 제시합니다.
THREE.JS의 메쉬 지오메트리를 주어진 간격/간격으로 오프셋 할 수있는 방법이 있습니까?THREE.js의 오프셋 메쉬
그것은 간단한 스케일링 아니다. 알고리즘은 법선을 기반으로해야한다는 제안은 스케일링 에지의 방향을 제시합니다.
이것은 내가 작성한 코드 중 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;
}
가설 적으로, THREE.FaceNormalsHelper 또는 THREE.VertexNormalsHelper. – VVK