AddMeshObject() public method

public AddMeshObject ( MeshObject obj ) : void
obj MeshObject
return void
Beispiel #1
0
        public void LoadMeshes(Renderer.Renderer renderer, string path, Matrix4 transform, Vector4 tintColor, Package currentPackage = null, string skin = null)
        {
            var data = (NTRO)Resource.Blocks[BlockType.DATA];

            var refMeshes      = (NTROArray)data.Output["m_refMeshes"];
            var materialGroups = (NTROArray)data.Output["m_materialGroups"];

            for (var i = 0; i < refMeshes.Count; i++)
            {
                var refMesh = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)refMeshes[i]).Value;

                var newResource = FileExtensions.LoadFileByAnyMeansNecessary(refMesh.Name + "_c", path, currentPackage);
                if (newResource == null)
                {
                    Console.WriteLine("unable to load mesh " + refMesh.Name);

                    continue;
                }

                if (!newResource.Blocks.ContainsKey(BlockType.VBIB))
                {
                    Console.WriteLine("Old style model, no VBIB!");

                    continue;
                }

                var skinMaterials = new List <string>();

                if (!string.IsNullOrEmpty(skin))
                {
                    foreach (var materialGroup2 in materialGroups)
                    {
                        var materialGroup = ((NTROValue <NTROStruct>)materialGroup2).Value;

                        if (((NTROValue <string>)materialGroup["m_name"]).Value == skin)
                        {
                            var materials = (NTROArray)materialGroup["m_materials"];

                            foreach (var material in materials)
                            {
                                skinMaterials.Add(((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)material).Value.Name);
                            }

                            break;
                        }
                    }
                }

                renderer.AddMeshObject(new MeshObject
                {
                    Resource      = newResource,
                    Transform     = transform,
                    TintColor     = tintColor,
                    SkinMaterials = skinMaterials
                });

                // TODO: Only first, again.
                break;
            }
        }
        public void LoadMeshes(Renderer.Renderer renderer, string path, Matrix4 transform, Vector4 tintColor, Package currentPackage = null, string skin = null)
        {
            var data = model.GetData();

            var refMeshes      = data.GetArray <string>("m_refMeshes");
            var materialGroups = data.GetArray("m_materialGroups");

            for (var i = 0; i < refMeshes.Length; i++)
            {
                var refMesh = refMeshes[i];

                var newResource = FileExtensions.LoadFileByAnyMeansNecessary(refMesh + "_c", path, currentPackage);
                if (newResource == null)
                {
                    Console.WriteLine("unable to load mesh " + refMesh);

                    continue;
                }

                if (!newResource.Blocks.ContainsKey(BlockType.VBIB))
                {
                    Console.WriteLine("Old style model, no VBIB!");

                    continue;
                }

                var skinMaterials = new List <string>();

                if (!string.IsNullOrEmpty(skin))
                {
                    foreach (var materialGroup in materialGroups)
                    {
                        if (materialGroup.GetProperty <string>("m_name") == skin)
                        {
                            var materials = materialGroup.GetArray <string>("m_materials");
                            skinMaterials.AddRange(materials);
                            break;
                        }
                    }
                }

                renderer.AddMeshObject(new MeshObject
                {
                    Resource      = newResource,
                    Transform     = transform,
                    TintColor     = tintColor,
                    SkinMaterials = skinMaterials,
                });

                // TODO: Only first, again.
                break;
            }
        }
        internal void AddMeshes(Renderer.Renderer renderer, string path, Package package)
        {
            var data = worldNode.GetData();

            var sceneObjectLayerIndices = data.GetIntegerArray("m_sceneObjectLayerIndices");
            var sceneObjects            = data.GetArray("m_sceneObjects");
            var i = 0;

            // Output is WorldNode_t we need to iterate m_sceneObjects inside it
            foreach (var sceneObject in sceneObjects)
            {
                var layerIndex = sceneObjectLayerIndices[i];
                i++;

                // TODO: We want UI for this
                if (layerIndex == 2 || layerIndex == 4)
                {
                    continue;
                }

                // sceneObject is SceneObject_t
                var renderableModel = sceneObject.GetProperty <string>("m_renderableModel");
                var transform       = sceneObject.GetArray("m_vTransform");

                var matrix = Matrix4.Identity;

                // what is this
                for (var x = 0; x < transform.Length; x++)
                {
                    var a = transform[x].ToVector4();

                    switch (x)
                    {
                    case 0: matrix.Column0 = new Vector4(a.X, a.Y, a.Z, a.W); break;

                    case 1: matrix.Column1 = new Vector4(a.X, a.Y, a.Z, a.W); break;

                    case 2: matrix.Column2 = new Vector4(a.X, a.Y, a.Z, a.W); break;

                    case 3: matrix.Column3 = new Vector4(a.X, a.Y, a.Z, a.W); break;
                    }
                }

                var tintColorWrongVector = sceneObject.GetSubCollection("m_vTintColor").ToVector4();

                Vector4 tintColor;
                if (tintColorWrongVector.W == 0)
                {
                    tintColor = Vector4.One;
                    Console.WriteLine("Ignoring tintColor, it will f**k things up.");
                }
                else
                {
                    tintColor = new Vector4(tintColorWrongVector.X, tintColorWrongVector.Y, tintColorWrongVector.Z, tintColorWrongVector.W);
                }

                if (renderableModel != null)
                {
                    var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderableModel + "_c", path, package);
                    if (newResource == null)
                    {
                        Console.WriteLine("unable to load model " + renderableModel + "_c");

                        continue;
                    }

                    var model      = new Model(newResource);
                    var modelEntry = new RenderModel(model);
                    modelEntry.LoadMeshes(renderer, path, matrix, tintColor, package);
                }

                var renderable = sceneObject.GetProperty <string>("m_renderable");

                if (renderable != null)
                {
                    var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderable + "_c", path, package);
                    if (newResource == null)
                    {
                        Console.WriteLine("unable to load renderable " + renderable + "_c");

                        continue;
                    }

                    renderer.AddMeshObject(new MeshObject
                    {
                        Resource  = newResource,
                        Transform = matrix,
                        TintColor = tintColor,
                    });
                }
            }
        }
        internal void AddMeshes(Renderer.Renderer renderer, string path, Package package)
        {
            var data = Resource.Blocks[BlockType.DATA] as NTRO;

            // Output is WorldNode_t we need to iterate m_sceneObjects inside it.

            var sceneObjectLayerIndices = (NTROArray)data.Output["m_sceneObjectLayerIndices"];
            var sceneObjects = (NTROArray)data.Output["m_sceneObjects"];
            var i = 0;
            foreach (var entry in sceneObjects)
            {
                var layerIndice = ((NTROValue<byte>)sceneObjectLayerIndices[i]).Value;
                i++;

                // TODO: We want UI for this
                if (layerIndice == 2 || layerIndice == 4)
                {
                    continue;
                }

                // sceneObject is SceneObject_t
                var sceneObject = ((NTROValue<NTROStruct>)entry).Value;
                var renderableModel = ((NTROValue<ResourceExtRefList.ResourceReferenceInfo>)sceneObject["m_renderableModel"]).Value;
                var transform = (NTROArray)sceneObject["m_vTransform"];

                var matrix = default(Matrix4);

                // what is this
                for (var x = 0; x < 4; x++)
                {
                    var a = ((NTROValue<Vector4>)transform[x]).Value;

                    switch (x)
                    {
                        case 0: matrix.Column0 = new OpenTK.Vector4(a.X, a.Y, a.Z, a.W); break;
                        case 1: matrix.Column1 = new OpenTK.Vector4(a.X, a.Y, a.Z, a.W); break;
                        case 2: matrix.Column2 = new OpenTK.Vector4(a.X, a.Y, a.Z, a.W); break;
                        case 3: matrix.Column3 = new OpenTK.Vector4(a.X, a.Y, a.Z, a.W); break;
                    }
                }

                var tintColorWrongVector = ((NTROValue<Vector4>)sceneObject["m_vTintColor"]).Value;

                OpenTK.Vector4 tintColor;
                if (tintColorWrongVector.W == 0)
                {
                    tintColor = OpenTK.Vector4.One;
                    Console.WriteLine("Ignoring tintColor, it will f**k things up.");
                }
                else
                {
                    tintColor = new OpenTK.Vector4(tintColorWrongVector.X, tintColorWrongVector.Y, tintColorWrongVector.Z, tintColorWrongVector.W);
                }

                if (renderableModel != null)
                {
                    var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderableModel.Name + "_c", path, package);
                    if (newResource == null)
                    {
                        Console.WriteLine("unable to load model " + renderableModel.Name + "_c");

                        continue;
                    }

                    var modelEntry = new Model(newResource);
                    modelEntry.LoadMeshes(renderer, path, matrix, tintColor, package);
                }

                var renderable = ((NTROValue<ResourceExtRefList.ResourceReferenceInfo>)sceneObject["m_renderable"]).Value;

                if (renderable != null)
                {
                    var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderable.Name + "_c", path, package);
                    if (newResource == null)
                    {
                        Console.WriteLine("unable to load renderable " + renderable.Name + "_c");

                        continue;
                    }

                    renderer.AddMeshObject(new MeshObject
                    {
                        Resource = newResource,
                        Transform = matrix,
                        TintColor = tintColor
                    });
                }
            }
        }
