예제 #1
0
        public bool ParseFromFile(string fname)
        {
            BlenderPhmoReader reader = new BlenderPhmoReader(fname);

            fileStruct = reader.ReadFile();
            if (fileStruct == null)
            {
                Console.WriteLine("Could not parse file.");
                return(false);
            }

            //create a rigidbody for the phmo
            var rigidbody = new PhysicsModel.RigidBody
            {
                Mass         = 100f,                                            //probably not important
                CenterOfMass = new RealVector3d(0.0f, 0.0f, 0.25f),             //probably not important
                ShapeIndex   = 0,                                               //important
                MotionType   = PhysicsModel.RigidBody.MotionTypeValue.Keyframed // keyframed movement for now.
            };

            var shapedefs = fileStruct.AsArray;

            if (shapedefs.Count < 1)
            {
                Console.WriteLine("No shapes!");
                return(false);
            }
            else if (shapedefs.Count < 2)
            {
                //optimise the phmo by avoiding the use of the list-shape
                // as a level of indirection for multiple shapes.
                //Also for ease of shape encoding, AddShape returns the
                //shape-type added. 'Unused0' is used to represent failure.
                if (AddShape(_phmo, shapedefs[0]) == HavokShapeType.TriangleMesh)
                {
                    return(false);
                }

                rigidbody.ShapeType = HavokShapeType.Polyhedron;

                //this field does not have any influence
                //rigidbody.BoundingSphereRadius = 0.5f;
            }
            else
            {
                MemoryStream moppCodeBlockStream = BlenderPhmoMoppUtil.GenerateForBlenderPhmoJsonFile(fname);

                rigidbody.ShapeType  = HavokShapeType.Mopp;
                rigidbody.ShapeIndex = 0;

                //phmo needs to use shapelist and listelements reflexives
                _phmo.Lists      = new List <PhysicsModel.List>();
                _phmo.ListShapes = new List <PhysicsModel.ListShape>();
                _phmo.Mopps      = new List <PhysicsModel.Mopp>();

                var moppTagblock = new PhysicsModel.Mopp
                {
                    Count      = 128,
                    Unknown    = 27,
                    ShapeType  = HavokShapeType.List,
                    ShapeIndex = 0
                };

                _phmo.MoppCodes = moppCodeBlockStream.ToArray();


                _phmo.Mopps.Add(moppTagblock);

                //_phmo.MoppCodes = new
                PhysicsModel.List shapeList = new PhysicsModel.List();

                Console.WriteLine("Loading multiple shapes");
                int amountAdded = 0;
                foreach (JSONNode listelem in fileStruct.AsArray)
                {
                    HavokShapeType typeAdded = AddShape(_phmo, listelem);
                    if (typeAdded == HavokShapeType.TriangleMesh)
                    {
                        Console.WriteLine("Failed loading shape.");
                        return(false);
                    }

                    PhysicsModel.ListShape shapeElem = new PhysicsModel.ListShape
                    {
                        ShapeType = typeAdded,
                        //assumes the shape added should be at the end of the respected list.
                        ShapeIndex = (short)(GetNumberOfShapes(_phmo, typeAdded) - 1)
                    };
                    _phmo.ListShapes.Add(shapeElem);
                    amountAdded++;
                }
                shapeList.Count               = 128;
                shapeList.ChildShapesSize     = amountAdded;
                shapeList.ChildShapesCapacity = (uint)(amountAdded + 0x80000000);
                _phmo.Lists.Add(shapeList);
                Console.WriteLine("Added {0} shapes.", amountAdded);
            }

            _phmo.RigidBodies.Add(rigidbody);

            return(true);
        }
예제 #2
0
        public bool ParseFromFile(string fname)
        {
            BlenderPhmoReader reader = new BlenderPhmoReader(fname);

            fileStruct = reader.ReadFile();
            if (fileStruct == null)
            {
                Console.WriteLine("Could not parse file.");
                return(false);
            }

            //create a rigidbody for the phmo
            var rigidbody = new PhysicsModel.RigidBody();

            rigidbody.Mass          = 100f;                      //probably not important
            rigidbody.CenterOfMassK = 0.25f;                     //probably not important
            rigidbody.ShapeIndex    = 0;                         //important
            rigidbody.MotionType    = MotionTypeValue.Keyframed; // keyframed movement for now.

            var shapedefs = fileStruct.AsArray;

            if (shapedefs.Count < 1)
            {
                Console.WriteLine("No shapes!");
                return(false);
            }
            else if (shapedefs.Count < 2)
            {
                //optimise the phmo by avoiding the use of the list-shape
                // as a level of indirection for multiple shapes.
                //Also for ease of shape encoding, AddShape returns the
                //shape-type added. 'Unused0' is used to represent failure.
                if (AddShape(_phmo, shapedefs[0]) == ShapeTypes.Unused0)
                {
                    return(false);
                }


                rigidbody.ShapeType = ShapeTypes.Polyhedron;


                //this field does not have any influence
                //rigidbody.BoundingSphereRadius = 0.5f;
            }
            else
            {
                rigidbody.ShapeType = ShapeTypes.List;
                //phmo needs to use shapelist and listelements reflexives
                _phmo.Lists      = new List <PhysicsModel.List>();
                _phmo.ListShapes = new List <PhysicsModel.ListShape>();
                PhysicsModel.List shapeList = new PhysicsModel.List();

                Console.WriteLine("Loading multiple shapes");
                int amountAdded = 0;
                foreach (JSONNode listelem in fileStruct.AsArray)
                {
                    ShapeTypes typeAdded = AddShape(_phmo, listelem);
                    if (typeAdded == ShapeTypes.Unused0)
                    {
                        Console.WriteLine("Failed loading shape.");
                        return(false);
                    }

                    PhysicsModel.ListShape shapeElem = new PhysicsModel.ListShape();
                    shapeElem.ShapeType = (PhysicsModel.ListShape.ShapeTypeValue)typeAdded;
                    //assumes the shape added should be at the end of the respected list.
                    shapeElem.ShapeIndex = (short)(getNumberOfShapes(_phmo, typeAdded) - 1);
                    _phmo.ListShapes.Add(shapeElem);
                    amountAdded++;
                }
                shapeList.Count               = 128;
                shapeList.ChildShapesSize     = amountAdded;
                shapeList.ChildShapesCapacity = (uint)(amountAdded + 0x80000000);
                _phmo.Lists.Add(shapeList);
                Console.WriteLine("Added {0} shapes.", amountAdded);
            }


            _phmo.RigidBodies.Add(rigidbody);

            return(true);
        }