Exemple #1
0
        private void WandOben(int x, int z)
        {
            int oldIndex = vertexListWaende.Count;

            vertexListWaende.Add(new VertexPositionTexture(new Vector3(x * step, 0, z * step + step), new Vector2(0, 0)));
            vertexListWaende.Add(new VertexPositionTexture(new Vector3(x * step, height, z * step + step), new Vector2(0, 1)));
            vertexListWaende.Add(new VertexPositionTexture(new Vector3(x * step + step, 0, z * step + step), new Vector2(1, 0)));
            vertexListWaende.Add(new VertexPositionTexture(new Vector3(x * step + step, height, z * step + step), new Vector2(1, 1)));

            List <Vector3> templist = new List <Vector3>();

            for (int i = oldIndex; i < vertexListWaende.Count; i++)
            {
                templist.Add(vertexListWaende[i].Position);
            }
            BoundingBoxes.Add(BoundingBox.CreateFromPoints(templist));
            //Console.WriteLine(BoundingBox.CreateFromPoints(templist).Min + " - " + BoundingBox.CreateFromPoints(templist).Max);

            indexListWaende.Add(Convert.ToInt16(oldIndex));
            indexListWaende.Add(Convert.ToInt16(oldIndex + 3));
            indexListWaende.Add(Convert.ToInt16(oldIndex + 1));
            indexListWaende.Add(Convert.ToInt16(oldIndex));
            indexListWaende.Add(Convert.ToInt16(oldIndex + 2));
            indexListWaende.Add(Convert.ToInt16(oldIndex + 3));
        }
Exemple #2
0
 public void MouseUp(Point point)
 {
     if (IsMouseDown)
     {
         var rect = new Rect(mouseDownLocation, point);
         BoundingBoxes.Add(new BoundingBox(rect, SelectedClass));
     }
     IsMouseDown = false;
 }
Exemple #3
0
        private void ExObjectDetect()
        {
            this.MediaService.Capture();
            var configurationDetector = new ConfigurationDetector();
            var config = configurationDetector.Detect();

            using (var yoloWrapper = new YoloWrapper(config))
            {
                var items = yoloWrapper.Detect(@"C:\Users\csy18\OneDrive\바탕 화면\RomanticLabel\RomanticLabel\cap.png");
                foreach (var item in items)
                {
                    var rect = new Rect(item.X, item.Y, item.Width, item.Height);
                    BoundingBoxes.Add(new BoundingBox(rect, item.Type));
                }
            }
        }
Exemple #4
0
        private void ExDrawGhostRect()
        {
            if (IsPlay && IsLeftMouseDown)
            {
                IsLeftMouseDown = false;
                GhostRect       = new Rect();

                var rect = new Rect(mouseDownLocation, new Point(PanelX, PanelY));
                BoundingBoxes.Add(new BoundingBox(rect, "New"));
            }
            else if (IsPlay && !IsLeftMouseDown)
            {
                IsLeftMouseDown   = true;
                mouseDownLocation = new Point(PanelX, PanelY);
            }
        }
