Ejemplo n.º 1
0
        //public override bool IntersectPoint(out Intersection intersect, Ray ray) {
        //    intersect = new Intersection();
        //    if (!this.boundBox.Intersect(ray)) {
        //        return false;
        //    }
        //    intersect.TMin = float.PositiveInfinity;
        //    Intersection intersection_comp = new Intersection();
        //    Vector3D v1, v2, v3;
        //    bool hit = false;
        //    int less = 0;
        //    BarycentricCoordinate bary = new BarycentricCoordinate();
        //    for (int i = 0; i < this.triangles.Length; i++) {
        //        if (triangles[i].IntersectPoint(out intersection_comp, ray) && intersection_comp.TMin < intersect.TMin) {
        //            intersect = intersection_comp;
        //            bary = triangles[i].CurrentBarycentricCoordinate;
        //            less = i;
        //            hit = true;
        //        }
        //    }
        //    if (hit) {
        //        if (this.shadeType == ShadeType.Phong) {
        //            Triangle t = (Triangle)intersect.HitPrimitive;
        //            bary = t.BarycentricCoordinateOnPoint(intersect.HitPoint);
        //            if (bary.IsValid) {
        //                v1 = bary.Alpha * this.normalsPerVertex[this.pointersToVertex[less].Vertex1];
        //                v2 = bary.Beta * this.normalsPerVertex[this.pointersToVertex[less].Vertex2];
        //                v3 = bary.Gama * this.normalsPerVertex[this.pointersToVertex[less].Vertex3];
        //                intersect.Normal = (v1 + v2 + v3);
        //                intersect.Normal.Normalize();
        //            }
        //        }
        //        intersect.HitPrimitive = this;
        //        intersect.HitPrimitive.Material = this.material;
        //    }
        //    return hit;
        //}
        //public void ProcessNormalsPerVertex() {
        //    Vector3D vertexVectorSum;
        //    int faceCount;
        //    PointerToVertex currentFace;
        //    for (int i = 0; i < this.Vertices.Length; i++) {
        //        // Find faces attached to our current vertex
        //        faceCount = 0;
        //        vertexVectorSum = Vector3D.Zero;
        //        for (int j = 0; j < this.pointersToVertex.Length; j++) {
        //            currentFace = this.pointersToVertex[j];
        //            if ((i == currentFace.Vertex1) || (i == currentFace.Vertex2) || (i == currentFace.Vertex3)) {
        //                faceCount++;
        //                vertexVectorSum = vertexVectorSum + this.triangles[j].Normal;
        //            }
        //        }
        //        // Use sum of face normals to calculate this vertex's normal
        //        this.normalsPerVertex[i] = vertexVectorSum / faceCount;
        //        this.normalsPerVertex[i].Normalize();
        //    }
        //}

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            if (this.loader != null)
            {
                this.loader.Dispose();
            }

            this.triangles = null;
            this.manager   = null;
            this.loader    = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Ejemplo n.º 2
0
        public void Load()
        {
            this.loader = AbstractLoaderModel.GetLoader(this.path);
            //throw new IOException(String.Format("O Arquivo {0} tem o formato inválido ou está corrompido!",
            //                                    this.path));
            if (this.loader != null)
            {
                this.loader.OnElementLoaded += this.TriangleModel_OnElementLoaded;
                this.triangles = this.loader.Load();
                this.loader.Dispose();
                this.boundBox = this.loader.BoundBox;
                //float len = Math.Abs(this.boundBox.PMax.Y - this.boundBox.PMin.Y);

                float scale = 50 / this.boundBox.HalfVector.Length;
                this.boundBox.Scale(scale);
                //this.boundBox.Translate(-this.boundBox.Center.ToVector3D());
                for (int i = 0; i < this.triangles.Length; i++)
                {
                    this.triangles[i].Wireframed = this.Wireframed;
                    this.triangles[i].Scale(scale);
                    //this.triangles[i].Translate(-this.boundBox.Center.ToVector3D());
                }
                //this.manager = new NoAccerelationStructure<Triangle>(this.triangles);
                this.manager = new Octree <Triangle>(this.boundBox, this.triangles);
                //this.manager = new KDTreeTriangleManager(new List<Triangle>(triangles));
                if (this.OnInitBuild != null)
                {
                    this.OnInitBuild();
                }
                DateTime antes = DateTime.Now;
                this.manager.Optimize();
                //((ITransformable3D)this.manager).Translate(-(this.boundBox.Center.X), -(this.boundBox.Center.Y), -(this.boundBox.Center.Z));
                //this.manager.Optimize();
                if (this.OnEndBuild != null)
                {
                    this.OnEndBuild(DateTime.Now.Subtract(antes));
                }
            }
        }