/// <summary> /// IMotionProviderメンバーの実装 /// </summary> public void Tick(int fps, float elapsedTime, IMorphManager morphManager) { // 行列の更新 foreach (var boneMotion in boneMotions) { boneMotion.ReviseBone((ulong)CurrentFrame); } foreach (var morphMotion in morphMotions) { morphManager.ApplyMorphProgress(morphMotion.GetMorphValue((ulong)CurrentFrame), morphMotion.MorphName); } // 停止中はフレームを進めない if (!isPlaying) { return; } // フレームを進める CurrentFrame += elapsedTime * fps; if (FrameTicked != null) { FrameTicked(this, new EventArgs()); } // 最終フレームに達した時の処理 if (CurrentFrame >= FinalFrame) { CurrentFrame = (actionAfterMotion == ActionAfterMotion.Replay) ? 1.0e-3f : FinalFrame; if (MotionFinished != null) { MotionFinished(this, actionAfterMotion); } } }
/// <summary> /// 初期化 /// </summary> /// <param name="skinning">スキニングに利用するインターフェース</param> public void Initialize(ModelData model, IMorphManager morph, ISkinningProvider skinning, IBufferManager bufferManager) { skinningProvider = skinning; motionTimer = new Stopwatch(); motionTimer.Start(); this.morphManager = morph; SubscribedMotionMap = new List <KeyValuePair <string, IMotionProvider> >(); }
public GroupMorphProvider(PMXModel model, IMorphManager morph) { this.morphManager = morph; int i = 0; foreach (MorphData morphData in model.Model.MorphList.Morphes) { if (morphData.type == MorphType.Group) { this.Morphs.Add(morphData.MorphName, new GroupMorphData(morphData)); } this.morphNameList.Add(i, morphData.MorphName); i++; } }
/// <summary> /// Update the whole skinning /// </summary> /// <param name="morphManager"></param> public virtual void UpdateSkinning(IMorphManager morphManager) { ResetAllBoneTransform(); UpdateGlobal(); foreach (ITransformUpdater kinematicsProvider in this.KinematicsProviders) { if (kinematicsProvider.UpdateTransform()) { UpdateGlobal(); //ResetAllBoneTransform();// BUG これなんでいれたっけ? } } foreach (var pmxBone in this.RootBone) { pmxBone.UpdateGrobalPose(); } SkeletonUpdated(this, new EventArgs()); for (int i = 0; i < this.Bone.Length; i++) { this.GlobalBonePose[this.Bone[i].BoneIndex] = this.Bone[i].GlobalPose; } }
/// <summary> /// IMotionProviderImplementation of a Member /// </summary> public void Tick(int fps, float elapsedTime, IMorphManager morphManager) { // 行列の更新 foreach (var boneMotion in this.boneMotions) { boneMotion.ReviseBone(this.CurrentFrame); } foreach (var morphMotion in this.morphMotions) { morphManager.ApplyMorphProgress(morphMotion.GetMorphValue((ulong)this.CurrentFrame), morphMotion.MorphName); } if (!this.isPlaying) { return; } this.CurrentFrame += (float)elapsedTime * fps; if (this.CurrentFrame >= this.FinalFrame) { this.CurrentFrame = this.FinalFrame; } if (FrameTicked != null) { FrameTicked(this, new EventArgs()); } if (this.CurrentFrame >= this.FinalFrame) { if (MotionFinished != null) { MotionFinished(this, this.actionAfterMotion); } if (this.actionAfterMotion == ActionAfterMotion.Replay) { this.CurrentFrame = 1.0e-3f; } } }
public override void Subscribe(EffectVariable subscribeTo, SubscribeArgument variable) { var currentModel = variable.Context.CurrentTargetContext.WorldSpace.getDrawableByFileName(name); if (currentModel == null) { return; } IDrawable targetDrawable = isSelf ? variable.Model : currentModel; if (target == TargetObject.UnUsed) { switch (variableType) { case VariableType.Float4x4: subscribeTo.AsMatrix().SetMatrix(variable.Context.MatrixManager.WorldMatrixManager.getWorldMatrix(targetDrawable)); break; case VariableType.Float3: subscribeTo.AsVector().Set(targetDrawable.Transformer.Position); break; case VariableType.Float4: subscribeTo.AsVector().Set(new Vector4(targetDrawable.Transformer.Position, 1f)); break; case VariableType.Float: subscribeTo.AsScalar().Set(targetDrawable.Transformer.Scale.Length()); break; case VariableType.Bool: subscribeTo.AsScalar().Set(targetDrawable.Visibility); break; default: break; } } else if (target == TargetObject.BoneName) { IEnumerable <PMXBone> targetBone = (from bone in ((PMXModel)targetDrawable).Skinning.Bone where bone.BoneName == itemName select bone); foreach (var bone in targetBone) { Matrix mat = bone.GlobalPose * variable.Context.MatrixManager.WorldMatrixManager.getWorldMatrix(targetDrawable); switch (variableType) { case VariableType.Float4x4: subscribeTo.AsMatrix().SetMatrix(mat); break; case VariableType.Float3: subscribeTo.AsVector().Set(Vector3.TransformCoordinate(bone.Position, mat)); break; case VariableType.Float4: subscribeTo.AsVector().Set(new Vector4(Vector3.TransformCoordinate(bone.Position, mat), 1f)); break; default: break; } break; } } else if (target == TargetObject.FaceName) { IMorphManager morphManager = ((PMXModel)targetDrawable).Morphmanager; subscribeTo.AsScalar().Set(morphManager.getMorphProgress(name)); } else { switch (target) { case TargetObject.X: subscribeTo.AsScalar().Set(targetDrawable.Transformer.Position.X); break; case TargetObject.Y: subscribeTo.AsScalar().Set(targetDrawable.Transformer.Position.Y); break; case TargetObject.Z: subscribeTo.AsScalar().Set(targetDrawable.Transformer.Position.Z); break; case TargetObject.XYZ: subscribeTo.AsVector().Set(targetDrawable.Transformer.Position); break; case TargetObject.Rx: case TargetObject.Ry: case TargetObject.Rz: case TargetObject.Rxyz: float xRotation, yRotation, zRotation; //X,Y,Z軸回転量に変換する。 int type = 0; //分解パターン if ( !CGHelper.FactoringQuaternionXYZ(targetDrawable.Transformer.Rotation, out xRotation, out yRotation, out zRotation)) { if ( !CGHelper.FactoringQuaternionYZX(targetDrawable.Transformer.Rotation, out yRotation, out zRotation, out xRotation)) { CGHelper.FactoringQuaternionZXY(targetDrawable.Transformer.Rotation, out zRotation, out xRotation, out yRotation); type = 2; } else { type = 1; } } else { type = 0; } if (target == TargetObject.Rx) { subscribeTo.AsScalar().Set(xRotation); } else if (target == TargetObject.Ry) { subscribeTo.AsScalar().Set(yRotation); } else if (target == TargetObject.Rz) { subscribeTo.AsScalar().Set(zRotation); } else { subscribeTo.AsVector().Set(new Vector3(xRotation, yRotation, zRotation)); } break; case TargetObject.Si: subscribeTo.AsScalar().Set(targetDrawable.Transformer.Scale.Length()); break; case TargetObject.Tr: //TODO Trへの対応 break; default: throw new ArgumentOutOfRangeException(); } } }