Exemple #5
0
        public scenario_structure_bsp(CacheBase Cache, int Address)
        {
            cache = Cache;
            EndianReader Reader = Cache.Reader;

            Reader.SeekTo(Address);

            #region sldt ID
            //sldt's sections address will be used instead of the one in sbsp
            int sectionAddress = 0;
            foreach (var item in Cache.IndexItems)
            {
                if (item.ClassCode == "scnr")
                {
                    Reader.SeekTo(item.Offset + 20);
                    int cnt = Reader.ReadInt32();
                    int ptr = Reader.ReadInt32() - Cache.Magic;

                    int bspIndex = 0;

                    for (int i = 0; i < cnt; i++)
                    {
                        Reader.SeekTo(ptr + 108 * i + 12);
                        if (Cache.IndexItems.GetItemByID(Reader.ReadInt32()).Offset == Address)
                        {
                            bspIndex = i;
                            break;
                        }
                    }

                    Reader.SeekTo(item.Offset + 1776 + 12);
                    int sldtID      = Reader.ReadInt32();
                    int sldtAddress = Cache.IndexItems.GetItemByID(sldtID).Offset;

                    Reader.SeekTo(sldtAddress + 4);
                    cnt = Reader.ReadInt32();
                    ptr = Reader.ReadInt32() - Cache.Magic;

                    for (int i = 0; i < cnt; i++)
                    {
                        Reader.SeekTo(ptr + 436 * i + 2);

                        if (Reader.ReadInt16() != bspIndex)
                        {
                            continue;
                        }

                        Reader.SeekTo(ptr + 436 * i + 312);
                        sectionAddress = Reader.ReadInt32() - Cache.Magic;

                        Reader.SeekTo(ptr + 436 * i + 428);
                        geomRawID = Reader.ReadInt32();
                    }

                    break;
                }
            }
            #endregion

            Reader.SeekTo(Address + 60);
            XBounds = new RealBounds(Reader.ReadSingle(), Reader.ReadSingle());
            YBounds = new RealBounds(Reader.ReadSingle(), Reader.ReadSingle());
            ZBounds = new RealBounds(Reader.ReadSingle(), Reader.ReadSingle());

            #region Clusters Block
            Reader.SeekTo(Address + 180);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Clusters.Add(new Cluster(Cache, iOffset + 220 * i));
            }
            #endregion

            #region Shaders Block
            Reader.SeekTo(Address + 192);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Shaders.Add(new Halo3Beta.render_model.Shader(Cache, iOffset + 36 * i));
            }
            #endregion

            #region GeometryInstances Block
            Reader.SeekTo(Address + 432);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                GeomInstances.Add(new InstancedGeometry(Cache, iOffset + 120 * i));
            }
            #endregion

            Reader.SeekTo(Address + 580);
            RawID1 = Reader.ReadInt32();

            #region ModelSections Block
            Reader.SeekTo(Address + 740);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                ModelSections.Add(new Halo3Beta.render_model.ModelSection(Cache, sectionAddress + 76 * i));
            }
            #endregion

            #region Bounding Boxes Block
            Reader.SeekTo(Address + 752);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                BoundingBoxes.Add(new Halo3Beta.render_model.BoundingBox(Cache, iOffset + 44 * i));
            }
            #endregion

            Reader.SeekTo(Address + 860);
            RawID2 = Reader.ReadInt32();

            Reader.SeekTo(Address + 892);
            RawID3 = Reader.ReadInt32();
        }
Exemple #6
0
        public render_model(CacheBase Cache, int Address)
        {
            cache = Cache;
            EndianReader Reader = Cache.Reader;

            Reader.SeekTo(Address);

            Name  = Cache.Strings.GetItemByID(Reader.ReadInt32());
            Flags = new Bitmask(Reader.ReadInt32());

            #region Regions Block
            Reader.SeekTo(Address + 12);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Regions.Add(new Region(Cache, iOffset + 16 * i));
            }
            #endregion

            Reader.SeekTo(Address + 28);
            InstancedGeometryIndex = Reader.ReadInt32();

            #region Instanced Geometry Block
            Reader.SeekTo(Address + 32);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                GeomInstances.Add(new InstancedGeometry(Cache, iOffset + 60 * i));
            }
            #endregion

            #region Nodes Block
            Reader.SeekTo(Address + 48);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Nodes.Add(new Node(Cache, iOffset + 96 * i));
            }
            #endregion

            #region MarkerGroups Block
            Reader.SeekTo(Address + 60);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                MarkerGroups.Add(new MarkerGroup(Cache, iOffset + 16 * i));
            }
            #endregion

            #region Shaders Block
            Reader.SeekTo(Address + 72);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Shaders.Add(new Shader(Cache, iOffset + 44 * i));
            }
            #endregion

            #region ModelSections Block
            Reader.SeekTo(Address + 104);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                ModelSections.Add(new ModelSection(Cache, iOffset + 92 * i));
            }
            #endregion

            #region BoundingBox Block
            Reader.SeekTo(Address + 116);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                BoundingBoxes.Add(new BoundingBox(Cache, iOffset + 52 * i));
            }
            #endregion

            #region NodeMapGroup Block
            Reader.SeekTo(Address + 176);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                NodeIndexGroups.Add(new NodeIndexGroup(Cache, iOffset + 12 * i));
            }
            #endregion

            Reader.SeekTo(Address + 236);
            RawID = Reader.ReadInt32();
        }
