/// <summary> /// Gets triangle. /// </summary> /// <param name="index">The triangle index.</param> /// <param name="positionComponent">The component where we look for position, must be /// correct format.</param> /// <remarks>This is not performance wise getter.</remarks> public Triangle3f Get3f(string positionComponent, uint index) { Triangle3f t = new Triangle3f(); Get(positionComponent, index, t); return(t); }
/// <summary> /// An array getter, optimized by reusing mappings. /// </summary> /// <param name="triangleIndex">The triangle index offset.</param> /// <param name="positionComponent">The position component.</param> /// <param name="storage">Where to store result.</param> public void Get(string positionComponent, uint triangleIndex, Triangle3f[] storage) { if (triangleIndex + storage.Length >= shapeCount) { throw new ArgumentException("Index out of range, not that many triangles."); } if (indexBuffer != null) { uint[] indices = indexBuffer.Getui(triangleIndex * 3, (uint)storage.Length * 3); Vector3f[] data = query.Get3f(positionComponent, indices); for (int i = 0; i < storage.Length; i++) { storage[i] = new Triangle3f(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]); } } else { Vector3f[] data = query.Get3f(positionComponent, triangleIndex * 3, (uint)storage.Length * 3); for (int i = 0; i < storage.Length; i++) { storage[i] = new Triangle3f(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]); } } }
//#endfor instanced to 'Float2' //#foreach instanced to 'Float3' /// <summary> /// Gets triangle. /// </summary> /// <param name="index">The triangle triangle index.</param> /// <remarks>This is not performance wise getter.</remarks> /// <returns></returns> public Triangle3f Get3f(uint index) { Triangle3f t = new Triangle3f(); Get(CommonComponents.Position, index, t); return(t); }
public static List <Triangle3f> TriangulateG3(this Autodesk.Revit.DB.Face _face) { var mesh = _face.Triangulate(); var count = mesh.NumTriangles; var list = new List <Triangle3f>(); for (int i = 0; i < count; i++) { var t = mesh.get_Triangle(i); var triangle = new Triangle3f (t.get_Vertex(0).ToVector3f(), t.get_Vertex(1).ToVector3f(), t.get_Vertex(2).ToVector3f()); list.Add(triangle); } return(list); }
/// <summary> /// Fills a triangle at index. /// </summary> /// <param name="index">The index.</param> /// <param name="triangle">The triangle to be filled.</param> public void Get(uint index, [NotNull] Triangle3f triangle) { int idx = (int)index; if (IsIndexed) { triangle.A = vertices[(int)indices[idx * 3]]; triangle.B = vertices[(int)indices[idx * 3 + 1]]; triangle.C = vertices[(int)indices[idx * 3 + 2]]; } else { triangle.A = vertices[3 * idx]; triangle.B = vertices[3 * idx + 1]; triangle.C = vertices[3 * idx + 2]; } }
/// <summary> /// Gets triangle. /// </summary> /// <param name="index">The triangle triangle index.</param> /// <remarks>This accessor is not to be used in performance critical parts of applications.</remarks> /// <returns></returns> public void Get(string positionComponent, uint index, Triangle3f storage) { if (index >= shapeCount) { throw new ArgumentException("Index out of range, not that many triangles."); } if (indexBuffer != null) { uint[] indices = indexBuffer.Getui(index * 3, 3); storage.A = query.Get3f(positionComponent, indices[0]); storage.B = query.Get3f(positionComponent, indices[1]); storage.C = query.Get3f(positionComponent, indices[2]); } else { storage.A = query.Get3f(positionComponent, index * 3); storage.B = query.Get3f(positionComponent, index * 3 + 1); storage.C = query.Get3f(positionComponent, index * 3 + 2); } }
public void printTriangleWireframe(Triangle3f triangle, Vec3f color) { printLineCut(new Line2f(triangle.v0, triangle.v1), color); printLineCut(new Line2f(triangle.v1, triangle.v2), color); printLineCut(new Line2f(triangle.v2, triangle.v0), color); }
static void Main(string[] args) { /* * Vec4f a = new Vec4f(0.0f, 0.0f, -0.1f, 1.0f); * Mat4f prj = Mat4f.PerspectiveRH((float)(Math.PI / 180.0) * 90.0f, 1.0f, 0.1f, 1000.0f); * Vec4f b = prj * a;*/ /* * Line2f l1 = new Line2f(1.0f, 1.0f, 2.0f, 2.0f); * Line2f l2 = new Line2f(1.0f, 2.0f, 2.0f, 1.0f); * * Vec2f i = l1.intersect(l2); * float t = l1.segmentT(l2); * float u = l1.segmentU(l2); * * Vec2f uu = new Vec2f(l2.t1 - l2.t0); * Vec2f ui = l2.t0 + uu * u; */ Line3f l1 = new Line3f(1.0f, 1.0f, 1.0f, 3.0f, 3.0f, 3.0f); Triangle3f t1 = new Triangle3f( new Vec3f(1.0f, 2.0f, 1.0f), new Vec3f(1.0f, 2.0f, 4.0f), new Vec3f(4.0f, 2.0f, 1.0f) ); float d = l1.segmentD(t1); Vec3f j = l1.t0 + l1.normalizedDirection() * d; Vec3f i = l1.intersect(t1); string fsdf = ""; //Vec2f v0 = new Vec2f(209.0f, 87.0f); //Vec2f v1 = new Vec2f(110.0f, 87.0f); //Vec2f v2 = new Vec2f(209.0f, 186.0f); //float ff = Trianglef.edgeFunction(v0, v1, v2); //Vec2f v0 = new Vec2f(125.0f, 22.0f); //Vec2f v1 = new Vec2f(82.0f, 65.0f); //Vec2f v2 = new Vec2f(151.0f, 91.0f); //Trianglef tt = new Trianglef(v0, v1, v2); //bool clock1 = tt.clockWise(); //v0 = new Vec2f(125.0f, 22.0f); //v1 = new Vec2f(151.0f, 65.0f); //v2 = new Vec2f(151.0f, 91.0f); //tt = new Trianglef(v0, v1, v2); //bool clock2 = tt.clockWise(); //Vec3f L = new Vec3f(1.0f, -1.0f, 0.0f); //L.normalize(); //Vec3f N = new Vec3f(0.0f, 1.0f, 0.0f); //Vec3f R = L.reflect(N); //float l1 = R.len(); //Vec3f Rf = L.refract(N, 1.0f / 1.333f); //float l2 = Rf.len(); /* * string objPath = "untitled.obj"; * FileStream objfs = File.Open(objPath, FileMode.Open, FileAccess.Read, FileShare.None); * * //string mtlPath = "untitled.mtl"; * //FileStream mtlfs = File.Open(mtlPath, FileMode.Open, FileAccess.Read, FileShare.None); * * DataStore dataStore = new DataStore(); * FaceParser faceParser = new FaceParser(dataStore); * GroupParser groupParser = new GroupParser(dataStore); * NormalParser normalParser = new NormalParser(dataStore); * TextureParser textureParser = new TextureParser(dataStore); * VertexParser vertexParser = new VertexParser(dataStore); * * MaterialStreamProvider materialFileStreamProvider = new MaterialStreamProvider(); * MaterialLibraryLoader materialLibraryLoader = new MaterialLibraryLoader(dataStore); * MaterialLibraryLoaderFacade materialLibraryLoaderFacade = new MaterialLibraryLoaderFacade(materialLibraryLoader, materialFileStreamProvider); * MaterialLibraryParser materialLibraryParser = new MaterialLibraryParser(materialLibraryLoaderFacade); * UseMaterialParser useMaterialParser = new UseMaterialParser(dataStore); * * ObjLoader objLoader = new ObjLoader(dataStore, faceParser, groupParser, normalParser, textureParser, vertexParser, materialLibraryParser, useMaterialParser); * * var objectStream = objfs; * LoadResult loadResult = objLoader.Load(objectStream); */ Console.ReadLine(); }
/// <summary> /// An array getter, optimized by reusing mappings. /// </summary> /// <param name="triangleIndex">The triangle index offset.</param> /// <param name="positionComponent">The position component.</param> /// <param name="count">Number of triangles.</param> public Triangle3f[] Get3f(string positionComponent, uint triangleIndex, uint count) { Triangle3f[] data = new Triangle3f[count]; Get(positionComponent, triangleIndex, data); return(data); }
/// <summary> /// Gets triangle. /// </summary> /// <param name="index">The triangle index.</param> /// <param name="positionComponent">The component where we look for position, must be /// Vector2f format.</param> /// <remarks>This is not performance wise getter.</remarks> public void Get(uint index, Triangle3f storage) { Get(CommonComponents.Position, index, storage); }
/// <summary> /// Obtains a collection of triangles. /// </summary> /// <param name="index">The base index.</param> /// <param name="count">Number of triangles.</param> /// <returns>The triangle collection.</returns> public Triangle3f[] Get(uint index, uint count) { Triangle3f[] data = new Triangle3f[count]; Get(index, data); return(data); }