Exemplo n.º 1
0
        private static RWSection ToClump
            (Material_0007[] materials, BoundingSphere boundingSphere,
            Vertex3[] vertices, Vertex3[] normals, Vertex2[] textCoords, RenderWareFile.Color[] vertexColors, RenderWareFile.Triangle[] triangles,
            BinMesh[] binMeshes, bool atomicNeedsMaterialEffects)
        {
            Clump_0010 clump = new Clump_0010()
            {
                clumpStruct = new ClumpStruct_0001()
                {
                    atomicCount = 1
                },
                frameList = new FrameList_000E()
                {
                    frameListStruct = new FrameListStruct_0001()
                    {
                        frames = new List <Frame>()
                        {
                            new Frame()
                            {
                                position       = new Vertex3(),
                                rotationMatrix = RenderWareFile.Sections.Matrix3x3.Identity,
                                parentFrame    = -1,
                                unknown        = 131075
                            },
                            new Frame()
                            {
                                position       = new Vertex3(),
                                rotationMatrix = RenderWareFile.Sections.Matrix3x3.Identity,
                                parentFrame    = 0,
                                unknown        = 0
                            }
                        }
                    },
                    extensionList = new List <Extension_0003>()
                    {
                        new Extension_0003(),
                        new Extension_0003()
                    }
                },
                geometryList = new GeometryList_001A()
                {
                    geometryListStruct = new GeometryListStruct_0001()
                    {
                        numberOfGeometries = 1
                    },
                    geometryList = new List <Geometry_000F>()
                    {
                        new Geometry_000F()
                        {
                            materialList = new MaterialList_0008()
                            {
                                materialListStruct = new MaterialListStruct_0001()
                                {
                                    materialCount = materials.Length
                                },
                                materialList = materials
                            },
                            geometryStruct = new GeometryStruct_0001()
                            {
                                geometryFlags =
                                    GeometryFlags.hasLights |
                                    GeometryFlags.modeulateMaterialColor |
                                    GeometryFlags.hasTextCoords |
                                    GeometryFlags.hasVertexColors |
                                    GeometryFlags.hasVertexPositions |
                                    GeometryFlags.hasNormals,
                                geometryFlags2  = (GeometryFlags2)1,
                                numTriangles    = triangles.Length,
                                numVertices     = vertices.Length,
                                numMorphTargets = 1,
                                ambient         = 1f,
                                specular        = 1f,
                                diffuse         = 1f,
                                vertexColors    = vertexColors,
                                textCoords      = textCoords,
                                triangles       = triangles,
                                morphTargets    = new MorphTarget[]
                                {
                                    new MorphTarget()
                                    {
                                        hasNormals   = 1,
                                        hasVertices  = 1,
                                        sphereCenter = new Vertex3(
                                            boundingSphere.Center.X,
                                            boundingSphere.Center.Y,
                                            boundingSphere.Center.Z),
                                        radius   = boundingSphere.Radius,
                                        vertices = vertices,
                                        normals  = normals,
                                    }
                                }
                            },
                            geometryExtension = new Extension_0003()
                            {
                                extensionSectionList = new List <RWSection>()
                                {
                                    new BinMeshPLG_050E()
                                    {
                                        binMeshHeaderFlags = BinMeshHeaderFlags.TriangleList,
                                        numMeshes          = binMeshes.Length,
                                        totalIndexCount    = binMeshes.Sum(b => b.indexCount),
                                        binMeshList        = binMeshes
                                    }
                                }
                            }
                        }
                    }
                },
                atomicList = new List <Atomic_0014>()
                {
                    new Atomic_0014()
                    {
                        atomicStruct = new AtomicStruct_0001()
                        {
                            frameIndex    = 1,
                            geometryIndex = 0,
                            flags         = AtomicFlags.CollisionTestAndRender,
                            unused        = 0
                        },
                        atomicExtension = new Extension_0003() // check this in case something fails
                        {
                            extensionSectionList = atomicNeedsMaterialEffects ? new List <RWSection>()
                            {
                                new MaterialEffectsPLG_0120()
                                {
                                    isAtomicExtension = true,
                                    value             = (MaterialEffectType)1
                                }
                            }
                        : new List <RWSection>()
                        }
                    }
                },

                clumpExtension = new Extension_0003()
            };

            return(clump);
        }