Exemple #7
0
        public gbxmodel(CacheBase Cache, int Address)
        {
            cache = Cache;
            EndianReader Reader = Cache.Reader;

            Reader.SeekTo(Address);

            Name  = "gbxmodel";
            Flags = new Bitmask(Reader.ReadInt16());

            Reader.SeekTo(Address + 0x30);
            uScale = Reader.ReadSingle();
            vScale = Reader.ReadSingle();


            #region MarkerGroups Block
            Reader.SeekTo(Address + 0xAC);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                MarkerGroups.Add(new MarkerGroup(Cache, iOffset + 64 * i));
            }
            #endregion

            #region Nodes Block
            Reader.SeekTo(Address + 0xB8);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Nodes.Add(new Node(Cache, iOffset + 156 * i));
            }
            #endregion

            #region Regions Block
            Reader.SeekTo(Address + 0xC4);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Regions.Add(new Region(Cache, iOffset + 76 * i));
            }
            #endregion

            #region ModelParts Block
            Reader.SeekTo(Address + 0xD0);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                ModelSections.Add(new ModelSection(Cache, iOffset + 48 * i)
                {
                    FacesIndex = i, VertsIndex = i, NodeIndex = 255
                });
            }
            #endregion

            #region Shaders Block
            Reader.SeekTo(Address + 0xDC);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Shaders.Add(new Shader(Cache, iOffset + 32 * i));
            }
            #endregion

            #region BoundingBox Block
            BoundingBoxes.Add(new BoundingBox());
            #endregion
        }
