/// <summary> /// コンストラクタ /// </summary> /// <param name="rigids">剛体情報</param> /// <param name="joints">関節情報</param> /// <param name="model">モデル情報</param> public PhysicsManager(MMDRigid[] rigids, MMDJoint[] joints, MMDModel model) { List<RigidBody> rbodies = new List<RigidBody>(); List<Generic6DofSpringConstraint> dofjoints = new List<Generic6DofSpringConstraint>(); motionState = new List<MMDMotionState>(); List<short> groups = new List<short>(); List<short> masks = new List<short>(); //剛体の作成 for (int i = 0; i < rigids.Length; i++) { MMDMotionState mstate; short group; rbodies.Add(CreateRigidBody(rigids[i], model, out group, out mstate)); motionState.Add(mstate); groups.Add(group); masks.Add((short)rigids[i].GroupTarget); } //ジョイント(拘束)の作成 for (int i = 0; i < joints.Length; i++) { RigidBody phisic0 = rbodies[(int)joints[i].RigidBodyA]; RigidBody phisic1 = rbodies[(int)joints[i].RigidBodyB]; dofjoints.Add(CreateJoint(phisic0, phisic1, joints[i], model)); } Rigids = new ReadOnlyCollection<RigidBody>(rbodies); this.groups = groups.ToArray(); this.masks = masks.ToArray(); Joints = new ReadOnlyCollection<Generic6DofSpringConstraint>(dofjoints); bSetup = true; //イベントをフック PhysicsThreadManager.Instanse.Synchronize += new Action(Update); PhysicsThreadManager.Instanse.DropFrame += new Action<int>(DropFrame); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="modelParts">モデルパーツ</param> /// <param name="boneManager">ボーンマネージャ</param> /// <param name="faceManager">表情マネージャ</param> /// <param name="attachedMotion">付属モーション</param> /// <param name="rigids">剛体</param> /// <param name="joints">ジョイント</param> public MMDXModel(List<IMMDModelPart> modelParts, MMDBoneManager boneManager, IMMDFaceManager faceManager, Dictionary<string, MMDMotion> attachedMotion, MMDRigid[] rigids, MMDJoint[] joints) : base(modelParts, boneManager, faceManager, attachedMotion, rigids, joints) { #if XBOX //ボーンマネージャ・表情マネージャを変換しておく this.boneManager = (MMDXBoxBoneManager)boneManager; this.faceManager = (MMDXBoxFaceManager)faceManager; //グラフィックデバイスの抜き出し if (modelParts.Count > 0) { GraphicsDevice graphics = ((MMDModelPart)modelParts[0]).GraphicsDevice; //頂点バッファの作成 skinVertexBuffer = new WritableVertexBuffer(graphics, this.boneManager.SKinTransformXBox.Length * 4, typeof(VertexSkinning)); this.faceManager.SetUp(graphics); } #endif }
/// <summary> /// コンストラクタ /// </summary> /// <param name="vertex">頂点データ</param> /// <param name="modelParts">モデルパーツ</param> /// <param name="boneManager">ボーンマネージャ</param> /// <param name="faceManager">表情マネージャ</param> /// <param name="attachedMotion">付随モーション</param> /// <param name="rigids">剛体情報</param> /// <param name="joints">関節情報</param> public SlimMMDModel(MMDVertexNmTx[] vertex, List<IMMDModelPart> modelParts, MMDBoneManager boneManager, MMDFaceManager faceManager, Dictionary<string, MMDMotion> attachedMotion, MMDRigid[] rigids, MMDJoint[] joints) : base(modelParts, boneManager, faceManager, attachedMotion, rigids, joints) { m_vertex = vertex; //データのコピー verticesSource = new VertexPNmTx[m_vertex.LongLength]; for (long i = 0; i < m_vertex.LongLength; ++i) { verticesSource[i].Position = m_vertex[i].Position; verticesSource[i].Normal = m_vertex[i].Normal; verticesSource[i].Texture = m_vertex[i].TextureCoordinate; } InitGraphicsResource(); SlimMMDXCore.Instance.LostDevice += OnLostDevice; SlimMMDXCore.Instance.ResetDevice += OnResetDevice; }
/// <summary> /// コンストラクタ /// </summary> /// <param name="modelParts">モデルパーツ</param> /// <param name="boneManager">ボーンマネージャ</param> /// <param name="faceManager">表情マネージャ</param> /// <param name="attachedMotion">付随モーション</param> /// <param name="rigids">剛体情報</param> /// <param name="joints">関節情報</param> public MMDModel(List<IMMDModelPart> modelParts, MMDBoneManager boneManager, IMMDFaceManager faceManager, Dictionary<string, MMDMotion> attachedMotion, MMDRigid[] rigids, MMDJoint[] joints) { Transform = Matrix.Identity; this.modelParts = modelParts; this.boneManager = boneManager; this.faceManager = faceManager; this.attachedMotion = attachedMotion; Culling = true; boneManager.CalcGlobalTransform(); this.physicsManager = new PhysicsManager(rigids, joints, this); foreach (var part in modelParts) part.SetModel(this); Parts = new ReadOnlyCollection<IMMDModelPart>(modelParts); animationPlayer = new AnimationPlayer(boneManager, faceManager); //イベントフック MMDCore.Instance.OnBoneUpdate += new Action<float>(BoneUpdate); MMDCore.Instance.OnSkinUpdate += new Action<float>(SkinUpdate); }
private Generic6DofSpringConstraint CreateJoint(RigidBody body0, RigidBody body1, MMDJoint joint, MMDModel model) { Matrix frameInA, frameInB; btTransform btFrameInA, btFrameInB; Matrix jointPos =MMDXMath.CreateMatrixFromYawPitchRoll(joint.Rotation[1], joint.Rotation[0], joint.Rotation[2]) * MMDXMath.CreateTranslationMatrix(joint.Position[0], joint.Position[1], joint.Position[2]); if (body0.MotionState != null) { MMDMotionState motionState = (MMDMotionState)body0.MotionState; frameInA = MMDXMath.ToMatrix(motionState.GraphicsWorldTrans); } else throw new NotImplementedException("来るハズないのだが"); frameInA = jointPos * model.Transform * Matrix.Invert(frameInA); if (body1.MotionState != null) { MMDMotionState motionState = (MMDMotionState)body1.MotionState; frameInB = MMDXMath.ToMatrix(motionState.GraphicsWorldTrans); } else throw new NotImplementedException("来るハズないのだが"); frameInB = jointPos * model.Transform * Matrix.Invert(frameInB); //frameInB = jointPos * Matrix.Invert(MMDMath.ConvertToMatrix(body1.GetWorldTransformSmart())); MMDXMath.TobtTransform(ref frameInA, out btFrameInA); MMDXMath.TobtTransform(ref frameInB, out btFrameInB); Generic6DofSpringConstraint mConstPoint = new Generic6DofSpringConstraint(body0, body1, btFrameInA, btFrameInB, true); //G6Dof設定用変数の準備 mConstPoint.setLinearLowerLimit(new btVector3(joint.ConstrainPosition1)); mConstPoint.setLinearUpperLimit(new btVector3(joint.ConstrainPosition2)); mConstPoint.setAngularLowerLimit(new btVector3(joint.ConstrainRotation1)); mConstPoint.setAngularUpperLimit(new btVector3(joint.ConstrainRotation2)); System.Diagnostics.Debug.WriteLine(joint.Name); for(int i=0;i<3;i++) System.Diagnostics.Debug.WriteLine(joint.ConstrainPosition1[i]); for (int i = 0; i < 3; i++) System.Diagnostics.Debug.WriteLine(joint.ConstrainPosition2[i]); for (int i = 0; i < 3; i++) System.Diagnostics.Debug.WriteLine(joint.ConstrainRotation1[i]); for (int i = 0; i < 3; i++) System.Diagnostics.Debug.WriteLine(joint.ConstrainRotation2[i]); for (int i = 0; i < 3; i++) { mConstPoint.setStiffness(i, joint.SpringPosition[i]); mConstPoint.enableSpring(i, true); mConstPoint.setStiffness(i + 3, joint.SpringRotation[i]); mConstPoint.enableSpring(i + 3, true); } mConstPoint.calculateTransforms(); mConstPoint.setEquilibriumPoint(); return mConstPoint; }