CreatePrimitive() public method

public CreatePrimitive ( LoaderTempMesh _SourcePrimitive, Scene _ParentMesh, string _Name, Scene _MatParams ) : Scene.Nodes.Mesh.Primitive
_SourcePrimitive FBX.SceneLoader.Objects.LoaderTempMesh
_ParentMesh Scene
_Name string
_MatParams Scene
return Scene.Nodes.Mesh.Primitive
Esempio n. 1
0
        /// <summary>
        /// Optimizes the existing meshes and build the primitives necessary for runtime display
        /// This will attempt to compact identical meshes and also consolidate mesh primitives
        /// </summary>
        protected void BuildConsolidatedMeshes()
        {
            // 1] Retrieve all existing meshes and compact identical instances
            List<LoaderTempMesh>	CompactedMeshes = new List<LoaderTempMesh>();
            foreach ( LoaderTempMesh M in m_TempMesh2FinalMesh.Keys )
            {
                // Check the existing meshes to see if they might be a master to this mesh
                if ( m_bCompactIdenticalMeshes )
                    foreach ( LoaderTempMesh MasterMesh in CompactedMeshes )
                        if ( M.MergeWithMasterMesh( MasterMesh ) )
                            break;	// We found this mesh's master!

                CompactedMeshes.Add( M );
            }

            // 2] Consolidate master meshes
            //			WMath.Global.PushEpsilon( 1e-3f );	// Use this new epsilon for float comparisons in the Math library...

            foreach ( LoaderTempMesh M in CompactedMeshes )
                M.PerformConsolidation();

            //			WMath.Global.PopEpsilon();

            // 3] Rebuild slave meshes from consolidated meshes
            foreach ( LoaderTempMesh M in CompactedMeshes )
                M.RebuildFromMasterMesh();

            // 4] Convert the mesh into a clean consolidated mesh
            PrimitiveBuilder	Builder = new PrimitiveBuilder();
            foreach ( LoaderTempMesh M in CompactedMeshes )
            {
                Scene.Nodes.Mesh	TargetMesh = m_TempMesh2FinalMesh[M];

                // Setup basic mesh infos
                TargetMesh.BBox = M.BoundingBox;

                // I know it's a bit of a lousy approximation for the b-sphere but we can always refine it later...
                TargetMesh.BSphere = new BoundingSphere( M.BoundingBox.Center, 0.5f * M.BoundingBox.Dim.Magnitude() );

                // Build primitives
                int	PrimitiveIndex = 0;
                foreach ( LoaderTempMesh.Primitive P in M.ConsolidatedPrimitives )
                {
                    if ( P.Material == null )
                        throw new Exception( "Primitive \"" + P.Name + "\" has no assigned material!" );

             					Scene.Materials.MaterialParameters	MatParams = m_Material2Parameters[P.Material];

            // 					if ( !m_Material2Technique.ContainsKey( P.Material ) )
            // 						continue;	// Un-supported...

             					// Create the temporary builder that will handle the primitive conversion
                    Builder.CreatePrimitive( P, TargetMesh, M.Name + "." + PrimitiveIndex++, MatParams );
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Optimizes the existing meshes and build the primitives necessary for runtime display
        /// This will attempt to compact identical meshes and also consolidate mesh primitives
        /// </summary>
        protected void  BuildConsolidatedMeshes()
        {
            // 1] Retrieve all existing meshes and compact identical instances
            List <LoaderTempMesh> CompactedMeshes = new List <LoaderTempMesh>();

            foreach (LoaderTempMesh M in m_TempMesh2FinalMesh.Keys)
            {
                // Check the existing meshes to see if they might be a master to this mesh
                if (m_bCompactIdenticalMeshes)
                {
                    foreach (LoaderTempMesh MasterMesh in CompactedMeshes)
                    {
                        if (M.MergeWithMasterMesh(MasterMesh))
                        {
                            break;                              // We found this mesh's master!
                        }
                    }
                }
                CompactedMeshes.Add(M);
            }

            // 2] Consolidate master meshes
//			WMath.Global.PushEpsilon( 1e-3f );	// Use this new epsilon for float comparisons in the Math library...

            foreach (LoaderTempMesh M in CompactedMeshes)
            {
                M.PerformConsolidation();
            }

//			WMath.Global.PopEpsilon();

            // 3] Rebuild slave meshes from consolidated meshes
            foreach (LoaderTempMesh M in CompactedMeshes)
            {
                M.RebuildFromMasterMesh();
            }


            // 4] Convert the mesh into a clean consolidated mesh
            PrimitiveBuilder Builder = new PrimitiveBuilder();
            foreach (LoaderTempMesh M in CompactedMeshes)
            {
                Scene.Nodes.Mesh TargetMesh = m_TempMesh2FinalMesh[M];

                // Setup basic mesh infos
                TargetMesh.BBox = M.BoundingBox;

                // I know it's a bit of a lousy approximation for the b-sphere but we can always refine it later...
                TargetMesh.BSphere = new BoundingSphere(M.BoundingBox.Center, 0.5f * M.BoundingBox.Dim.Magnitude());

                // Build primitives
                int PrimitiveIndex = 0;
                foreach (LoaderTempMesh.Primitive P in M.ConsolidatedPrimitives)
                {
                    if (P.Material == null)
                    {
                        throw new Exception("Primitive \"" + P.Name + "\" has no assigned material!");
                    }

                    Scene.Materials.MaterialParameters MatParams = m_Material2Parameters[P.Material];

//                  if ( !m_Material2Technique.ContainsKey( P.Material ) )
//                      continue;	// Un-supported...

                    // Create the temporary builder that will handle the primitive conversion
                    Builder.CreatePrimitive(P, TargetMesh, M.Name + "." + PrimitiveIndex++, MatParams);
                }
            }
        }