Exemplo n.º 1
0
        /// <summary>
        /// Creates a Cirrus mesh node
        /// </summary>
        /// <param name="_Scene"></param>
        /// <param name="_FBXMesh"></param>
        /// <returns></returns>
        protected Scene.Nodes.Mesh      CreateMesh(FBXImporter.NodeMesh _FBXMesh, Scene.Nodes.Node _Parent)
        {
            // Create a temporary mesh that will be optimized later, when all meshes have been loaded
            LoaderTempMesh TempMesh = new LoaderTempMesh(this, _FBXMesh.Name);

            if (m_bGenerateBoundingBoxes)
            {
                TempMesh.BoundingBox = new WMath.BoundingBox(m_ScaleFactor * _FBXMesh.BoundingBox.m_Min, m_ScaleFactor * _FBXMesh.BoundingBox.m_Max);
            }

            // Handle pivot & reset X-Form
            if (m_bResetXForm)
            {
                TempMesh.Pivot = _FBXMesh.Pivot;                        // Storing the mesh's pivot will have the effect of composing vertices with that matrix, actually performing the "reset X-Form" operation
            }
//          else
//              Transform.Pivot = _FBXNode.Pivot;	// Storing the mesh's pivot here will simply compose the mesh's transform with its pivot

            // Setup compulsory vertices and triangles
            Point[] SourceVertices = _FBXMesh.Vertices;
            Point[] ScaledVertices = new Point[SourceVertices.Length];
            for (int VertexIndex = 0; VertexIndex < _FBXMesh.VerticesCount; VertexIndex++)
            {
                ScaledVertices[VertexIndex] = m_ScaleFactor * SourceVertices[VertexIndex];
            }

            TempMesh.SetVertices(ScaledVertices);
            TempMesh.SetFaces(_FBXMesh.Triangles);

            // Setup all the possible recognized layers
            foreach (FBXImporter.Layer Layer in _FBXMesh.Layers)
            {
                foreach (FBXImporter.LayerElement LE in Layer.Elements)
                {
                    switch (LE.ElementType)
                    {
                    case FBXImporter.LayerElement.ELEMENT_TYPE.MATERIAL:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.UV:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.NORMAL:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.TANGENT:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.BINORMAL:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.VERTEX_COLOR:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.SMOOTHING:
                        TempMesh.AddLayerElement(LE);
                        break;

                    default:
                        break;                                  // Other types are not supported (or irrelevant)...
                    }
                }
            }

            // Build un-optimized primitives
            TempMesh.BuildPrimitives();

            // Create the final scene mesh and tie it to our temporary mesh
            FBX.Scene.Nodes.Mesh Mesh = m_Scene.CreateMesh(_FBXMesh.Name, _Parent, _FBXMesh.LocalTransform);
            m_TempMesh2FinalMesh[TempMesh] = Mesh;

            // Add some properties
            Mesh.Visible = _FBXMesh.Visible;

//          FBXImporter.ObjectProperty	PropertyCastShadow = _FBXMesh.FindUserProperty( "CastShadow" );
//          Mesh.CastShadow = PropertyCastShadow != null ? (bool) PropertyCastShadow.Value : true;
            Mesh.CastShadow    = true;
            Mesh.ReceiveShadow = true;

            return(Mesh);
        }