Ejemplo n.º 1
0
        /// <summary>
        /// Create objects from model. Requires FrameMesh/FrameModel to be already set and a model already read into the data.
        /// </summary>
        public void CreateObjectsFromModel()
        {
            frameGeometry = new FrameGeometry();
            frameMaterial = new FrameMaterial();


            //set lods for all data.
            indexBuffers  = new IndexBuffer[model.Lods.Length];
            vertexBuffers = new VertexBuffer[model.Lods.Length];

            List <Vertex[]> vertData = new List <Vertex[]>();

            for (int i = 0; i != model.Lods.Length; i++)
            {
                vertData.Add(model.Lods[i].Vertices);

                if (model.Lods[i].VertexDeclaration.HasFlag(VertexFlags.Tangent))
                {
                    model.Lods[i].VertexDeclaration -= VertexFlags.Tangent;
                }
            }

            frameMesh.Boundings  = BoundingBoxExtenders.CalculateBounds(vertData);
            frameMaterial.Bounds = FrameMesh.Boundings;
            CalculateDecompression();
            UpdateObjectsFromModel();
            BuildIndexBuffer();
            BuildVertexBuffer();

            for (int i = 0; i < model.Lods.Length; i++)
            {
                frameGeometry.LOD[i].IndexBufferRef  = new Hash("M2TK." + model.Name + ".IB" + i);
                frameGeometry.LOD[i].VertexBufferRef = new Hash("M2TK." + model.Name + ".VB" + i);
            }
        }
Ejemplo n.º 2
0
        public void ConvertMTKToRenderModel(M2TStructure structure)
        {
            List <Vertex[]> vertices = new List <Vertex[]>();

            LODs = new LOD[structure.Lods.Length];
            for (int i = 0; i != structure.Lods.Length; i++)
            {
                M2TStructure.Lod lod = structure.Lods[i];
                vertices.Add(lod.Vertices);
                LOD lod2 = new LOD();
                lod2.Indices    = lod.Indices;
                lod2.ModelParts = new ModelPart[lod.Parts.Length];
                for (int y = 0; y != lod.Parts.Length; y++)
                {
                    ModelPart part = new ModelPart();
                    part.NumFaces     = lod.Parts[y].NumFaces;
                    part.StartIndex   = lod.Parts[y].StartIndex;
                    part.MaterialHash = lod.Parts[y].Hash;


                    switch (part.MaterialHash)
                    {
                    case 1337:
                        part.Material = RenderStorageSingleton.Instance.Prefabs.GizmoRed;
                        break;

                    case 1338:
                        part.Material = RenderStorageSingleton.Instance.Prefabs.GizmoBlue;
                        break;

                    case 1339:
                        part.Material = RenderStorageSingleton.Instance.Prefabs.GizmoGreen;
                        break;

                    default:
                        part.Material = MaterialsManager.LookupMaterialByHash(part.MaterialHash);
                        break;
                    }
                    lod2.ModelParts[y] = part;
                }

                lod2.Vertices = new VertexLayouts.NormalLayout.Vertex[lod.Vertices.Length];
                for (int y = 0; y != lod.Vertices.Length; y++)
                {
                    var vertice = new VertexLayouts.NormalLayout.Vertex();
                    vertice.Position  = lod.Vertices[y].Position;
                    vertice.Normal    = lod.Vertices[y].Normal;
                    vertice.TexCoord0 = lod.Vertices[y].UVs[0];
                    vertice.TexCoord7 = lod.Vertices[y].UVs[3];
                    lod2.Vertices[y]  = vertice;
                }
                LODs[i] = lod2;
            }
            BoundingBox = new RenderBoundingBox();
            BoundingBox.Init(BoundingBoxExtenders.CalculateBounds(vertices));
            BoundingBox.SetTransform(Transform);
            BoundingBox.DoRender = false;
            SetupShaders();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create objects from model. Requires FrameMesh/FrameModel to be already set and a model already read into the data.
        /// </summary>
        public void CreateObjectsFromModel()
        {
            frameGeometry = new FrameGeometry();
            frameMaterial = new FrameMaterial();


            //set lods for all data.
            indexBuffers  = new IndexBuffer[model.Lods.Length];
            vertexBuffers = new VertexBuffer[model.Lods.Length];

            List <Vertex[]> vertData = new List <Vertex[]>();

            for (int i = 0; i != model.Lods.Length; i++)
            {
                vertData.Add(model.Lods[i].Vertices);
            }

            frameMesh.Boundings  = BoundingBoxExtenders.CalculateBounds(vertData);
            frameMaterial.Bounds = FrameMesh.Boundings;
            CalculateDecompression();
            UpdateObjectsFromModel();
            BuildIndexBuffer();
            BuildVertexBuffer();

            for (int i = 0; i < model.Lods.Length; i++)
            {
                var lod = frameGeometry.LOD[i];

                var size = 0;
                lod.GetVertexOffsets(out size);
                if (vertexBuffers[i].Data.Length != (size * lod.NumVerts))
                {
                    throw new SystemException();
                }
                lod.IndexBufferRef  = new HashName("M2TK." + model.Name + ".IB" + i);
                lod.VertexBufferRef = new HashName("M2TK." + model.Name + ".VB" + i);
            }

            if (model.IsSkinned)
            {
                CreateSkinnedObjectsFromModel();
            }
        }
Ejemplo n.º 4
0
            public void BuildBasicCollision(Lod model)
            {
                nxs  = Convert.ToString(22239310);
                mesh = Convert.ToString(1213416781);

                ver   = 1;
                flags = MeshSerialFlags.MSF_MATERIALS;
                convexEdgeThreshold = 0.001f;
                maxVertices         = 255;
                num4       = 0;
                nPoints    = model.Vertices.Length;
                nTriangles = model.Indices.Length / 3;
                points     = new Vector3[nPoints];
                indices    = new uint[model.Indices.Length];
                materials  = new CollisionMaterials[model.Indices.Length];

                int idx = 0;

                for (int i = 0; i != model.Parts.Length; i++)
                {
                    ModelPart part = model.Parts[i];
                    for (int x = (int)part.StartIndex; x < part.StartIndex + part.NumFaces * 3; x++)
                    {
                        indices[x] = model.Indices[x];
                        Enum.TryParse(model.Parts[i].Material, true, out materials[x]);
                    }
                }

                for (int i = 0; i != points.Length; i++)
                {
                    points[i] = model.Vertices[i].Position;
                }

                numConvexParts = 0;
                numFlatParts   = 0;

                convexParts = new short[nTriangles];
                flatParts   = new short[nTriangles];

                opcHbmData = new HBMOPCDataClass();
                opcHbmData.BuildBasicOPCHBM();

                boundingBox = new BoundingBox();
                unkFloats   = new float[14];

                //sort out bounding box/sphere
                List <Vertex[]> data = new List <Vertex[]>();

                data.Add(model.Vertices);
                boundingBox    = new BoundingBox();
                boundingSphere = new BoundingSphere();
                boundingBox    = BoundingBoxExtenders.CalculateBounds(data);
                boundingSphere = BoundingSphereExtenders.CalculateFromBBox(boundingBox);

                unkSize     = nTriangles;
                unkSizeData = new byte[unkSize];
                for (int i = 0; i != unkSizeData.Length; i++)
                {
                    unkSizeData[i] = 0;
                }
            }