Exemplo n.º 1
0
        private static void GetAtomicTriangleList(Scene scene, AtomicSector_0009 atomic)
        {
            if (atomic.atomicSectorStruct.isNativeData)
            {
                GetNativeTriangleList(scene, atomic.atomicSectorExtension);
                return;
            }

            int[] totalVertexIndices = new int[scene.MeshCount];

            for (int i = 0; i < scene.MeshCount; i++)
            {
                totalVertexIndices[i] = scene.Meshes[i].VertexCount;
            }

            foreach (RenderWareFile.Triangle t in atomic.atomicSectorStruct.triangleArray)
            {
                scene.Meshes[t.materialIndex].Faces.Add(new Face(new int[] {
                    t.vertex1 + totalVertexIndices[t.materialIndex],
                    t.vertex2 + totalVertexIndices[t.materialIndex],
                    t.vertex3 + totalVertexIndices[t.materialIndex]
                }));
            }

            foreach (Mesh mesh in scene.Meshes)
            {
                foreach (Vertex3 v in atomic.atomicSectorStruct.vertexArray)
                {
                    mesh.Vertices.Add(new Vector3D(v.X, v.Y, v.Z));
                }

                foreach (Vertex2 v in atomic.atomicSectorStruct.uvArray)
                {
                    mesh.TextureCoordinateChannels[0].Add(new Vector3D(v.X, v.Y, 0f));
                }

                foreach (RenderWareFile.Color c in atomic.atomicSectorStruct.colorArray)
                {
                    mesh.VertexColorChannels[0].Add(new Color4D(
                                                        c.R / 255f,
                                                        c.G / 255f,
                                                        c.B / 255f,
                                                        c.A / 255f));
                }
            }
        }
        private static void GetAtomicTriangleList(StreamWriter OBJWriter, AtomicSector_0009 AtomicSector, ref List <Triangle> triangleList, ref int totalVertexIndices, bool isCollision)
        {
            if (AtomicSector.atomicStruct.isNativeData)
            {
                GetNativeTriangleList(OBJWriter, AtomicSector.atomicExtension, ref triangleList, ref totalVertexIndices);
                return;
            }

            //Write vertex list to obj
            if (AtomicSector.atomicStruct.vertexArray != null)
            {
                foreach (Vertex3 i in AtomicSector.atomicStruct.vertexArray)
                {
                    OBJWriter.WriteLine("v " + i.X.ToString() + " " + i.Y.ToString() + " " + i.Z.ToString());
                }
            }

            OBJWriter.WriteLine();

            //Write uv list to obj
            if (AtomicSector.atomicStruct.uvArray != null)
            {
                if (Program.levelEditor.checkBoxFlipUVs.Checked)
                {
                    foreach (TextCoord i in AtomicSector.atomicStruct.uvArray)
                    {
                        OBJWriter.WriteLine("vt " + i.X.ToString() + " " + (-i.Y).ToString());
                    }
                }
                else
                {
                    foreach (TextCoord i in AtomicSector.atomicStruct.uvArray)
                    {
                        OBJWriter.WriteLine("vt " + i.X.ToString() + " " + i.Y.ToString());
                    }
                }
            }
            OBJWriter.WriteLine();

            // Write vcolors to obj
            if (AtomicSector.atomicStruct.colorArray != null)
            {
                foreach (RenderWareFile.Color i in AtomicSector.atomicStruct.colorArray)
                {
                    //if (i.R < 255)
                    //{
                    //    OBJWriter.WriteLine("vc " + ((byte)Math.Min(255, i.R * 2.5f)).ToString() + " " + ((byte)(i.G * 0.6f)).ToString() + " " + ((byte)(i.B * 0.3f)).ToString() + " " + i.A.ToString());
                    //}
                    //else
                    //{
                    OBJWriter.WriteLine("vc " + i.R.ToString() + " " + i.G.ToString() + " " + i.B.ToString() + " " + i.A.ToString());
                    //}
                }
            }

            OBJWriter.WriteLine();

            if (AtomicSector.atomicStruct.triangleArray != null)
            {
                if (isCollision)
                {
                    RenderWareFile.Color[] collisionFlagList = new RenderWareFile.Color[0];
                    foreach (RWSection r in AtomicSector.atomicExtension.extensionSectionList)
                    {
                        if (r is UserDataPLG_011F userdata)
                        {
                            collisionFlagList = userdata.collisionFlags;
                        }
                    }

                    for (int i = 0; i < AtomicSector.atomicStruct.triangleArray.Length; i++)
                    {
                        triangleList.Add(new TriangleExt
                        {
                            collisionFlag = collisionFlagList[i],
                            MaterialIndex = AtomicSector.atomicStruct.triangleArray[i].materialIndex,
                            vertex1       = AtomicSector.atomicStruct.triangleArray[i].vertex1 + totalVertexIndices,
                            vertex2       = AtomicSector.atomicStruct.triangleArray[i].vertex2 + totalVertexIndices,
                            vertex3       = AtomicSector.atomicStruct.triangleArray[i].vertex3 + totalVertexIndices,
                        });
                    }
                }
                else
                {
                    foreach (RenderWareFile.Triangle i in AtomicSector.atomicStruct.triangleArray)
                    {
                        triangleList.Add(new Triangle
                        {
                            MaterialIndex = i.materialIndex,
                            vertex1       = i.vertex1 + totalVertexIndices,
                            vertex2       = i.vertex2 + totalVertexIndices,
                            vertex3       = i.vertex3 + totalVertexIndices,
                        });
                    }
                }
            }

            if (AtomicSector.atomicStruct.vertexArray != null)
            {
                totalVertexIndices += AtomicSector.atomicStruct.vertexArray.Count();
            }
        }
