HumanoidEntity CreateHumanoid(string name, Vector3 initialPosition) { Dictionary <string, VisualEntity> humanoidShapes = new Dictionary <string, VisualEntity>(); string prefix = name + "_"; foreach (HumanoidShapeDescriptor desc in ShapeDescriptors) { Shape newShape = null; newShape = new BoxShape(new BoxShapeProperties( desc.Name + " Shape", (float)desc.mass, new Pose(), new Vector3((float)desc.xSize, (float)desc.ySize, (float)desc.zSize))); // newShape = new ConvexMeshShape(new ConvexMeshShapeProperties(desc.Name + "Shape", desc.mesh)); SingleShapeEntity shapeEntity = null; /* * SimplifiedConvexMeshEnvironmentEntity shapeEntity = null; * if (desc.Name == _parentName) * { * shapeEntity = new HumanoidEntity(newShape, new Vector3( * (float)desc.xPosition + initialPosition.X, * (float)desc.yPosition + initialPosition.Y, * (float)desc.zPosition + initialPosition.Z),desc.mesh); * } * else * { * shapeEntity = new SegmentEntity(newShape, new Vector3( * (float)desc.xPosition + initialPosition.X, * (float)desc.yPosition + initialPosition.Y, * (float)desc.zPosition + initialPosition.Z),desc.mesh); * } */ if (desc.Name == _parentName) { shapeEntity = new HumanoidEntity(newShape, new Vector3( (float)desc.xPosition + initialPosition.X, (float)desc.yPosition + initialPosition.Y, (float)desc.zPosition + initialPosition.Z)); } else { shapeEntity = new SegmentEntity(newShape, new Vector3( (float)desc.xPosition + initialPosition.X, (float)desc.yPosition + initialPosition.Y, (float)desc.zPosition + initialPosition.Z)); } shapeEntity.State.Name = prefix + desc.Name; shapeEntity.State.Pose.Orientation = UIMath.EulerToQuaternion(new xna.Vector3((float)desc.xRotation, (float)desc.yRotation, (float)desc.zRotation)); if (!string.IsNullOrEmpty(desc.mesh)) { shapeEntity.State.Assets.Mesh = desc.mesh; } shapeEntity.MeshScale = new Vector3(.001f, .001f, .001f); shapeEntity.MeshRotation = new Vector3(desc.xRotation, desc.yRotation, desc.zRotation); shapeEntity.Flags = VisualEntityProperties.DoCompletePhysicsShapeUpdate; // shapeEntity.State.Flags |= EntitySimulationModifiers.Kinematic; humanoidShapes.Add(shapeEntity.State.Name, shapeEntity); } // now set up the Parent/Child relationships foreach (ParentChild rel in Relationships) { string Dof = rel.Dof; JointAngularProperties angular = new JointAngularProperties(); if (Dof == "Twist") { angular.TwistMode = JointDOFMode.Free; angular.TwistDrive = new JointDriveProperties(JointDriveMode.Position, new SpringProperties(500000, 1000, 0), 1000000); // angular.TwistDrive.Mode = JointDriveMode.Velocity; } if (Dof == "Swing1") { angular.Swing1Mode = JointDOFMode.Free; angular.SwingDrive = new JointDriveProperties(JointDriveMode.Position, new SpringProperties(500000, 1000, 0), 1000000); //angular.SwingDrive.Mode = JointDriveMode.Velocity; } if (Dof == "Swing2") { angular.Swing2Mode = JointDOFMode.Free; angular.SwingDrive = new JointDriveProperties(JointDriveMode.Position, new SpringProperties(500000, 1000, 0), 1000000); // angular.SwingDrive.Mode = JointDriveMode.Velocity; } EntityJointConnector[] connectors = new EntityJointConnector[] { new EntityJointConnector(humanoidShapes[prefix + rel.Child], rel.ChildNormal, rel.ChildAxis, rel.ChildConnect), new EntityJointConnector(humanoidShapes[prefix + rel.Parent], rel.ParentNormal, rel.ParentAxis, rel.ParentConnect) }; SegmentEntity child = (SegmentEntity)humanoidShapes[prefix + rel.Child]; child.CustomJoint = new Joint(); child.CustomJoint.State = new JointProperties(angular, connectors); child.CustomJoint.State.Name = rel.JointName; child.Flags = VisualEntityProperties.DoCompletePhysicsShapeUpdate; humanoidShapes[prefix + rel.Parent].InsertEntityGlobal(humanoidShapes[prefix + rel.Child]); } HumanoidEntity retValue = (HumanoidEntity)humanoidShapes[prefix + _parentName]; // retValue.State.MassDensity.CenterOfMass = new Pose(new Vector3(0.05f,1.05f,0), new Quaternion(0,0,0,1)); retValue.State.Flags = EntitySimulationModifiers.Kinematic; retValue.State.Name = name; return(retValue); }
//Numbers below shoud come from GameController void Start() { uiView = GetComponent <UIView>(); uiMath = GetComponent <UIMath>(); }