示例#1
0
        /// <summary>
        /// Gets the number of shapes in the list for the particular shape
        /// </summary>
        /// <param name="phmo">the serialized phmo from which to get the counts</param>
        /// <param name="type">the shape for which to get the count</param>
        /// <returns></returns>
        private int getNumberOfShapes(PhysicsModel phmo, ShapeTypes type)
        {
            switch (type)
            {
            case ShapeTypes.Box:
                return(phmo.Boxes != null ? phmo.Boxes.Count : 0);

            case ShapeTypes.List:
                return(phmo.Lists != null ? phmo.Lists.Count : 0);

            case ShapeTypes.Mopp:
                return(phmo.Mopps != null ? phmo.Mopps.Count : 0);

            case ShapeTypes.Pill:
                return(phmo.Pills != null ? phmo.Pills.Count : 0);

            case ShapeTypes.Polyhedron:
                return(phmo.Polyhedra != null ? phmo.Polyhedra.Count : 0);

            case ShapeTypes.Sphere:
                return(phmo.Spheres != null ? phmo.Spheres.Count : 0);

            default:
                return(0);
            }
        }
        /// <summary>
        /// Gets the number of shapes in the list for the particular shape
        /// </summary>
        /// <param name="phmo">the serialized phmo from which to get the counts</param>
        /// <param name="type">the shape for which to get the count</param>
        /// <returns></returns>
        private int getNumberOfShapes(PhysicsModel phmo, ShapeTypes type)
        {

            switch (type)
            {

                case ShapeTypes.Box:
                    return phmo.Boxes != null ? phmo.Boxes.Count : 0;
                case ShapeTypes.List:
                    return phmo.Lists != null ? phmo.Lists.Count : 0;
                case ShapeTypes.Mopp:
                    return phmo.Mopps != null ? phmo.Mopps.Count : 0;
                case ShapeTypes.Pill:
                    return phmo.Pills != null ? phmo.Pills.Count : 0;
                case ShapeTypes.Polyhedron:
                    return phmo.Polyhedra != null ? phmo.Polyhedra.Count : 0;
                case ShapeTypes.Sphere:
                    return phmo.Spheres != null ? phmo.Spheres.Count : 0;

                default:
                    return 0;
            }
        }
示例#3
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);
        }