Exemplo n.º 3
0
        private void AddAtomic(SharpDevice device, AtomicSector_0009 AtomicSector, List <string> MaterialList)
        {
            if (AtomicSector.atomicSectorStruct.isNativeData)
            {
                AddNativeData(device, AtomicSector.atomicSectorExtension, MaterialList, Matrix.Identity);
                return;
            }

            List <VertexColoredTextured> vertexList = new List <VertexColoredTextured>();

            foreach (Vertex3 v in AtomicSector.atomicSectorStruct.vertexArray)
            {
                vertexList.Add(new VertexColoredTextured(new Vector3(v.X, v.Y, v.Z), new Vector2(), new SharpDX.Color()));
                vertexListG.Add(new Vector3(v.X, v.Y, v.Z));
            }

            for (int i = 0; i < vertexList.Count; i++)
            {
                RenderWareFile.Color c = AtomicSector.atomicSectorStruct.colorArray[i];

                VertexColoredTextured v = vertexList[i];
                v.Color       = new SharpDX.Color(c.R, c.G, c.B, c.A);
                vertexList[i] = v;
            }

            for (int i = 0; i < vertexList.Count; i++)
            {
                Vertex2 tc = AtomicSector.atomicSectorStruct.uvArray[i];

                VertexColoredTextured v = vertexList[i];
                v.TextureCoordinate = new Vector2(tc.X, tc.Y);
                vertexList[i]       = v;
            }

            List <SharpSubSet> SubsetList = new List <SharpSubSet>();
            List <int>         indexList  = new List <int>();
            int previousIndexCount        = 0;

            for (int i = 0; i < MaterialList.Count; i++)
            {
                for (int j = 0; j < AtomicSector.atomicSectorStruct.triangleArray.Length; j++) // each (Triangle t in AtomicSector.atomicStruct.triangleArray)
                {
                    Triangle t = AtomicSector.atomicSectorStruct.triangleArray[j];
                    if (t.materialIndex == i)
                    {
                        indexList.Add(t.vertex1);
                        indexList.Add(t.vertex2);
                        indexList.Add(t.vertex3);

                        triangleList.Add(new Triangle(t.materialIndex, (ushort)(t.vertex1 + triangleListOffset), (ushort)(t.vertex2 + triangleListOffset), (ushort)(t.vertex3 + triangleListOffset)));
                    }
                }

                if (indexList.Count - previousIndexCount > 0)
                {
                    SubsetList.Add(new SharpSubSet(previousIndexCount, indexList.Count - previousIndexCount,
                                                   TextureManager.GetTextureFromDictionary(MaterialList[i]), MaterialList[i]));
                }

                previousIndexCount = indexList.Count();
            }

            triangleListOffset += AtomicSector.atomicSectorStruct.vertexArray.Length;

            if (SubsetList.Count > 0)
            {
                AddToMeshList(SharpMesh.Create(device, vertexList.ToArray(), indexList.ToArray(), SubsetList));
            }
        }