Exemplo n.º 2
0
        public static RWSection[] CreateDFFFile(ModelConverterData data, bool flipUVs)
        {
            Vertex3 Max = new Vertex3(data.VertexList[0].Position.X, data.VertexList[0].Position.Y, data.VertexList[0].Position.Z);
            Vertex3 Min = new Vertex3(data.VertexList[0].Position.X, data.VertexList[0].Position.Y, data.VertexList[0].Position.Z);

            foreach (Vertex i in data.VertexList)
            {
                if (i.Position.X > Max.X)
                {
                    Max.X = i.Position.X;
                }
                if (i.Position.Y > Max.Y)
                {
                    Max.Y = i.Position.Y;
                }
                if (i.Position.Z > Max.Z)
                {
                    Max.Z = i.Position.Z;
                }
                if (i.Position.X < Min.X)
                {
                    Min.X = i.Position.X;
                }
                if (i.Position.Y < Min.Y)
                {
                    Min.Y = i.Position.Y;
                }
                if (i.Position.Z < Min.Z)
                {
                    Min.Z = i.Position.Z;
                }
            }

            Vertex3 sphereCenter;

            sphereCenter.X = (Max.X + Min.X) / 2f;
            sphereCenter.Y = (Max.Y + Min.Y) / 2f;
            sphereCenter.Z = (Max.Z + Min.Z) / 2f;

            float sphereRadius = Math.Max((Max.X - Min.X) / 2f, Math.Max((Max.Y - Min.Y) / 2f, (Max.Z - Min.Z) / 2f));

            List <Vertex3> vList = new List <Vertex3>(data.VertexList.Count);

            foreach (Vertex v in data.VertexList)
            {
                vList.Add(new Vertex3(v.Position.X, v.Position.Y, v.Position.Z));
            }

            List <Vertex3> nList = new List <Vertex3>(data.VertexList.Count);

            foreach (Vertex v in data.VertexList)
            {
                nList.Add(new Vertex3(-v.Normal.X, -v.Normal.Y, -v.Normal.Z));
            }

            List <Color> cList = new List <Color>(data.VertexList.Count);

            foreach (Vertex v in data.VertexList)
            {
                cList.Add(new Color(v.Color.R, v.Color.G, v.Color.B, v.Color.A));
            }

            List <Vertex2> uvList = new List <Vertex2>(data.VertexList.Count);

            if (flipUVs)
            {
                foreach (Vertex v in data.VertexList)
                {
                    uvList.Add(new Vertex2(v.TexCoord.X, v.TexCoord.Y));
                }
            }
            else
            {
                foreach (Vertex v in data.VertexList)
                {
                    uvList.Add(new Vertex2(v.TexCoord.X, -v.TexCoord.Y));
                }
            }

            List <RenderWareFile.Triangle> tList = new List <RenderWareFile.Triangle>(data.TriangleList.Count);

            foreach (Triangle t in data.TriangleList)
            {
                tList.Add(new RenderWareFile.Triangle((ushort)t.materialIndex, (ushort)t.vertex1, (ushort)t.vertex2, (ushort)t.vertex3));
            }

            List <Material_0007> materials = new List <Material_0007>(data.MaterialList.Count);

            for (int i = 0; i < data.MaterialList.Count; i++)
            {
                materials.Add(new Material_0007()
                {
                    materialStruct = new MaterialStruct_0001()
                    {
                        unusedFlags = 0,
                        color       = new Color()
                        {
                            R = 0xFF, G = 0xFF, B = 0xFF, A = 0xFF
                        },
                        unusedInt2 = currentRenderWareVersion == scoobyRenderWareVersion ? 0x27584014 : 0,
                        isTextured = 1,
                        ambient    = 1f,
                        specular   = 1f,
                        diffuse    = 1f
                    },
                    texture = new Texture_0006()
                    {
                        textureStruct = new TextureStruct_0001()
                        {
                            filterMode   = TextureFilterMode.FILTERLINEARMIPLINEAR,
                            addressModeU = TextureAddressMode.TEXTUREADDRESSWRAP,
                            addressModeV = TextureAddressMode.TEXTUREADDRESSWRAP,
                            useMipLevels = 1
                        },
                        diffuseTextureName = new String_0002()
                        {
                            stringString = data.MaterialList[i]
                        },
                        alphaTextureName = new String_0002()
                        {
                            stringString = ""
                        },
                        textureExtension = new Extension_0003()
                    },
                    materialExtension = new Extension_0003()
                });
            }

            List <BinMesh> binMeshList = new List <BinMesh>();
            int            TotalNumberOfTristripIndicies = 0;

            for (int i = 0; i < data.MaterialList.Count; i++)
            {
                List <int> indices = new List <int>();
                foreach (Triangle f in data.TriangleList)
                {
                    if (f.materialIndex == i)
                    {
                        indices.Add(f.vertex1);
                        indices.Add(f.vertex2);
                        indices.Add(f.vertex3);
                    }
                }
                TotalNumberOfTristripIndicies += indices.Count();

                binMeshList.Add(new BinMesh
                {
                    materialIndex = i,
                    indexCount    = indices.Count(),
                    vertexIndices = indices.ToArray()
                });
            }

            Clump_0010 clump = new Clump_0010()
            {
                clumpStruct = new ClumpStruct_0001()
                {
                    atomicCount = 1
                },
                frameList = new FrameList_000E()
                {
                    frameListStruct = new FrameListStruct_0001()
                    {
                        frames = new List <Frame>()
                        {
                            new Frame()
                            {
                                position       = new Vertex3(),
                                rotationMatrix = new Matrix3x3()
                                {
                                    M11 = 1f,
                                    M12 = 0f,
                                    M13 = 0f,
                                    M21 = 0f,
                                    M22 = 1f,
                                    M23 = 0f,
                                    M31 = 0f,
                                    M32 = 0f,
                                    M33 = 1f,
                                },
                                parentFrame = -1,
                                unknown     = 131075
                            },
                            new Frame()
                            {
                                position       = new Vertex3(),
                                rotationMatrix = new Matrix3x3()
                                {
                                    M11 = 1f,
                                    M12 = 0f,
                                    M13 = 0f,
                                    M21 = 0f,
                                    M22 = 1f,
                                    M23 = 0f,
                                    M31 = 0f,
                                    M32 = 0f,
                                    M33 = 1f,
                                },
                                parentFrame = 0,
                                unknown     = 0
                            }
                        }
                    },
                    extensionList = new List <Extension_0003>()
                    {
                        new Extension_0003(),
                        new Extension_0003()
                    }
                },
                geometryList = new GeometryList_001A()
                {
                    geometryListStruct = new GeometryListStruct_0001()
                    {
                        numberOfGeometries = 1,
                    },
                    geometryList = new List <Geometry_000F>()
                    {
                        new Geometry_000F()
                        {
                            geometryStruct = new GeometryStruct_0001()
                            {
                                geometryFlags   = GeometryFlags.hasLights | GeometryFlags.modeulateMaterialColor | GeometryFlags.hasTextCoords | GeometryFlags.hasVertexColors | GeometryFlags.hasVertexPositions | (nList.Count > 0 ? GeometryFlags.hasNormals:0),
                                geometryFlags2  = (GeometryFlags2)1,
                                numTriangles    = data.TriangleList.Count(),
                                numVertices     = data.VertexList.Count(),
                                numMorphTargets = 1,
                                ambient         = 1f,
                                specular        = 1f,
                                diffuse         = 1f,
                                vertexColors    = cList.ToArray(),
                                textCoords      = uvList.ToArray(),
                                triangles       = tList.ToArray(),
                                morphTargets    = new MorphTarget[]
                                {
                                    new MorphTarget()
                                    {
                                        hasNormals   = nList.Count > 0 ? 1 : 0,
                                        hasVertices  = 1,
                                        sphereCenter = sphereCenter,
                                        radius       = sphereRadius,
                                        vertices     = vList.ToArray(),
                                        normals      = nList.ToArray(),
                                    }
                                }
                            },

                            materialList = new MaterialList_0008()
                            {
                                materialListStruct = new MaterialListStruct_0001()
                                {
                                    materialCount = materials.Count()
                                },

                                materialList = materials.ToArray()
                            },

                            geometryExtension = new Extension_0003()
                            {
                                extensionSectionList = new List <RWSection>()
                                {
                                    new BinMeshPLG_050E()
                                    {
                                        binMeshHeaderFlags = BinMeshHeaderFlags.TriangleList,
                                        numMeshes          = binMeshList.Count(),
                                        totalIndexCount    = TotalNumberOfTristripIndicies,
                                        binMeshList        = binMeshList.ToArray()
                                    }
                                }
                            }
                        }
                    }
                },
                atomicList = new List <Atomic_0014>()
                {
                    new Atomic_0014()
                    {
                        atomicStruct = new AtomicStruct_0001()
                        {
                            frameIndex    = 1,
                            geometryIndex = 0,
                            unknown1      = 5,
                            unknown2      = 0
                        },
                        atomicExtension = currentRenderWareVersion == scoobyRenderWareVersion ? new Extension_0003()
                        {
                            extensionSectionList = new List <RWSection>()
                            {
                                new MaterialEffectsPLG_0120()
                                {
                                    value = 0
                                }
                            }
                        } : new Extension_0003()
                    }
                },

                clumpExtension = new Extension_0003()
            };

            return(new RWSection[] { clump });
        }