Exemple #1
0
        public MObj(IObj obj, MeshSettings defaultMeshSettings)
        {
            Obj      = obj;
            Faces    = new List <MFace>();
            Vertices = new List <MVertex>();


            foreach (var face in Obj.Faces.Where(x => x.Material.Reflectance != null))
            {
                var illuminanceAngles = new MFaceIlluminanceAngles(face.Normal, face.Material, defaultMeshSettings.SpectrumAngles.Theta, defaultMeshSettings.SpectrumAngles.Mu, defaultMeshSettings.SpectrumAngles.Phi, defaultMeshSettings.SpectrumAngles.GaussWeight, defaultMeshSettings.NSH);
                var vertices          = new MVertex[3];
                for (int i = 0; i < 3; i++)
                {
                    var vertex = new MVertex(face, Obj.Vertices[face.VertexIndexes[i]], illuminanceAngles);
                    Vertices.Add(vertex);
                    vertices[i] = vertex;
                }

                Faces.Add(new MFace(face, this, vertices, defaultMeshSettings, illuminanceAngles));
            }
        }
Exemple #2
0
        public MFaceDivideResult Divide()
        {
            if (!CanDivide())
            {
                return(null);
            }

            var result = new MFaceDivideResult();

            // divide face
            // Ищем самую длинную сторону
            Point3D v12 = Vertices[0].Point - Vertices[1].Point;
            Point3D v23 = Vertices[1].Point - Vertices[2].Point;
            Point3D v31 = Vertices[2].Point - Vertices[0].Point;

            int[] k;
            if (v12.Length2 > v23.Length2 && v12.Length2 > v31.Length2)
            {
                k = new int[] { 0, 1, 2 }
            }
            ;
            else if (v23.Length2 > v12.Length2 && v23.Length2 > v31.Length2)
            {
                k = new int[] { 1, 2, 0 }
            }
            ;
            else
            {
                k = new int[] { 2, 0, 1 }
            };

            // Вычисляю координату новой вершины - центра гиппотренузы
            Point3D p = (Vertices[k[0]].Point - Vertices[k[1]].Point) / 2 + Vertices[k[1]].Point;

            // Новая вершина
            result.NewVertex = new MVertex(Vertices[0].Face, p, Vertices[0].IlluminanceAngles);

            // Создаем новую грань
            var newVertices = new MVertex[3];

            newVertices[k[1]] = Vertices[k[2]];
            newVertices[k[2]] = Vertices[k[0]];
            newVertices[k[0]] = result.NewVertex;

            result.NewFace = new MFace(this, newVertices);
            Obj.Faces.Add(result.NewFace);
            Obj.Vertices.Add(result.NewVertex);

            // Меняем вершину у сещуствующей
            Vertices[k[0]] = result.NewVertex;
            Deep++;

            return(result);
        }

        bool CanDivide()
        {
            var result =
                Deep < MeshSettings.MaxDivideDeep; // &&

            //( Face.Material.Reflectance != null );

            return(result);
        }
    }