Exemple #8
0
        public render_model(CacheBase Cache, int Address)
        {
            cache = Cache;
            EndianReader Reader = Cache.Reader;

            Reader.SeekTo(Address);

            Name = Cache.Strings.GetItemByID(Reader.ReadInt16());
            //Flags = new Bitmask(Reader.ReadInt32());

            #region BoundingBox Block
            Reader.SeekTo(Address + 20);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                BoundingBoxes.Add(new BoundingBox(Cache, iOffset + 56 * i));
            }
            #endregion

            #region Regions Block
            Reader.SeekTo(Address + 28);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Regions.Add(new Region(Cache, iOffset + 16 * i));
            }
            #endregion

            #region ModelParts Block
            Reader.SeekTo(Address + 36);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                ModelSections.Add(new ModelSection(Cache, iOffset + 92 * i)
                {
                    FacesIndex = i, VertsIndex = i, NodeIndex = 255
                });
            }
            Reader.SeekTo(Address + 72);
            #endregion

            #region Nodes Block
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Nodes.Add(new Node(Cache, iOffset + 96 * i));
            }
            #endregion

            #region MarkerGroups Block
            Reader.SeekTo(Address + 88);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                MarkerGroups.Add(new MarkerGroup(Cache, iOffset + 12 * i));
            }
            #endregion

            #region Shaders Block
            Reader.SeekTo(Address + 96);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Shaders.Add(new Shader(Cache, iOffset + 32 * i));
            }
            #endregion
        }
        public scenario_structure_bsp(CacheBase Cache, int Address)
        {
            cache = Cache;
            EndianReader Reader = Cache.Reader;

            Reader.SeekTo(Address);

            #region sldt/lbsp ID
            //lbsp's sections address will be used instead of the one in sbsp
            int sectionAddress = 0;
            int sectionCount   = 0;
            foreach (var item in Cache.IndexItems)
            {
                if (item.ClassCode == "scnr")
                {
                    Reader.SeekTo(item.Offset + 76);
                    int cnt = Reader.ReadInt32();
                    int ptr = Reader.ReadInt32() - Cache.Magic;

                    int bspIndex = 0;

                    for (int i = 0; i < cnt; i++)
                    {
                        Reader.SeekTo(ptr + 172 * i + 12);
                        if (Cache.IndexItems.GetItemByID(Reader.ReadInt32()).Offset == Address)
                        {
                            bspIndex = i;
                            break;
                        }
                    }

                    Reader.SeekTo(item.Offset + 1844 + 12);
                    int sldtID      = Reader.ReadInt32();
                    int sldtAddress = Cache.IndexItems.GetItemByID(sldtID).Offset;

                    Reader.SeekTo(sldtAddress + 4);
                    cnt = Reader.ReadInt32();
                    ptr = Reader.ReadInt32() - Cache.Magic;

                    Reader.SeekTo(ptr + 32 * bspIndex + 12);
                    int lbspID      = Reader.ReadInt32();
                    int lbspAddress = Cache.IndexItems.GetItemByID(lbspID).Offset;

                    Reader.SeekTo(lbspAddress + 124);
                    sectionCount   = Reader.ReadInt32();
                    sectionAddress = Reader.ReadInt32() - Cache.Magic;

                    Reader.SeekTo(lbspAddress + 268);
                    geomRawID = Reader.ReadInt32();
                    break;
                }
            }
            #endregion

            Reader.SeekTo(Address + 236);
            XBounds = new RealBounds(Reader.ReadSingle(), Reader.ReadSingle());
            YBounds = new RealBounds(Reader.ReadSingle(), Reader.ReadSingle());
            ZBounds = new RealBounds(Reader.ReadSingle(), Reader.ReadSingle());

            #region Clusters Block
            Reader.SeekTo(Address + 308);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Clusters.Add(new Cluster(Cache, iOffset + 140 * i));
            }
            #endregion

            #region Shaders Block
            Reader.SeekTo(Address + 320);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Shaders.Add(new ReachRetail.render_model.Shader(Cache, iOffset + 44 * i));
            }
            #endregion

            #region GeometryInstances Block
            Reader.SeekTo(Address + 608);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                GeomInstances.Add(new InstancedGeometry(Cache, iOffset + 4 * i));
            }

            #region Load Fixup Data
            Reader.SeekTo(Address + 1298);
            int id    = Reader.ReadUInt16();
            var entry = Cache.zone.RawEntries[id];
            var er    = new EndianReader(new MemoryStream(Cache.zone.FixupData), EndianFormat.BigEndian);
            int addr  = entry.Fixups[entry.Fixups.Count - 10].Offset;

            for (int i = 0; i < GeomInstances.Count; i++)
            {
                er.SeekTo(entry.FixupOffset + addr + 156 * i);
                var geom = GeomInstances[i];

                geom.TransformScale = er.ReadSingle();

                geom.TransformMatrix.m11 = er.ReadSingle();
                geom.TransformMatrix.m12 = er.ReadSingle();
                geom.TransformMatrix.m13 = er.ReadSingle();

                geom.TransformMatrix.m21 = er.ReadSingle();
                geom.TransformMatrix.m22 = er.ReadSingle();
                geom.TransformMatrix.m23 = er.ReadSingle();

                geom.TransformMatrix.m31 = er.ReadSingle();
                geom.TransformMatrix.m32 = er.ReadSingle();
                geom.TransformMatrix.m33 = er.ReadSingle();

                geom.TransformMatrix.m41 = er.ReadSingle();
                geom.TransformMatrix.m42 = er.ReadSingle();
                geom.TransformMatrix.m43 = er.ReadSingle();

                er.ReadUInt16();
                er.ReadUInt16();
                er.ReadUInt16();
                geom.SectionIndex = er.ReadUInt16();
            }
            er.Close();
            er.Dispose();
            #endregion
            #endregion

            Reader.SeekTo(Address + 796);
            RawID1 = Reader.ReadInt32();

            Reader.SeekTo(Address + 976);
            RawID2 = Reader.ReadInt32();

            #region ModelParts Block
            Reader.SeekTo(Address + 1100);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            if (sectionAddress == -Cache.Magic)
            {
                sectionAddress = iOffset;                                 //null address in lbsp
            }
            for (int i = 0; i < iCount; i++)
            {
                ModelSections.Add(new ReachRetail.render_model.ModelSection(Cache, sectionAddress + 92 * i));
            }
            #endregion

            #region Bounding Boxes Block
            Reader.SeekTo(Address + 1112);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                BoundingBoxes.Add(new ReachRetail.render_model.BoundingBox(Cache, iOffset + 52 * i));
            }
            #endregion

            Reader.SeekTo(Address + 1244);
            RawID3 = Reader.ReadInt32();
        }