Exemplo n.º 4
0
        void AddAtomic(AtomicSector_0009 AtomicSector)
        {
            if (AtomicSector.atomicStruct.isNativeData)
            {
                AddNativeData(AtomicSector.atomicExtension, MaterialList);
                return;
            }

            List <VertexColoredTextured> vertexList = new List <VertexColoredTextured>();

            foreach (Vertex3 v in AtomicSector.atomicStruct.vertexArray)
            {
                vertexList.Add(new VertexColoredTextured(new Vector3(v.X, v.Y, v.Z), new Vector2(), new SharpDX.Color()));
                this.vertexList.Add(new Vector3(v.X, v.Y, v.Z));
            }

            if (!isShadowCollision)
            {
                for (int i = 0; i < vertexList.Count; i++)
                {
                    RenderWareFile.Color c = AtomicSector.atomicStruct.colorArray[i];

                    VertexColoredTextured v = vertexList[i];
                    v.Color       = new SharpDX.Color(c.R, c.G, c.B, c.A);
                    vertexList[i] = v;
                }

                for (int i = 0; i < vertexList.Count; i++)
                {
                    TextCoord tc = AtomicSector.atomicStruct.uvArray[i];

                    VertexColoredTextured v = vertexList[i];
                    v.TextureCoordinate = new Vector2(tc.X, tc.Y);
                    vertexList[i]       = v;
                }
            }

            List <SharpSubSet> SubsetList = new List <SharpSubSet>();
            List <int>         indexList  = new List <int>();
            int previousIndexCount        = 0;

            for (int i = 0; i < MaterialList.Count; i++)
            {
                for (int j = 0; j < AtomicSector.atomicStruct.triangleArray.Length; j++) // each (Triangle t in AtomicSector.atomicStruct.triangleArray)
                {
                    Triangle t = AtomicSector.atomicStruct.triangleArray[j];
                    if (t.materialIndex == i)
                    {
                        indexList.Add(t.vertex1);
                        indexList.Add(t.vertex2);
                        indexList.Add(t.vertex3);

                        if (isShadowCollision)
                        {
                            RenderWareFile.Color c     = RenderWareFile.Color.FromString(MaterialList[i]);
                            SharpDX.Color        color = new SharpDX.Color(c.R, c.G, c.B, c.A);

                            VertexColoredTextured v1 = vertexList[t.vertex1];
                            v1.Color = color;
                            vertexList[t.vertex1] = v1;

                            VertexColoredTextured v2 = vertexList[t.vertex2];
                            v2.Color = color;
                            vertexList[t.vertex2] = v2;

                            VertexColoredTextured v3 = vertexList[t.vertex3];
                            v3.Color = color;
                            vertexList[t.vertex3] = v3;
                        }

                        triangleList.Add(t);
                    }
                }

                if (indexList.Count - previousIndexCount > 0)
                {
                    if (BSPRenderer.TextureStream.ContainsKey(MaterialList[i]))
                    {
                        SubsetList.Add(new SharpSubSet(previousIndexCount, indexList.Count - previousIndexCount, BSPRenderer.TextureStream[MaterialList[i]]));
                    }
                    else
                    {
                        SubsetList.Add(new SharpSubSet(previousIndexCount, indexList.Count - previousIndexCount, BSPRenderer.whiteDefault));
                    }
                }

                previousIndexCount = indexList.Count();
            }

            if (SubsetList.Count > 0)
            {
                meshList.Add(SharpMesh.Create(SharpRenderer.device, vertexList.ToArray(), indexList.ToArray(), SubsetList));
            }
        }
Exemplo n.º 5
0
        private static void GetAtomicTriangleList(StreamWriter OBJWriter, AtomicSector_0009 AtomicSector, ref List <Triangle> triangleList, ref int totalVertexIndices, bool flipUVs)
        {
            if (AtomicSector.atomicSectorStruct.isNativeData)
            {
                GetNativeTriangleList(OBJWriter, AtomicSector.atomicSectorExtension, null, ref triangleList, ref totalVertexIndices, flipUVs);
                return;
            }

            //Write vertex list to obj
            if (AtomicSector.atomicSectorStruct.vertexArray != null)
            {
                foreach (Vertex3 i in AtomicSector.atomicSectorStruct.vertexArray)
                {
                    OBJWriter.WriteLine("v " + i.X.ToString() + " " + i.Y.ToString() + " " + i.Z.ToString());
                }
            }

            OBJWriter.WriteLine();

            //Write uv list to obj
            if (AtomicSector.atomicSectorStruct.uvArray != null)
            {
                if (flipUVs)
                {
                    foreach (Vertex2 i in AtomicSector.atomicSectorStruct.uvArray)
                    {
                        OBJWriter.WriteLine("vt " + i.X.ToString() + " " + (-i.Y).ToString());
                    }
                }
                else
                {
                    foreach (Vertex2 i in AtomicSector.atomicSectorStruct.uvArray)
                    {
                        OBJWriter.WriteLine("vt " + i.X.ToString() + " " + i.Y.ToString());
                    }
                }
            }
            OBJWriter.WriteLine();

            // Write vcolors to obj
            if (AtomicSector.atomicSectorStruct.colorArray != null)
            {
                foreach (Color i in AtomicSector.atomicSectorStruct.colorArray)
                {
                    OBJWriter.WriteLine("vc " + i.R.ToString() + " " + i.G.ToString() + " " + i.B.ToString() + " " + i.A.ToString());
                }
            }

            OBJWriter.WriteLine();

            if (AtomicSector.atomicSectorStruct.triangleArray != null)
            {
                foreach (RenderWareFile.Triangle i in AtomicSector.atomicSectorStruct.triangleArray)
                {
                    triangleList.Add(new Triangle
                    {
                        materialIndex = i.materialIndex,
                        vertex1       = i.vertex1 + totalVertexIndices,
                        vertex2       = i.vertex2 + totalVertexIndices,
                        vertex3       = i.vertex3 + totalVertexIndices,
                    });
                }
            }

            if (AtomicSector.atomicSectorStruct.vertexArray != null)
            {
                totalVertexIndices += AtomicSector.atomicSectorStruct.vertexArray.Count();
            }
        }