Beispiel #5
0
        internal void AddMeshes(Renderer.Renderer renderer, string path, Package package)
        {
            var data = Resource.Blocks[BlockType.DATA] as NTRO;

            var sceneObjectLayerIndices = (NTROArray)data.Output["m_sceneObjectLayerIndices"];
            var sceneObjects            = (NTROArray)data.Output["m_sceneObjects"];
            var i = 0;

            // Output is WorldNode_t we need to iterate m_sceneObjects inside it
            foreach (var entry in sceneObjects)
            {
                var layerIndice = ((NTROValue <byte>)sceneObjectLayerIndices[i]).Value;
                i++;

                // TODO: We want UI for this
                if (layerIndice == 2 || layerIndice == 4)
                {
                    continue;
                }

                // sceneObject is SceneObject_t
                var sceneObject     = ((NTROValue <NTROStruct>)entry).Value;
                var renderableModel = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)sceneObject["m_renderableModel"]).Value;
                var transform       = (NTROArray)sceneObject["m_vTransform"];

                var matrix = default(Matrix4);

                // what is this
                for (var x = 0; x < 4; x++)
                {
                    var a = ((NTROValue <System.Numerics.Vector4>)transform[x]).Value;

                    switch (x)
                    {
                    case 0: matrix.Column0 = new Vector4(a.X, a.Y, a.Z, a.W); break;

                    case 1: matrix.Column1 = new Vector4(a.X, a.Y, a.Z, a.W); break;

                    case 2: matrix.Column2 = new Vector4(a.X, a.Y, a.Z, a.W); break;

                    case 3: matrix.Column3 = new Vector4(a.X, a.Y, a.Z, a.W); break;
                    }
                }

                var tintColorWrongVector = ((NTROValue <System.Numerics.Vector4>)sceneObject["m_vTintColor"]).Value;

                Vector4 tintColor;
                if (tintColorWrongVector.W == 0)
                {
                    tintColor = Vector4.One;
                    Console.WriteLine("Ignoring tintColor, it will f**k things up.");
                }
                else
                {
                    tintColor = new Vector4(tintColorWrongVector.X, tintColorWrongVector.Y, tintColorWrongVector.Z, tintColorWrongVector.W);
                }

                if (renderableModel != null)
                {
                    var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderableModel.Name + "_c", path, package);
                    if (newResource == null)
                    {
                        Console.WriteLine("unable to load model " + renderableModel.Name + "_c");

                        continue;
                    }

                    var modelEntry = new Model(newResource);
                    modelEntry.LoadMeshes(renderer, path, matrix, tintColor, package);
                }

                var renderable = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)sceneObject["m_renderable"]).Value;

                if (renderable != null)
                {
                    var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderable.Name + "_c", path, package);
                    if (newResource == null)
                    {
                        Console.WriteLine("unable to load renderable " + renderable.Name + "_c");

                        continue;
                    }

                    renderer.AddMeshObject(new MeshObject
                    {
                        Resource  = newResource,
                        Transform = matrix,
                        TintColor = tintColor,
                    });
                }
            }
        }
        public void LoadMeshes(Renderer.Renderer renderer, string path, Matrix4 transform, Vector4 tintColor, Package currentPackage = null, string skin = null)
        {
            var data = (NTRO)Resource.Blocks[BlockType.DATA];

            var refMeshes = (NTROArray)data.Output["m_refMeshes"];
            var materialGroups = (NTROArray)data.Output["m_materialGroups"];

            for (var i = 0; i < refMeshes.Count; i++)
            {
                var refMesh = ((NTROValue<ResourceExtRefList.ResourceReferenceInfo>)refMeshes[i]).Value;

                var newResource = FileExtensions.LoadFileByAnyMeansNecessary(refMesh.Name + "_c", path, currentPackage);
                if (newResource == null)
                {
                    Console.WriteLine("unable to load mesh " + refMesh.Name);

                    continue;
                }

                if (!newResource.Blocks.ContainsKey(BlockType.VBIB))
                {
                    Console.WriteLine("Old style model, no VBIB!");

                    continue;
                }

                var skinMaterials = new List<string>();

                if (!string.IsNullOrEmpty(skin))
                {
                    foreach (var materialGroup2 in materialGroups)
                    {
                        var materialGroup = ((NTROValue<NTROStruct>)materialGroup2).Value;

                        if (((NTROValue<string>)materialGroup["m_name"]).Value == skin)
                        {
                            var materials = (NTROArray)materialGroup["m_materials"];

                            foreach (var material in materials)
                            {
                                skinMaterials.Add(((NTROValue<ResourceExtRefList.ResourceReferenceInfo>)material).Value.Name);
                            }

                            break;
                        }
                    }
                }

                renderer.AddMeshObject(new MeshObject
                {
                    Resource = newResource,
                    Transform = transform,
                    TintColor = tintColor,
                    SkinMaterials = skinMaterials
                });

                // TODO: Only first, again.
                break;
            }
        }