Esempio n. 1
0
        public int add(Vertex v)//For dealing with type Vertex
        {
            int min_ix = (int)((v.x.theValue - this.threshold) / this.cell_width);
            int min_iy = (int)((v.y.theValue - this.threshold) / this.cell_width);
            int min_iz = (int)((v.z.theValue - this.threshold) / this.cell_width);
            int max_ix = (int)((v.x.theValue + this.threshold) / this.cell_width);
            int max_iy = (int)((v.y.theValue + this.threshold) / this.cell_width);
            int max_iz = (int)((v.z.theValue + this.threshold) / this.cell_width);

            for (int ix = min_ix; ix < max_ix + 1; ix++)
            {
                for (int iy = min_iy; iy < max_iy + 1; iy++)
                {
                    for (int iz = min_iz; iz < max_iz + 1; iz++)
                    {
                        foreach (int index in this.buckets[(int)this.vertex_hash(ix, iy, iz)])
                        {
                            if (v.sub(this.vertices[index]).norm_sq() < this.threshold * this.threshold)
                            {
                                return(index);
                            }
                        }
                    }
                }
            }

            this.vertices.Add(v);
            this.buckets[(int)this.vertex_hash((int)(v.x.theValue / this.cell_width), (int)(v.y.theValue / this.cell_width),
                                               (int)(v.z.theValue / this.cell_width))].Add(this.vertices.Count - 1);
            return(this.vertices.Count - 1);
        }
Esempio n. 2
0
 public Triangle(Vertex u, Vertex v, Vertex w, int group)
 {
     this.u     = u;
     this.v     = v;
     this.w     = w;
     this.n     = KCLWriter.unit(KCLWriter.cross(v.sub(u), w.sub(u)));
     this.group = group;
 }
