1

I have an array of (x,y,z) of vertices coordinates. And array of facets which contains indexes of vertices (from first array) for each facet (whereby each facet can have a different number of vertices).

How can I make custom 3D object using these data?

1 Answer 1

2

If you have only convex polygons, you can do something like this. The second loop creates triangle strip from your convex polygons.

var vertices = [
    0, 0, 0,
    1, 0, 0,
    1, 1, 0,
    0, 1, 0,
    0, 0, 1
];

var faces = [
    [0, 1, 2, 3],
    [0, 3, 4]
];

var geometry = new THREE.Geometry ();
var i, j, face;
for (i = 0; i < vertices.length; i += 3) {
    geometry.vertices.push (new THREE.Vector3 (
        vertices[i],
        vertices[i + 1],
        vertices[i + 2]
    ));
}

var i, j, face;
for (i = 0; i < faces.length; i++) {
    face = faces[i];
    for (j = 1; j < face.length - 1; j++) {
        geometry.faces.push (new THREE.Face3 (face[0], face[j], face[j + 1]));
    }
}

Here is a fiddle with the whole code: http://jsfiddle.net/g25v5t0k/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.