Beispiel #1
0
        public static void Open(string FileName, SBScene Scene)
        {
            ISSBH_File File;

            if (SSBH.TryParseSSBHFile(FileName, out File))
            {
                if (File is MESH mesh)
                {
                    if (mesh.VersionMajor != 1 && mesh.VersionMinor != 10)
                    {
                        SBConsole.WriteLine($"Mesh Version {mesh.VersionMajor}.{mesh.VersionMinor} not supported");
                        return;
                    }
                    if (mesh.UnknownOffset != 0 || mesh.UnknownSize != 0)
                    {
                        SBConsole.WriteLine($"Warning: Unknown Mesh format detected");
                    }

                    SBUltimateModel model = new SBUltimateModel();
                    model.Name           = mesh.ModelName;
                    model.BoundingSphere = new Vector4(mesh.BoundingSphereX, mesh.BoundingSphereY, mesh.BoundingSphereZ, mesh.BoundingSphereRadius);

                    ((SBSceneSSBH)Scene).Model = model;

                    SSBHVertexAccessor accessor = new SSBHVertexAccessor(mesh);
                    {
                        foreach (var meshObject in mesh.Objects)
                        {
                            SBUltimateMesh sbMesh = new SBUltimateMesh();
                            foreach (var attr in meshObject.Attributes)
                            {
                                foreach (var atstring in attr.AttributeStrings)
                                {
                                    UltimateVertexAttribute at;
                                    if (Enum.TryParse(atstring.Name, out at))
                                    {
                                        sbMesh.EnableAttribute(at);
                                    }
                                }
                            }
                            sbMesh.Name       = meshObject.Name;
                            sbMesh.ParentBone = meshObject.ParentBoneName;

                            sbMesh.BoundingSphere = new BoundingSphere(meshObject.BoundingSphereX, meshObject.BoundingSphereY, meshObject.BoundingSphereZ, meshObject.BoundingSphereRadius);
                            sbMesh.AABoundingBox  = new AABoundingBox(new Vector3(meshObject.MinBoundingBoxX, meshObject.MinBoundingBoxY, meshObject.MinBoundingBoxZ),
                                                                      new Vector3(meshObject.MaxBoundingBoxX, meshObject.MaxBoundingBoxY, meshObject.MaxBoundingBoxZ));
                            sbMesh.OrientedBoundingBox = new OrientedBoundingBox(new Vector3(meshObject.OBBCenterX, meshObject.OBBCenterY, meshObject.OBBCenterZ),
                                                                                 new Vector3(meshObject.OBBSizeX, meshObject.OBBSizeY, meshObject.OBBSizeZ),
                                                                                 new Matrix3(meshObject.M11, meshObject.M12, meshObject.M13,
                                                                                             meshObject.M21, meshObject.M22, meshObject.M23,
                                                                                             meshObject.M31, meshObject.M32, meshObject.M33));

                            sbMesh.Indices  = new List <uint>(accessor.ReadIndices(0, meshObject.IndexCount, meshObject));
                            sbMesh.Vertices = CreateVertices(mesh, Scene.Skeleton, meshObject, accessor, sbMesh.Indices.ToArray());
                            model.Meshes.Add(sbMesh);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public static MODL CreateMODLFile(SBUltimateModel model)
        {
            MODL modl = new MODL();

            modl.ModelEntries = new MODL_Entry[model.Meshes.Count];
            Dictionary <string, int> subindex = new Dictionary <string, int>();
            int i = 0;

            foreach (var mesh in model.Meshes)
            {
                var entry = new MODL_Entry();
                modl.ModelEntries[i++] = entry;

                if (!subindex.ContainsKey(mesh.Name))
                {
                    subindex.Add(mesh.Name, 0);
                }

                entry.MeshName = mesh.Name;
                entry.SubIndex = subindex[mesh.Name];
                if (mesh.Material != null)
                {
                    entry.MaterialName = mesh.Material.Label;
                }
                else
                {
                    SBConsole.WriteLine("Warning: Missing material");
                }
                subindex[mesh.Name]++;
                SBConsole.WriteLine($"Creating modl entry: {entry.MeshName} {entry.SubIndex} {entry.MaterialName}");
            }

            return(modl);
        }
Beispiel #3
0
        public static void Open(string FileName, SBScene Scene)
        {
            ISSBH_File File;

            if (SSBH.TryParseSSBHFile(FileName, out File))
            {
                if (File is MESH mesh)
                {
                    if (mesh.VersionMajor != 1 && mesh.VersionMinor != 10)
                    {
                        SBConsole.WriteLine($"Mesh Version {mesh.VersionMajor}.{mesh.VersionMinor} not supported");
                        return;
                    }
                    if (mesh.UnknownOffset != 0 || mesh.UnknownSize != 0)
                    {
                        SBConsole.WriteLine($"Warning: Unknown Mesh format detected");
                    }

                    SBUltimateModel model = new SBUltimateModel();
                    model.Name           = mesh.ModelName;
                    model.BoundingSphere = new Vector4(mesh.BoundingSphereX, mesh.BoundingSphereY, mesh.BoundingSphereZ, mesh.BoundingSphereRadius / 2);

                    Vector3 min = new Vector3(mesh.MinBoundingBoxX, mesh.MinBoundingBoxY, mesh.MinBoundingBoxZ);
                    Vector3 max = new Vector3(mesh.MaxBoundingBoxX, mesh.MaxBoundingBoxY, mesh.MaxBoundingBoxZ);

                    model.VolumeCenter = (max + min) / 2;
                    model.VolumeSize   = (max - min) / 2;

                    ((SBSceneSSBH)Scene).Model = model;

                    using (SSBHVertexAccessor accessor = new SSBHVertexAccessor(mesh))
                    {
                        foreach (var meshObject in mesh.Objects)
                        {
                            SBUltimateMesh <UltimateVertex> sbMesh = new SBUltimateMesh <UltimateVertex>();
                            foreach (var attr in meshObject.Attributes)
                            {
                                foreach (var atstring in attr.AttributeStrings)
                                {
                                    MESHAttribute at;
                                    if (Enum.TryParse <MESHAttribute>(atstring.Name, out at))
                                    {
                                        //SBConsole.WriteLine("\tLoaded:" + at.ToString());
                                        sbMesh.ExportAttributes.Add(at);
                                    }
                                }
                            }
                            sbMesh.Name           = meshObject.Name;
                            sbMesh.BoundingSphere = new Vector4(meshObject.BoundingSphereX, meshObject.BoundingSphereY, meshObject.BoundingSphereZ, meshObject.BoundingSphereRadius);
                            sbMesh.ParentBone     = meshObject.ParentBoneName;

                            sbMesh.Indices  = new List <uint>(accessor.ReadIndices(0, meshObject.IndexCount, meshObject));
                            sbMesh.Vertices = CreateVertices(mesh, Scene.Skeleton, meshObject, accessor, sbMesh.Indices.ToArray());
                            model.Meshes.Add(sbMesh);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public static void Open(string FileName, SBScene Scene)
        {
            SsbhFile File;

            if (Ssbh.TryParseSsbhFile(FileName, out File))
            {
                if (File is Mesh mesh)
                {
                    if (mesh.VersionMajor != 1 && mesh.VersionMinor != 10)
                    {
                        SBConsole.WriteLine($"Mesh Version {mesh.VersionMajor}.{mesh.VersionMinor} not supported");
                        return;
                    }
                    if (mesh.UnknownOffset != 0 || mesh.UnknownSize != 0)
                    {
                        SBConsole.WriteLine($"Warning: Unknown Mesh format detected");
                    }

                    SBUltimateModel model = new SBUltimateModel();
                    model.Name           = mesh.ModelName;
                    model.BoundingSphere = new Vector4(mesh.BoundingSphereCenter.X, mesh.BoundingSphereCenter.Y, mesh.BoundingSphereCenter.Z, mesh.BoundingSphereRadius);

                    ((SBSceneSSBH)Scene).Model = model;

                    SsbhVertexAccessor accessor = new SsbhVertexAccessor(mesh);
                    {
                        foreach (var meshObject in mesh.Objects)
                        {
                            SBUltimateMesh sbMesh = new SBUltimateMesh();
                            sbMesh.EnableAttributes(meshObject);

                            sbMesh.Name       = meshObject.Name;
                            sbMesh.ParentBone = meshObject.ParentBoneName;

                            sbMesh.BoundingSphere = new BoundingSphere(meshObject.BoundingSphereCenter.X, meshObject.BoundingSphereCenter.Y, meshObject.BoundingSphereCenter.Z, meshObject.BoundingSphereRadius);
                            sbMesh.AABoundingBox  = new AABoundingBox(new Vector3(meshObject.BoundingBoxMin.X, meshObject.BoundingBoxMin.Y, meshObject.BoundingBoxMin.Z),
                                                                      new Vector3(meshObject.BoundingBoxMax.X, meshObject.BoundingBoxMax.Y, meshObject.BoundingBoxMax.Z));
                            sbMesh.OrientedBoundingBox = new OrientedBoundingBox(
                                meshObject.OrientedBoundingBoxCenter.ToOpenTK(),
                                meshObject.OrientedBoundingBoxSize.ToOpenTK(),
                                meshObject.OrientedBoundingBoxTransform.ToOpenTK());

                            sbMesh.Indices  = new List <uint>(accessor.ReadIndices(0, meshObject.IndexCount, meshObject));
                            sbMesh.Vertices = CreateVertices(mesh, Scene.Skeleton, meshObject, accessor, sbMesh.Indices.ToArray());
                            model.Meshes.Add(sbMesh);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Imports information into this scene from an IO Model
        /// </summary>
        public override void FromIOModel(IOModel iomodel)
        {
            // copy skeleton
            Skeleton = iomodel.Skeleton;

            // make temp material
            UltimateMaterial material = new UltimateMaterial();

            material.Name  = "SFX_PBS_0100080008008269_opaque";
            material.Label = "skin_sonic_001";

            //TODO more elegant material management
            Materials.Add(material);

            // convert meshes
            SBUltimateModel model = new SBUltimateModel();

            foreach (var iomesh in iomodel.Meshes)
            {
                SBUltimateMesh <UltimateVertex> mesh = new SBUltimateMesh <UltimateVertex>();
                mesh.Name       = iomesh.Name;
                mesh.ParentBone = "";
                mesh.Material   = material;

                model.Meshes.Add(mesh);

                mesh.Indices = iomesh.Indices;

                iomesh.GenerateTangentsAndBitangents();

                foreach (var vertex in iomesh.Vertices)
                {
                    mesh.Vertices.Add(IOToUltimateVertex(vertex));
                }

                //TODO: make more customizable through import settings
                mesh.ExportAttributes.Add(SSBHLib.Tools.MESHAttribute.Position0);
                mesh.ExportAttributes.Add(SSBHLib.Tools.MESHAttribute.Normal0);
                mesh.ExportAttributes.Add(SSBHLib.Tools.MESHAttribute.Tangent0);
                mesh.ExportAttributes.Add(SSBHLib.Tools.MESHAttribute.map1);
                mesh.ExportAttributes.Add(SSBHLib.Tools.MESHAttribute.colorSet1);
            }

            Model = model;
        }