Esempio n. 3
0
        public static bool edge_test(Vertex v0, Vertex v1, Vertex v2, float hw)
        {
            Vertex e = v1.sub(v0);

            if (edge_axis_test(e.z.theValue, -e.y.theValue, v0.y.theValue, v0.z.theValue, v2.y.theValue, v2.z.theValue, hw))
            {
                return(true);
            }
            if (edge_axis_test(-e.z.theValue, e.x.theValue, v0.x.theValue, v0.z.theValue, v2.x.theValue, v2.z.theValue, hw))
            {
                return(true);
            }
            if (edge_axis_test(e.y.theValue, -e.x.theValue, v0.x.theValue, v0.y.theValue, v2.x.theValue, v2.y.theValue, hw))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        private static List <Triangle> readLoadedModel(ModelBase model, float faceSizeThreshold, Dictionary <string, int> matColTypes)
        {
            List <Triangle> triangles = new List <Triangle>();

            foreach (ModelBase.BoneDef bone in model.m_BoneTree)
            {
                foreach (ModelBase.GeometryDef geometry in bone.m_Geometries.Values)
                {
                    foreach (ModelBase.PolyListDef polyList in geometry.m_PolyLists.Values)
                    {
                        string material = polyList.m_MaterialName;

                        foreach (ModelBase.FaceListDef faceList in polyList.m_FaceLists)
                        {
                            foreach (ModelBase.FaceDef face in faceList.m_Faces)
                            {
                                if (face.m_NumVertices == 3)
                                {
                                    Vertex u = new Vertex(
                                        face.m_Vertices[0].m_Position.X, face.m_Vertices[0].m_Position.Y, face.m_Vertices[0].m_Position.Z);
                                    Vertex v = new Vertex(
                                        face.m_Vertices[1].m_Position.X, face.m_Vertices[1].m_Position.Y, face.m_Vertices[1].m_Position.Z);
                                    Vertex w = new Vertex(
                                        face.m_Vertices[2].m_Position.X, face.m_Vertices[2].m_Position.Y, face.m_Vertices[2].m_Position.Z);

                                    //Below line gets rid of faces that are too small, original 0.001
                                    if (cross(v.sub(u), w.sub(u)).norm_sq() < faceSizeThreshold)
                                    {
                                        continue;
                                    }                                                                          //#TODO: find a better solution
                                    triangles.Add(new Triangle(u, v, w, matColTypes[material]));
                                }
                            }
                        }
                    }
                }
            }

            return(triangles);
        }
Esempio n. 5
0
        //For dealing with type Vertex
        public int add(Vertex v)
        {
            int min_ix = (int)((v.x.theValue - this.threshold) / this.cell_width);
            int min_iy = (int)((v.y.theValue - this.threshold) / this.cell_width);
            int min_iz = (int)((v.z.theValue - this.threshold) / this.cell_width);
            int max_ix = (int)((v.x.theValue + this.threshold) / this.cell_width);
            int max_iy = (int)((v.y.theValue + this.threshold) / this.cell_width);
            int max_iz = (int)((v.z.theValue + this.threshold) / this.cell_width);

            for (int ix = min_ix; ix < max_ix + 1; ix++)
            {
                for (int iy = min_iy; iy < max_iy + 1; iy++)
                {
                    for (int iz = min_iz; iz < max_iz + 1; iz++)
                    {
                        foreach (int index in this.buckets[(int)this.vertex_hash(ix, iy, iz)])
                        {
                            if (v.sub(this.vertices[index]).norm_sq() < this.threshold * this.threshold)
                                return index;
                        }
                    }
                }
            }

            this.vertices.Add(v);
            this.buckets[(int)this.vertex_hash((int)(v.x.theValue / this.cell_width), (int)(v.y.theValue / this.cell_width),
                (int)(v.z.theValue / this.cell_width))].Add(this.vertices.Count - 1);
            return (this.vertices.Count - 1);
        }
Esempio n. 6
0
 public Triangle(Vertex u, Vertex v, Vertex w, int group)
 {
     this.u = u;
     this.v = v;
     this.w = w;
     this.n = KCLWriter.unit(KCLWriter.cross(v.sub(u), w.sub(u)));
     this.group = group;
 }
Esempio n. 7
0
        private static List<Triangle> readLoadedModel(ModelBase model, float faceSizeThreshold, Dictionary<string, int> matColTypes)
        {
            List<Triangle> triangles = new List<Triangle>();

            foreach (ModelBase.BoneDef bone in model.m_BoneTree)
            {
                foreach (ModelBase.GeometryDef geometry in bone.m_Geometries.Values)
                {
                    foreach (ModelBase.PolyListDef polyList in geometry.m_PolyLists.Values)
                    {
                        string material = polyList.m_MaterialName;

                        foreach (ModelBase.FaceListDef faceList in polyList.m_FaceLists)
                        {
                            foreach (ModelBase.FaceDef face in faceList.m_Faces)
                            {
                                if (face.m_NumVertices == 3)
                                {
                                    Vertex u = new Vertex(
                                        face.m_Vertices[0].m_Position.X, face.m_Vertices[0].m_Position.Y, face.m_Vertices[0].m_Position.Z);
                                    Vertex v = new Vertex(
                                        face.m_Vertices[1].m_Position.X, face.m_Vertices[1].m_Position.Y, face.m_Vertices[1].m_Position.Z);
                                    Vertex w = new Vertex(
                                        face.m_Vertices[2].m_Position.X, face.m_Vertices[2].m_Position.Y, face.m_Vertices[2].m_Position.Z);

                                    //Below line gets rid of faces that are too small, original 0.001
                                    if (cross(v.sub(u), w.sub(u)).norm_sq() < faceSizeThreshold) { continue; } //#TODO: find a better solution
                                    triangles.Add(new Triangle(u, v, w, matColTypes[material]));
                                }
                                else if (face.m_NumVertices == 4)
                                {
                                    Vertex u1 = new Vertex(
                                        face.m_Vertices[0].m_Position.X, face.m_Vertices[0].m_Position.Y, face.m_Vertices[0].m_Position.Z);
                                    Vertex v1 = new Vertex(
                                        face.m_Vertices[1].m_Position.X, face.m_Vertices[1].m_Position.Y, face.m_Vertices[1].m_Position.Z);
                                    Vertex w1 = new Vertex(
                                        face.m_Vertices[3].m_Position.X, face.m_Vertices[3].m_Position.Y, face.m_Vertices[3].m_Position.Z);

                                    //Below line gets rid of faces that are too small, original 0.001
                                    if (cross(v1.sub(u1), w1.sub(u1)).norm_sq() < faceSizeThreshold) { continue; } //#TODO: find a better solution
                                    triangles.Add(new Triangle(u1, v1, w1, matColTypes[material]));

                                    Vertex u2 = new Vertex(
                                        face.m_Vertices[1].m_Position.X, face.m_Vertices[1].m_Position.Y, face.m_Vertices[1].m_Position.Z);
                                    Vertex v2 = new Vertex(
                                        face.m_Vertices[2].m_Position.X, face.m_Vertices[2].m_Position.Y, face.m_Vertices[2].m_Position.Z);
                                    Vertex w2 = new Vertex(
                                        face.m_Vertices[3].m_Position.X, face.m_Vertices[3].m_Position.Y, face.m_Vertices[3].m_Position.Z);

                                    //Below line gets rid of faces that are too small, original 0.001
                                    if (cross(v2.sub(u2), w2.sub(u2)).norm_sq() < faceSizeThreshold) { continue; } //#TODO: find a better solution
                                    triangles.Add(new Triangle(u2, v2, w2, matColTypes[material]));
                                }
                            }
                        }
                    }
                }
            }

            return triangles;
        }
Esempio n. 8
0
 public static bool edge_test(Vertex v0, Vertex v1, Vertex v2, float hw)
 {
     Vertex e = v1.sub(v0);
     if (edge_axis_test(e.z.theValue, -e.y.theValue, v0.y.theValue, v0.z.theValue, v2.y.theValue, v2.z.theValue, hw))
         return true;
     if (edge_axis_test(-e.z.theValue, e.x.theValue, v0.x.theValue, v0.z.theValue, v2.x.theValue, v2.z.theValue, hw))
         return true;
     if (edge_axis_test(e.y.theValue, -e.x.theValue, v0.x.theValue, v0.y.theValue, v2.x.theValue, v2.y.theValue, hw))
         return true;
     return false;
 }