public void CreateChildren(GravityModelMesh[] _meshes)
        {
            List <GravityModelMesh> childs = new List <GravityModelMesh>();

            foreach (GravityModelMesh m in _meshes)
            {
                if (string.Compare(m.ParentName, _name, true) == 0)
                {
                    childs.Add(m);
                }
            }

            foreach (GravityModelMesh m in _meshes)
            {
                if (string.Compare(m.Name, _parentName, true) == 0)
                {
                    _parent = m;
                    break;
                }
            }

            _children = childs.ToArray();
        }
        public void CreateChildren(GravityModelMesh[] _meshes)
        {
            List<GravityModelMesh> childs = new List<GravityModelMesh>();

            foreach (GravityModelMesh m in _meshes)
            {
                if (string.Compare(m.ParentName, _name, true) == 0)
                    childs.Add(m);
            }

            foreach (GravityModelMesh m in _meshes)
            {
                if (string.Compare(m.Name, _parentName, true) == 0)
                {
                    _parent = m;
                    break;
                }
            }

            _children = childs.ToArray();
        }
예제 #3
0
        public bool Load(Stream stream)
        {
            BinaryReader br = new BinaryReader(stream);

            string header = ((char)br.ReadByte()).ToString() + ((char)br.ReadByte()) + ((char)br.ReadByte()) + ((char)br.ReadByte());

            if (header != "GRSM")
                return false;

            majorVersion = br.ReadByte();
            minorVersion = br.ReadByte();

            _animationLength = br.ReadInt32();
            _shade = (ShadeType)br.ReadInt32();

            if (majorVersion > 1 || (majorVersion == 1 && minorVersion >= 4))
                _alpha = br.ReadByte();
            else
                _alpha = 255;

            br.ReadBytes(16);

            _textures = new Texture2D[br.ReadInt32()];
            for (int i = 0; i < _textures.Length; i++)
            {
                _textures[i] = SharedInformation.ContentManager.Load<Texture2D>(@"data\texture\" + br.ReadCString(40));
            }

            _mainNodeName = br.ReadCString(40);

            _meshes = new GravityModelMesh[br.ReadInt32()];
            for (int i = 0; i < _meshes.Length; i++)
            {
                GravityModelMesh mesh = new GravityModelMesh();

                mesh.Load(this, br, majorVersion, minorVersion);

                _meshes[i] = mesh;
            }

            _rootMesh = FindMesh(_mainNodeName);
            _rootMesh.CreateChildren(_meshes);

            bbmin = new Vector3(999999, 999999, 999999);
            bbmax = new Vector3(-999999, -999999, -999999);

            _rootMesh.SetBoundingBox(ref bbmin, ref bbmax);
            bbrange = (bbmin + bbmax) / 2.0F;

            Matrix mat = Matrix.CreateScale(1, -1, 1);
            realbbmin = new Vector3(999999, 999999, 999999);
            realbbmax = new Vector3(-999999, -999999, -999999);
            _rootMesh.SetBoundingBox2(mat, ref realbbmin, ref realbbmax);
            realbbrange = (realbbmax + realbbmin) / 2.0F;
            //maxrange = Math.Max(Math.Max(Math.Max(realbbmax.X, -realbbmin.X), Math.Max(realbbmax.Y, -realbbmin.Y)), Math.Max(realbbmax.Z, -realbbmin.Z))));

            return true;
        }
예제 #4
0
        public bool Load(Stream stream)
        {
            BinaryReader br = new BinaryReader(stream);

            string header = ((char)br.ReadByte()).ToString() + ((char)br.ReadByte()) + ((char)br.ReadByte()) + ((char)br.ReadByte());

            if (header != "GRSM")
            {
                return(false);
            }

            majorVersion = br.ReadByte();
            minorVersion = br.ReadByte();

            _animationLength = br.ReadInt32();
            _shade           = (ShadeType)br.ReadInt32();

            if (majorVersion > 1 || (majorVersion == 1 && minorVersion >= 4))
            {
                _alpha = br.ReadByte();
            }
            else
            {
                _alpha = 255;
            }

            br.ReadBytes(16);

            _textures = new Texture2D[br.ReadInt32()];
            for (int i = 0; i < _textures.Length; i++)
            {
                _textures[i] = SharedInformation.ContentManager.Load <Texture2D>(@"data\texture\" + br.ReadCString(40));
            }

            _mainNodeName = br.ReadCString(40);

            _meshes = new GravityModelMesh[br.ReadInt32()];
            for (int i = 0; i < _meshes.Length; i++)
            {
                GravityModelMesh mesh = new GravityModelMesh();

                mesh.Load(this, br, majorVersion, minorVersion);

                _meshes[i] = mesh;
            }

            _rootMesh = FindMesh(_mainNodeName);
            _rootMesh.CreateChildren(_meshes);

            bbmin = new Vector3(999999, 999999, 999999);
            bbmax = new Vector3(-999999, -999999, -999999);

            _rootMesh.SetBoundingBox(ref bbmin, ref bbmax);
            bbrange = (bbmin + bbmax) / 2.0F;

            Matrix mat = Matrix.CreateScale(1, -1, 1);

            realbbmin = new Vector3(999999, 999999, 999999);
            realbbmax = new Vector3(-999999, -999999, -999999);
            _rootMesh.SetBoundingBox2(mat, ref realbbmin, ref realbbmax);
            realbbrange = (realbbmax + realbbmin) / 2.0F;
            //maxrange = Math.Max(Math.Max(Math.Max(realbbmax.X, -realbbmin.X), Math.Max(realbbmax.Y, -realbbmin.Y)), Math.Max(realbbmax.Z, -realbbmin.Z))));

            return(true);
        }