Exemple #1
0
        public static CompiledModel CompileModel(RawModel model, GraphicsDevice device)
        {
            CompiledModel result = new CompiledModel();

            var combinedIndex = CompileIndicies(model);
            result.indicies = new IndexBuffer(device, typeof(Int16), combinedIndex.Length, BufferUsage.WriteOnly);
            result.indicies.SetData(combinedIndex);

            if (model.IsTextured)
            {
                var combinedVertex = CompileTexturedVerticies(model);
                result.verticies = new VertexBuffer(device, typeof(TexturedVertex), combinedVertex.Length, BufferUsage.WriteOnly);
                result.verticies.SetData(combinedVertex);
                result.Textured = true;
            }
            else
            {
                var combinedVertex = CompileVerticies(model);
                result.verticies = new VertexBuffer(device, typeof(Vertex), combinedVertex.Length, BufferUsage.WriteOnly);
                result.verticies.SetData(combinedVertex);
                result.Textured = false;
            }

            result.primitiveCount = combinedIndex.Length / 3;
            result.boundingSphere = new BoundingSphere(Vector3.Zero, 1);

            return result;
        }
Exemple #2
0
 public static RawModel ModelArgument(Object o)
 {
     if (o is RawModel) return o as RawModel;
     if (o is Mesh)
     {
         var m = new RawModel();
         m.AddPart(o as Mesh);
         return m;
     }
     throw new ScriptError("Object isn't a model.", null);
 }
Exemple #3
0
        public static Vertex[] CompileVerticies(RawModel model)
        {
            var combinedVertex = new Vertex[model.TotalVerticies];

            int vCount = 0;
            foreach (var part in model.parts)
            {
                for (int i = 0; i < part.verticies.Length; ++i)
                    combinedVertex[i + vCount] = part.GetVertex(i);
                vCount += part.VertexCount;
            }

            return combinedVertex;
        }
Exemple #4
0
        public static short[] CompileIndicies(RawModel model)
        {
            var combinedIndex = new short[model.TotalIndicies];
            int vCount = 0;
            int iCount = 0;
            foreach (var part in model.parts)
            {
                for (int i = 0; i < part.indicies.Length; ++i) combinedIndex[i + iCount] = (short)(part.indicies[i] + vCount);
                vCount += part.VertexCount;
                iCount += part.indicies.Length;
            }

            return combinedIndex;
        }
Exemple #5
0
 public void AddParts(RawModel other)
 {
     parts.AddRange(other.parts);
 }