public static GeometryBuilder ToGeometryBuilder(this Va3cGeometry g) { var gb = new GeometryBuilder(); var vertices = g.data.vertices.ToIArray() .SelectTriplets(ToVertex); // https://github.com/mrdoob/three.js/wiki/JSON-Model-format-3 // https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 // https://stackoverflow.com/questions/35386518/parsing-three-js-json-mesh-format-normals-errors // https://stackoverflow.com/questions/28023734/threejs-json-loader-mixed-faces-and-vertices var f = 0; var obscure = removeFourthValue(g.data.faces.ToArray()); while (f < obscure.Length) { //var bits = g.data.faces[f++]; //var isTriangle = (bits & 1) == 0; //var isQuad = (bits & 1) != 0; //var hasMaterial = (bits & 2) != 0; //var hasUV = (bits & 4) != 0; //var hasVertexUv = (bits & 8) != 0; //var hasNormal = (bits & 16) != 0; //var hasVertexNormal = (bits & 32) != 0; //var hasColor = (bits & 64) != 0; //var hasVertexColor = (bits & 128) != 0; //Debug.Assert(bits == 0); for (var i = 0; i < 3; ++i) { gb.Indices.Add(obscure[f++]); } } gb.Vertices.AddRange(vertices.ToArray()); gb.UVs.AddRange(Vector2.Zero.Repeat(vertices.Count).ToArray()); var nfaces = gb.Indices.Count / 3; for (var i = 0; i < nfaces; ++i) { gb.MaterialIds.Add(-1); gb.FaceGroupIds.Add(-1); } return(gb); }
public static Va3cGeometry ToGeometry(IMesh m, int index) { var r = new Va3cGeometry(); r.uuid = index.ToString(); for (var i = 0; i < m.NumFaces; ++i) { r.data.faces.Add(0); for (var j = 0; j < 3; ++j) { r.data.faces.Add(m.Indices[i * 3 + j]); } } for (var i = 0; i < m.NumVertices; ++i) { var v = m.Vertices[i]; r.data.vertices.Add(v.X * Constants.FeetToMm); r.data.vertices.Add(v.Y * Constants.FeetToMm); r.data.vertices.Add(v.Z * Constants.FeetToMm); } return(r); }