Exemple #10
0
        /// <summary>
        /// Create a new geometry given filename
        /// </summary>
        /// <param name="fileName"> filepath to the 3D model file </param>
        public Geometry(string fileName, bool enableRigging = false)
        {
            RiggingEnabled = enableRigging;
            sourceFileName = fileName;

            //Create new importer.
            importer = new AssimpContext();

            //import the file
            scene = importer.ImportFile(fileName,
                                        PostProcessSteps.CalculateTangentSpace | PostProcessSteps.Triangulate |
                                        PostProcessSteps.JoinIdenticalVertices | PostProcessSteps.SortByPrimitiveType |
                                        PostProcessSteps.GenerateUVCoords | PostProcessSteps.FlipUVs |
                                        PostProcessSteps.LimitBoneWeights | PostProcessSteps.ValidateDataStructure);

            //make sure scene not null
            if (scene == null)
            {
                throw new FileNotFoundException();
            }

            //loop through sizes and count them.
            allMeshes = new List <ClientMesh>(scene.MeshCount);

            //loop through and store sizes
            for (int idx = 0; idx < scene.MeshCount; idx++)
            {
                ClientMesh mesh = new ClientMesh();
                allMeshes.Add(mesh);

                mesh.CountVertices = scene.Meshes[idx].VertexCount;

                mesh.vertSize = scene.Meshes[idx].VertexCount * Vector3.SizeInBytes;
                mesh.normSize = scene.Meshes[idx].Normals.Count * Vector3.SizeInBytes;
                mesh.faceSize = scene.Meshes[idx].FaceCount * scene.Meshes[idx].Faces[0].IndexCount * sizeof(int);
                if (scene.Meshes[idx].HasTextureCoords(0))
                {
                    mesh.texSize = scene.Meshes[idx].TextureCoordinateChannels[0].Count * Vector3.SizeInBytes;
                }
            }

            diffuseTextureSRV = new Dictionary <string, ShaderResourceView>();

            // do all the processing that rigging is required to have
            if (enableRigging)
            {
                _allBones        = new List <ClientBone>();
                _allBoneMappings = new Dictionary <string, int>();
                _allBoneLookup   = new Dictionary <string, ClientBone>();

                // set the animation related lookup tables
                AnimationIndices = new Dictionary <string, int>();
                _animationNodes  = new List <Dictionary <string, ClientAnimationNode> >(scene.AnimationCount);
                for (int i = 0; i < scene.AnimationCount; i++)
                {
                    AnimationIndices[scene.Animations[i].Name] = i;
                    _animationNodes.Add(new Dictionary <string, ClientAnimationNode>());

                    for (int j = 0; j < scene.Animations[i].NodeAnimationChannelCount; j++)
                    {
                        NodeAnimationChannel ch     = scene.Animations[i].NodeAnimationChannels[j];
                        ClientAnimationNode  myNode = new ClientAnimationNode(ch.NodeName);

                        _animationNodes[i][ch.NodeName] = myNode;
                        myNode.Translations             = new List <Vector3>();
                        myNode.TranslationTime          = new List <double>();
                        myNode.Rotations    = new List <Quaternion>();
                        myNode.RotationTime = new List <double>();
                        myNode.Scalings     = new List <Vector3>();
                        myNode.ScalingTime  = new List <double>();

                        // copy over all the necessary information in the animation channels
                        for (int k = 0; k < ch.PositionKeyCount; k++)
                        {
                            myNode.Translations.Add(ch.PositionKeys[k].Value.ToVector3());
                            myNode.TranslationTime.Add(ch.PositionKeys[k].Time);
                        }

                        for (int k = 0; k < ch.RotationKeyCount; k++)
                        {
                            myNode.Rotations.Add(ch.RotationKeys[k].Value.ToQuaternion());
                            myNode.RotationTime.Add(ch.RotationKeys[k].Time);
                        }

                        for (int k = 0; k < ch.ScalingKeyCount; k++)
                        {
                            myNode.Scalings.Add(ch.ScalingKeys[k].Value.ToVector3());
                            myNode.ScalingTime.Add(ch.ScalingKeys[k].Time);
                        }
                    }
                }

                // create and store the big scene tree
                _rootBone = CreateBoneTree(scene.RootNode, null);

                // set each bone offset
                foreach (var sceneMesh in scene.Meshes)
                {
                    foreach (var rawBone in sceneMesh.Bones)
                    {
                        ClientBone found;
                        if (!_allBoneLookup.TryGetValue(rawBone.Name, out found))
                        {
                            Console.WriteLine("Cannot find bone: " + rawBone.Name);
                            continue;
                        }

                        found.BoneOffset = rawBone.OffsetMatrix.ToMatrix();
                        _allBones.Add(found);
                        _allBoneMappings[found.BoneName] = _allBones.IndexOf(found);
                    }
                }

                // for bones not inside the meshes...? jasdkl;fja;lskdjkfl
                foreach (var boneName in _allBoneLookup.Keys.Where(b =>
                                                                   _allBones.All(b1 => b1.BoneName != b) && b.StartsWith("Bone")))
                {
                    _allBoneLookup[boneName].BoneOffset = _allBoneLookup[boneName].Parent.BoneOffset.Clone();
                    _allBones.Add(_allBoneLookup[boneName]);
                    _allBoneMappings[boneName] = _allBones.IndexOf(_allBoneLookup[boneName]);
                }

                // load the bone weights
                for (int idx = 0; idx < scene.MeshCount; idx++)
                {
                    LoadBoneWeights(scene.Meshes[idx], allMeshes[idx]);
                }

                //_boneTransformStream = new DataStream(MAX_BONES_PER_GEO * sizeof(float) * 16, true, true);
                _boneTransformList = new List <Matrix>(MAX_BONES_PER_GEO);
                for (int i = 0; i < MAX_BONES_PER_GEO; i++)
                {
                    _boneTransformList.Add(Matrix.Identity);
                }
            }

            // main loading loop; copy cover the scene content into the datastreams and then to the buffers
            for (int idx = 0; idx < scene.MeshCount; idx++)
            {
                ClientMesh mesh = allMeshes[idx];

                //create new datastreams.
                mesh.Vertices = new DataStream(mesh.vertSize, true, true);
                mesh.Normals  = new DataStream(mesh.normSize, true, true);
                mesh.Faces    = new DataStream(mesh.faceSize, true, true);

                // create a new material
                mesh.Materials = new ClientMaterial();

                //min and max bounds
                var min = new Vector3(float.MaxValue);
                var max = new Vector3(float.MinValue);
                // copy the buffers
                scene.Meshes[idx].Vertices.ForEach(vertex =>
                {
                    mesh.Vertices.Write(vertex.ToVector3());

                    //keep track of min and max for obj boundaries.
                    min = Vector3.Minimize(min, vertex.ToVector3());
                    max = Vector3.Maximize(max, vertex.ToVector3());
                });
                BoundingBoxes.Add(new BoundingBox(min, max));


                scene.Meshes[idx].Normals.ForEach(normal =>
                {
                    mesh.Normals.Write(normal.ToVector3());
                });
                scene.Meshes[idx].Faces.ForEach(face =>
                {
                    mesh.Faces.WriteRange(face.Indices.ToArray());
                });

                // check if the mesh has texture coordinates
                if (scene.Meshes[idx].HasTextureCoords(0))
                {
                    mesh.TexCoords = new DataStream(mesh.texSize, true, true);
                    scene.Meshes[idx].TextureCoordinateChannels[0].ForEach(texture => {
                        mesh.TexCoords.Write(texture);
                    });

                    mesh.TexCoords.Position = 0;
                }

                // Parse material properties
                ApplyMaterial(scene.Materials[scene.Meshes[idx].MaterialIndex], mesh.Materials);

                // reset datastream positions
                mesh.Vertices.Position = 0;
                mesh.Normals.Position  = 0;
                mesh.Faces.Position    = 0;

                //create vertex vbo and faces ebo.
                mesh.VBOPositions = new Buffer(GraphicsRenderer.Device, mesh.Vertices, mesh.vertSize, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
                mesh.VBONormals   = new Buffer(GraphicsRenderer.Device, mesh.Normals, mesh.normSize, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
                if (scene.Meshes[idx].HasTextureCoords(0))
                {
                    mesh.VBOTexCoords = new Buffer(GraphicsRenderer.Device, mesh.TexCoords, mesh.texSize, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
                }

                // buffer creation flags
                var ibd = new BufferDescription(
                    mesh.faceSize,
                    ResourceUsage.Immutable,
                    BindFlags.IndexBuffer,
                    CpuAccessFlags.None,
                    ResourceOptionFlags.None,
                    0);

                mesh.EBO = new Buffer(GraphicsRenderer.Device, mesh.Faces, ibd);
            }

            _inverseGlobalTransform = Matrix.Invert(scene.RootNode.Transform.ToMatrix());
        }
        public scenario_structure_bsp(CacheBase Cache, int Address)
        {
            cache = Cache;
            EndianReader Reader = Cache.Reader;

            Reader.SeekTo(Address);

            #region sldt/lbsp ID
            //lbsp's sections address will be used instead of the one in sbsp
            int sectCount = 0, sectionAddress = 0, bbCount = 0, bbAddr = 0;
            foreach (var item in Cache.IndexItems)
            {
                if (item.ClassCode == "scnr")
                {
                    Reader.SeekTo(item.Offset + 160);
                    int cnt = Reader.ReadInt32();
                    int ptr = Reader.ReadInt32() - Cache.Magic;

                    int bspIndex = 0;

                    for (int i = 0; i < cnt; i++)
                    {
                        Reader.SeekTo(ptr + 336 * i + 12);
                        if (Cache.IndexItems.GetItemByID(Reader.ReadInt32()).Offset == Address)
                        {
                            bspIndex = i;
                            break;
                        }
                    }

                    Reader.SeekTo(item.Offset + 1896 + 12);
                    int sldtID      = Reader.ReadInt32();
                    int sldtAddress = Cache.IndexItems.GetItemByID(sldtID).Offset;

                    Reader.SeekTo(sldtAddress + 4);
                    cnt = Reader.ReadInt32();
                    ptr = Reader.ReadInt32() - Cache.Magic;

                    Reader.SeekTo(ptr + 32 * bspIndex + 12);
                    int lbspID      = Reader.ReadInt32();
                    int lbspAddress = Cache.IndexItems.GetItemByID(lbspID).Offset;

                    Reader.SeekTo(lbspAddress + 320); //320, 512, 692
                    sectCount      = Reader.ReadInt32();
                    sectionAddress = Reader.ReadInt32() - Cache.Magic;

                    Reader.SeekTo(lbspAddress + 344); //344, 536, 716
                    bbCount = Reader.ReadInt32();
                    bbAddr  = Reader.ReadInt32() - Cache.Magic;

                    Reader.SeekTo(lbspAddress + 464); //464, 656, 836
                    geomRawID = Reader.ReadInt32();
                    break;
                }
            }
            #endregion

            Reader.SeekTo(Address + 268);
            XBounds = new Range <float>(Reader.ReadSingle(), Reader.ReadSingle());
            YBounds = new Range <float>(Reader.ReadSingle(), Reader.ReadSingle());
            ZBounds = new Range <float>(Reader.ReadSingle(), Reader.ReadSingle());

            #region Clusters Block
            Reader.SeekTo(Address + 340);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < 1; i++)
            {
                Clusters.Add(new Cluster(Cache, iOffset + 140 * i));
            }
            #endregion

            #region Shaders Block
            Reader.SeekTo(Address + 352);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Shaders.Add(new Halo4Retail.render_model.Shader(Cache, iOffset + 44 * i));
            }
            #endregion

            #region GeometryInstances Block
            Reader.SeekTo(Address + 640);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                GeomInstances.Add(new InstancedGeometry(Cache, iOffset + 4 * i));
            }

            #region Load Fixup Data
            Reader.SeekTo(Address + 1364);
            int id    = Reader.ReadInt32();
            var entry = Cache.zone.RawEntries[id & 0xFFFF];
            var er    = new EndianReader(new MemoryStream(Cache.GetRawFromID(id)), EndianFormat.Big);
            int addr  = entry.Fixups[entry.Fixups.Count - 10].Offset;

            for (int i = 0; i < GeomInstances.Count; i++)
            {
                er.SeekTo(addr + 148 * i);
                var geom = GeomInstances[i];

                geom.TransformScale = er.ReadSingle();

                geom.TransformMatrix = Matrix4x3.Read(er);

                er.ReadUInt16();
                er.ReadUInt16();
                er.ReadInt32();
                er.ReadUInt16();
                geom.SectionIndex = er.ReadUInt16();
            }
            er.Close();
            er.Dispose();
            #endregion
            #endregion

            Reader.SeekTo(Address + 844);
            RawID1 = Reader.ReadInt32();

            Reader.SeekTo(Address + 1048);
            RawID2 = Reader.ReadInt32();

            #region ModelSections Block
            Reader.SeekTo(Address + 1144);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            if (sectionAddress == -Cache.Magic)
            {
                sectionAddress = iOffset;                                 //null address in lbsp
            }
            for (int i = 0; i < sectCount; i++)
            {
                ModelSections.Add(new Halo4Retail.render_model.ModelSection(Cache, sectionAddress + 112 * i));
            }
            #endregion

            #region Bounding Boxes Block
            Reader.SeekTo(Address + 1168);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < bbCount; i++)
            {
                BoundingBoxes.Add(new Halo4Retail.render_model.BoundingBox(Cache, bbAddr + 52 * i));
            }
            #endregion

            Reader.SeekTo(Address + 1288);
            RawID3 = Reader.ReadInt32();
        }
        public scenario_structure_bsp(CacheBase Cache, int Address)
        {
            cache = Cache;
            EndianReader Reader = Cache.Reader;

            Reader.SeekTo(Address);

            #region sldt/lbsp ID
            //lbsp's sections address will be used instead of the one in sbsp
            int sectionAddress = 0;
            foreach (var item in Cache.IndexItems)
            {
                if (item.ClassCode == "scnr")
                {
                    Reader.SeekTo(item.Offset + 68);
                    int cnt = Reader.ReadInt32();
                    int ptr = Reader.ReadInt32() - Cache.Magic;

                    int bspIndex = 0;

                    for (int i = 0; i < cnt; i++)
                    {
                        Reader.SeekTo(ptr + 168 * i + 12);
                        if (Cache.IndexItems.GetItemByID(Reader.ReadInt32()).Offset == Address)
                        {
                            bspIndex = i;
                            break;
                        }
                    }

                    Reader.SeekTo(item.Offset + 1828 + 12);
                    int sldtID      = Reader.ReadInt32();
                    var sldt        = Cache.IndexItems.GetItemByID(sldtID);
                    int sldtAddress = Cache.IndexItems.GetItemByID(sldtID).Offset;

                    Reader.SeekTo(sldtAddress + 4);
                    cnt = Reader.ReadInt32();
                    ptr = Reader.ReadInt32() - Cache.Magic;

                    Reader.SeekTo(ptr + 32 * bspIndex + 12);
                    int lbspID      = Reader.ReadInt32();
                    var lbsp        = Cache.IndexItems.GetItemByID(lbspID);
                    int lbspAddress = Cache.IndexItems.GetItemByID(lbspID).Offset;

                    Reader.SeekTo(lbspAddress + 116);
                    sectionAddress = Reader.ReadInt32() - Cache.Magic;

                    Reader.SeekTo(lbspAddress + 244);
                    geomRawID = Reader.ReadInt32();
                    break;
                }
            }
            #endregion

            Reader.SeekTo(Address + 236);
            XBounds = new Range <float>(Reader.ReadSingle(), Reader.ReadSingle());
            YBounds = new Range <float>(Reader.ReadSingle(), Reader.ReadSingle());
            ZBounds = new Range <float>(Reader.ReadSingle(), Reader.ReadSingle());

            #region Clusters Block
            Reader.SeekTo(Address + 308);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Clusters.Add(new Cluster(Cache, iOffset + 288 * i));
            }
            #endregion

            #region Shaders Block
            Reader.SeekTo(Address + 320);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Shaders.Add(new ReachBeta.render_model.Shader(Cache, iOffset + 44 * i));
            }
            #endregion

            #region GeometryInstances Block
            Reader.SeekTo(Address + 620);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                GeomInstances.Add(new InstancedGeometry(Cache, iOffset + 168 * i));
            }
            #endregion

            Reader.SeekTo(Address + 796);
            RawID1 = Reader.ReadInt32();

            Reader.SeekTo(Address + 976);
            RawID2 = Reader.ReadInt32();

            #region ModelParts Block
            Reader.SeekTo(Address + 1112);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                ModelSections.Add(new ReachBeta.render_model.ModelSection(Cache, sectionAddress + 92 * i));
            }
            #endregion

            #region Bounding Boxes Block
            Reader.SeekTo(Address + 1124);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                BoundingBoxes.Add(new ReachBeta.render_model.BoundingBox(Cache, iOffset + 52 * i));
            }
            #endregion

            Reader.SeekTo(Address + 1244);
            RawID3 = Reader.ReadInt32();
        }