public virtual void DoInitSystem(CGfxParticleSystem sys, GParticleComponent compoent)
        {
            CreateParticleSystems(sys);

            compoent.ParticleSystemPropertyChanged(sys);
            InitSystem(sys);
        }
Exemple #2
0
        public unsafe void InitParticle(McParticleEffector effector, CGfxParticleSystem sys, CGfxParticle *p)
        {
            if (sys.TrailNode != null)
            {
                sys.TrailNode.CreateTrail(ref (*p));
            }

            if (sys.TextureCutNode != null)
            {
                sys.TextureCutNode.GetStartValue(ref (*p));
            }

            p->SetParticleLife(sys.MinLife, sys.MaxLife);
            if (sys.EnableEventReceiver)
            {
                sys.BindTriggerEvent(ref (*p));
            }

            //if (sys.TriggerNodes.Count > 0)
            //{
            //    for (int i = 0; i < sys.TriggerNodes.Count; i++)
            //    {
            //        sys.TriggerNodes[i].TriggerBornEvent(ref p->FinalPose);
            //    }
            //}
        }
        public void Tick(CCommandList cmd, CGfxParticleSystem sys, float elaspe)
        {
            ScopeTick.Begin();

            sys.Simulate(elaspe);//这里处理粒子死亡释放

            ScopeTickDeath.Begin();
            ScopeTickSubDeath.Begin();
            sys.DealDeathParticles();
            ScopeTickSubDeath.End();
            ScopeTickSubBorn.Begin();

            sys.TriggerParticle();

            ScopeTickSubBorn.End();
            ScopeTickDeath.End();

            //粒子系统的更新
            if (sys.MacrossNode != null)
            {
                ParticleData.ParticleSystem = sys;
                sys.MacrossNode.Update(elaspe, ParticleData);
            }
            ScopeTickState.Begin();
            sys.UpdateParticleSubState(elaspe);
            ScopeTickState.End();

            ScopeTickCompose.Begin();
            sys.DealParticleStateCompose(elaspe);
            ScopeTickCompose.End();

            sys.Flush2VB(cmd);

            ScopeTick.End();
        }
        //获取绕发射中心的旋转方向
        public void GetRotationByCenter(CGfxParticleSystem sys, CGfxParticleSubState substate, ref Quaternion rotation, out Vector3 result)
        {
            result = new Vector3(sys.Matrix.M41 + substate.Position.X,
                                 sys.Matrix.M42 + substate.Position.Y,
                                 sys.Matrix.M43 + substate.Position.Z);

            result = rotation * (mPose.mPosition - result) + result - mPose.mPosition;
        }
        public void GetDirectionToCenter([Editor.DisplayParamName("粒子系统对象(CGfxParticleSystem)")] CGfxParticleSystem sys, [Editor.DisplayParamName("粒子发射器状态对象(CGfxParticleSubState)")] CGfxParticleSubState substate, out Vector3 dir)
        {
            Vector3 basepos = new Vector3(sys.Matrix.M41 + substate.Position.X,
                                          sys.Matrix.M42 + substate.Position.Y,
                                          sys.Matrix.M43 + substate.Position.Z);

            dir = mPose.mPosition - basepos;
            dir.Normalize();
        }
        public virtual void CreateParticleSystems(CGfxParticleSystem sys)
        {
            if (sys.SubParticleSystems != null)
            {
                sys.SubParticleSystems = new List <CGfxParticleSystem>();
            }

            //sys.SubParticleSystems.Add(CreateParticleSystem1());
        }
 //[EngineNS.Editor.MacrossMember(Editor.MacrossMemberAttribute.enMacrossType.Callable | Editor.MacrossMemberAttribute.enMacrossType.Overrideable)]
 //[Editor.MacrossPanelPathAttribute("粒子系统/粒子系统对象(CGfxParticleSystem)/DoParticleSubState")]
 //[EngineNS.Editor.DisplayParamName("粒子发射器状态对象初始华")]
 public virtual void DoParticleSubStateBorn([EngineNS.Editor.DisplayParamName("粒子发射系统对象")] CGfxParticleSystem sys, [EngineNS.Editor.DisplayParamName("粒子发射器状态对象")] CGfxParticleSubState substate, int index)
 {
     if (substate.MacrossNode != null)
     {
         ParticleData.ParticleSubState     = substate;
         ParticleData.ParticleEmitterShape = substate.Shape;
         substate.MacrossNode.Init(ParticleData);
     }
 }
        //[Editor.MacrossPanelPathAttribute("粒子系统/粒子效应器(McParticleEffector)/InitSystem")]
        //[Editor.MacrossMemberAttribute(Editor.MacrossMemberAttribute.enMacrossType.Callable | Editor.MacrossMemberAttribute.enMacrossType.Overrideable)]
        public virtual async System.Threading.Tasks.Task <bool> InitSystem(CGfxParticleSystem sys, EngineNS.GamePlay.Actor.GActor actor, GParticleComponent compoent, GParticleComponent.GParticleComponentInitializer initializer)
        {
            DoInitSystem(sys, compoent);
            //await sys.SetHostActorMesh(compoent, initializer, UseMeshRName);
            //sys.SetHostActorMaterial(compoent, initializer, UseMaterialRName);
            await sys.InitSubSystem(actor, compoent);

            sys.HostActorMesh = compoent;
            return(true);
        }
        //宏图中处理逻辑 工具中提供固定形式
        public unsafe void OnParticleStateTick(CGfxParticleSystem sys, CGfxParticleState **pStates, int num, int stateIndex, CGfxParticleSubState state, float elaspe, int pindex)
        {
            for (int i = num - 1; i >= 0; i--)
            {
                if (pindex == 0)
                {
                    state.UpdateParticle(this, elaspe, sys, pStates[i]->Host);
                }

                state.MacrossParticleStateNodeUpdate(this, elaspe, sys, pStates[i]->Host, pStates[i], i);
            }
        }
        public Vector3 GetRotationByCenter([Editor.DisplayParamName("粒子系统对象(CGfxParticleSystem)")] CGfxParticleSystem sys, [Editor.DisplayParamName("粒子发射器状态对象(CGfxParticleSubState)")] CGfxParticleSubState substate, [Editor.DisplayParamName("转向轴(Vector3)")] Vector3 aix)
        {
            Vector3 basepos = new Vector3(sys.Matrix.M41 + substate.Position.X,
                                          sys.Matrix.M42 + substate.Position.Y,
                                          sys.Matrix.M43 + substate.Position.Z);

            Vector3 dir = mPose.mPosition - basepos;

            Vector3.Cross(ref dir, ref aix, out basepos);
            basepos.Normalize();
            return(basepos);
        }
        //生成ParticleState时的初始数据 宏图中设置
        public virtual unsafe void DoParticleStateBorn(CGfxParticleSystem sys, CGfxParticleState **pStates, CGfxParticleSubState substate, int stateIndex, int particlenum = 0)
        {
            int nowindex = sys.ParticleNumber - particlenum;

            for (int i = 0; i < particlenum; i++)
            {
                if (stateIndex == 0)
                {
                    substate.InitParticle(this, sys, pStates[i]->Host);
                }
                substate.MacrossParticleStateNodeInit(this, sys, pStates[i]->Host, pStates[i], nowindex + i);
                substate.EffectParticleStatePose(ref *pStates[i]);
            }
        }
        public unsafe void FacePose([Editor.DisplayParamName("粒子系统对象(CGfxParticleSystem)")] CGfxParticleSystem sys, [Editor.DisplayParamName("Bilboard类型(BILLBOARD_TYPE)")] CGfxParticleSystem.BILLBOARDTYPE type, [Editor.DisplayParamName("坐标系统类型(CoordinateSpace)")] CGfxParticleSystem.CoordinateSpace coord, ref Vector3 prepos)
        {
            var rc = CEngine.Instance.RenderContext;

            if (sys.UseCamera != null)
            {
                sys.Face2(ref this, type, sys.UseCamera, coord, ref prepos);
                return;
            }
#if PWindow
            EngineNS.GamePlay.IModuleInstance ModuleInstance = (EngineNS.GamePlay.IModuleInstance)EngineNS.CEngine.Instance.GameEditorInstance;
            if (ModuleInstance != null)
            {
                sys.Face2(ref this, type, ModuleInstance.GetMainViewCamera(), coord, ref prepos);
            }
#endif
        }
Exemple #13
0
        public bool CanTriggerParticle(CGfxParticleSystem sys)
        {
            if (Tick > sys.LiveTime)
            {
                return(false);
            }

            if (Tick <= sys.FireDelay)
            {
                return(false);
            }

            if (IsFirst)
            {
                IsFirst = false;
                return(true);
            }

            return(Tick - PreTriggerTick > sys.FireInterval);
        }
        //[Editor.MacrossMemberAttribute(Editor.MacrossMemberAttribute.enMacrossType.Callable | Editor.MacrossMemberAttribute.enMacrossType.Overrideable)]
        public void InitSystem([EngineNS.Editor.DisplayParamName("粒子系统对象(CGfxParticleSystem)")] CGfxParticleSystem sys)
        {
            //var rc = CEngine.Instance.RenderContext;
            //sys.MaxParticle = maxNum;
            //var shapes = CreateParticleShapes();


            //if (shapes.Count == 0)
            //    return;

            ////初始化粒子池
            //sys.InitParticlePool(rc, sys.MaxParticle, shapes);

            if (sys.MacrossNode != null)
            {
                ParticleData.ParticleSystem = sys;
                if (sys.UseMaterialRName != null && string.IsNullOrEmpty(sys.UseMaterialRName.Address) == false)
                {
                    sys.SetHostActorMaterial(sys.UseMaterialRName);
                }
                sys.MacrossNode.Init(ParticleData);
            }
        }
Exemple #15
0
        internal unsafe void OnParticleBorn(McParticleEffector effector, CGfxParticleSystem sys)
        {
            CGfxParticleState **pStates;
            int num = 0;

            ScopeTickGetNewBorns.Begin();
            SDK_GfxParticleSubState_GetNewBorns(CoreObject, &pStates, &num);
            ScopeTickGetNewBorns.End();
            ScopeTickDoParticleBorn.Begin();
            for (int i = 0; i < num; i++)
            {
                var particle = pStates[i]->Host;
                if ((IntPtr)particle == IntPtr.Zero)
                {
                    effector.DoParticleBorn(sys, ref CGfxParticle.Empty);
                }
                else
                {
                    effector.DoParticleBorn(sys, ref (*particle));
                }
            }
            ScopeTickDoParticleBorn.End();
        }
Exemple #16
0
 public bool IsDeath(CGfxParticleSystem sys)
 {
     return(Tick > sys.LiveTime);
 }
Exemple #17
0
 public void ParticleSystemPropertyChanged(CGfxParticleSystem sys)
 {
     ParticleSystemPropertyChangedEvent?.Invoke(sys);
 }
Exemple #18
0
        public unsafe void MacrossParticleStateNodeInit(McParticleEffector effector, CGfxParticleSystem sys, CGfxParticle *p, CGfxParticleState *pt, int pi)
        {
            //粒子状态信息的初始化 粒子下面可能有多个状态
            if (MacrossParticleStateNode != null)
            {
                effector.ParticleData.ParticleSystem       = sys;
                effector.ParticleData.ParticleSubState     = this;
                effector.ParticleData.ParticleEmitterShape = Shape;

                effector.ParticleData.Particle      = p;
                effector.ParticleData.ParticleState = pt;

                MacrossParticleStateNode.Init(effector.ParticleData, ref (*p), ref (*pt));
            }

            //var lifetick = p->mLifeTick / p->mLife;
            if (ColorNode != null)
            {
                ColorNode.GetStartValue();
                pt->mStartPose.SetUserParams_Color4(0, ColorNode.StartValue);
            }

            if (ParticleScaleNode != null)
            {
                ParticleScaleNode.GetStartValue();
                pt->mStartPose.mScale = ParticleScaleNode.StartValue;
            }

            if (ParticleVelocityNodes != null && ParticleVelocityNodes.Count > 0)
            {
                for (int i = 0; i < ParticleVelocityNodes.Count; i++)
                {
                    var ParticleVelocityNode = ParticleVelocityNodes[i];
                    if (ParticleVelocityNode != null)
                    {
                        ParticleVelocityNode.GetStartValue();
                        if (ParticleVelocityNodes.Count == 1)
                        {
                            //ParticleVelocityNode.StartValue.Normalize();
                            if (i == 0)
                            {
                                pt->mStartPose.mVelocity = ParticleVelocityNode.StartValue;
                            }
                            else
                            {
                                pt->mStartPose.mVelocity *= ParticleVelocityNode.StartValue;
                            }
                        }
                        else
                        {
                            ParticleVelocityNode.AddStartValue(pi, ref ParticleVelocityNode.StartValue);
                            //ParticleVelocityNode.AddStartValue(pt, ref ParticleVelocityNode.StartValue);
                        }
                    }
                }
            }

            if (RotationNodes != null && RotationNodes.Count > 0)
            {
                for (int i = 0; i < RotationNodes.Count; i++)
                {
                    var rotationNode = RotationNodes[i];
                    if (rotationNode != null)
                    {
                        rotationNode.GetStartValue2();
                        //ParticleVelocityNode.StartValue.Normalize();
                        if (i == 0)
                        {
                            pt->mStartPose.mRotation = rotationNode.StartValue;
                        }
                        else
                        {
                            pt->mStartPose.mRotation *= rotationNode.StartValue;
                        }
                    }
                }
            }

            if (AcceleratedNode != null)
            {
                AcceleratedNode.GetStartValue();
                pt->mStartPose.mAcceleration.X = AcceleratedNode.StartValue;
            }

            if (VelocityByTangentNode != null)
            {
                VelocityByTangentNode.GetStartValue();
                pt->mStartPose.mAxis = VelocityByTangentNode.StartValue;

                VelocityByTangentNode.Power.GetStartValue();
                pt->mStartPose.mAcceleration.Y = VelocityByTangentNode.Power.StartValue;
            }
        }
Exemple #19
0
        public unsafe void MacrossParticleStateNodeUpdate(McParticleEffector effector, float e, CGfxParticleSystem sys, CGfxParticle *p, CGfxParticleState *pt, int pi)
        {
            var life = (*p).mLife;
            var tick = (*p).mLifeTick;

            if (tick / life >= 1)
            {
                if (ParticleVelocityNodes != null && ParticleVelocityNodes.Count > 1)
                {
                    for (int i = 0; i < ParticleVelocityNodes.Count; i++)
                    {
                        var ParticleVelocityNode = ParticleVelocityNodes[i];
                        if (ParticleVelocityNode != null)
                        {
                            ParticleVelocityNode.StartValues.RemoveAt(pi);
                        }
                    }
                }
                return;
            }

            effector.ParticleData.ParticleSystem       = sys;
            effector.ParticleData.ParticleSubState     = this;
            effector.ParticleData.ParticleEmitterShape = Shape;

            effector.ParticleData.Particle      = p;
            effector.ParticleData.ParticleState = pt;


            if (ParticleScaleNode != null)
            {
                ParticleScaleNode.SetParticleScale2((*p).mLife, (*p).mLifeTick, ref (*pt).mPose);
                ParticleScaleNode.SetParticleScale(life, tick, ref (*pt).mPose);

                pt->mPose.mScale  = ParticleScaleNode.Scale;
                pt->mPose.mScale *= pt->mStartPose.mScale;
            }

            if (VelocityByCenterNode != null)
            {
                VelocityByCenterNode.SetPower(life, tick);
                VelocityByCenterNode.SetPower2((*p).mLife, (*p).mLifeTick);
            }

            if (VelocityByTangentNode != null)
            {
                VelocityByTangentNode.SetAix(life, tick, ref pt->mStartPose.mAxis, pt->mStartPose.mAcceleration.Y);
                VelocityByTangentNode.SetAix2((*p).mLife, (*p).mLifeTick, ref pt->mStartPose.mAxis);
            }

            if (ParticleVelocityNodes != null && ParticleVelocityNodes.Count > 0)
            {
                for (int i = 0; i < ParticleVelocityNodes.Count; i++)
                {
                    var ParticleVelocityNode = ParticleVelocityNodes[i];
                    if (ParticleVelocityNode != null)
                    {
                        ParticleVelocityNode.SetParticleVelocity2((*p).mLife, (*p).mLifeTick, ref (*pt).mPose);
                        ParticleVelocityNode.SetParticleVelocity(life, tick, ref (*pt).mPose);

                        if (ParticleVelocityNodes.Count == 1)
                        {
                            if (i == 0)
                            {
                                pt->mPose.mVelocity = ParticleVelocityNode.Velocity;
                            }
                            else
                            {
                                pt->mPose.mVelocity += ParticleVelocityNode.Velocity;
                            }

                            pt->mPose.mVelocity *= pt->mStartPose.mVelocity;
                        }
                        else
                        {
                            if (i == 0)
                            {
                                pt->mPose.mVelocity = ParticleVelocityNode.Velocity * ParticleVelocityNode.StartValues[pi];
                            }
                            else
                            {
                                pt->mPose.mVelocity += ParticleVelocityNode.Velocity * ParticleVelocityNode.StartValues[pi];
                            }
                        }


                        //ParticleScaleNode.SetParticleScale2((*p).mLife, (*p).mLifeTick, ref (*pt).mPose);
                    }
                }
            }

            if (RotationNodes != null && RotationNodes.Count > 0)
            {
                for (int i = 0; i < RotationNodes.Count; i++)
                {
                    var RotationNode = RotationNodes[i];
                    if (RotationNode != null)
                    {
                        RotationNode.SetYawPitchRoll(life, tick);

                        {
                            RotationNode.Update(e, ref pt->mPose, ref pt->mStartPose);
                        }

                        //ParticleScaleNode.SetParticleScale2((*p).mLife, (*p).mLifeTick, ref (*pt).mPose);
                        if (sys.IsBillBoard)
                        {
                            float Yaw, Pitch, Roll;
                            pt->mPose.mRotation.GetYawPitchRoll(out Yaw, out Pitch, out Roll);
                            pt->mPose.mAngle = Roll;
                        }
                    }
                }
            }

            if (AcceleratedNode != null)
            {
                AcceleratedNode.SetAccelerated(life, tick);
                pt->mPose.mAcceleration.X = AcceleratedNode.Accelerated * pt->mStartPose.mAcceleration.X;
            }
            else
            {
                pt->mPose.mAcceleration.X = 1f;
            }

            if (VelocityByCenterNode != null && VelocityByTangentNode != null)
            {
                VelocityByCenterNode.GetValue(ref (*pt), sys, this, e);
                VelocityByTangentNode.GetValue(ref (*pt), sys, this, e);

                pt->AccelerationEffect(e, ref VelocityByTangentNode.Offset, ref VelocityByCenterNode.Direction);
            }
            else if (VelocityByCenterNode != null)
            {
                VelocityByCenterNode.GetValue(ref (*pt), sys, this, e);

                VelocityByCenterNode.OnlyUseThisNode(e, ref (*pt));
            }
            else if (VelocityByTangentNode != null)
            {
                VelocityByTangentNode.GetValue(ref (*pt), sys, this, e);

                VelocityByTangentNode.OnlyUseThisNode(e, ref (*pt));
            }
            else if (MacrossParticleStateNode != null)
            {
                //if (ParticleVelocityNodes != null && ParticleVelocityNodes.Count > 0)
                {
                    pt->AccelerationEffect(e);
                }
            }

            //粒子状态信息的更新 粒子下面可能有多个状态
            if (MacrossParticleStateNode != null)
            {
                MacrossParticleStateNode.Update(e, effector.ParticleData, ref (*p), ref (*pt));
            }

            if (ColorNode != null)
            {
                ColorNode.SetParticleColor(life, tick, ref (*pt).mPose, ref (*pt).mStartPose);
            }
        }
 //[Editor.MacrossMemberAttribute(Editor.MacrossMemberAttribute.enMacrossType.Callable | Editor.MacrossMemberAttribute.enMacrossType.Overrideable)]
 public virtual void DoParticleDead([Editor.DisplayParamName("粒子系统对象(CGfxParticleSystem)")] CGfxParticleSystem sys, [Editor.DisplayParamName("粒子对象(CGfxParticle)")] ref CGfxParticle p)
 {
     p.mExtData = IntPtr.Zero;
     p.mFlags   = 0;
 }
Exemple #21
0
        internal unsafe void OnParticleStateBorn(McParticleEffector effector, CGfxParticleSystem sys, int stateIndex)
        {
            CGfxParticleState **pStates;
            int num = 0;

            ScopeTickGetNewBorns2.Begin();
            //这里处理每个substate发射出来的粒子,如果num的预期超过粒子数目最大值就有可能...
            SDK_GfxParticleSubState_GetNewBorns(CoreObject, &pStates, &num);

            ScopeTickGetNewBorns2.End();
            ScopeTickDoParticleStateBorn.Begin();

            effector.DoParticleStateBorn(sys, pStates, this, stateIndex, num);

            ScopeTickDoParticleStateBorn.End();
            SDK_GfxParticleSubState_PushNewBorns(CoreObject);
            if (sys.IsBind == true)
            {
                return;
            }

            if (sys.HostActorPlacement == null)
            {
                return;
            }

            var placement = sys.HostActorPlacement as GParticlePlacementComponent;

            if (placement == null)
            {
                return;
            }

            Vector3    pos;
            Vector3    scale;
            Quaternion rot;
            Vector4    temppos;

            bool IsIgnore = placement.IsIgnore;

            placement.IsIgnore = false;
            placement.WorldMatrix.Decompose(out scale, out rot, out pos);
            placement.IsIgnore = IsIgnore;

            for (int i = 0; i < num; i++)
            {
                //pStates[i]->SyncStartToPose();
                pStates[i]->mStartPose.mPosition *= scale;
                Vector3.Transform(ref pStates[i]->mStartPose.mPosition, ref rot, out temppos);
                pStates[i]->mStartPose.mPosition.X += temppos.X;
                pStates[i]->mStartPose.mPosition.Y += temppos.Y;
                pStates[i]->mStartPose.mPosition.Z += temppos.Z;
                pStates[i]->mStartPose.mPosition   += pos;

                if (rot.IsValid)
                {
                    pStates[i]->mStartPose.mRotation *= rot;
                }

                pStates[i]->mStartPose.mScale *= scale;

                Vector3.Transform(ref pStates[i]->mStartPose.mVelocity, ref rot, out temppos);
                pStates[i]->mStartPose.mVelocity.X = temppos.X;
                pStates[i]->mStartPose.mVelocity.Y = temppos.Y;
                pStates[i]->mStartPose.mVelocity.Z = temppos.Z;
                pStates[i]->mStartPose.mVelocity.Normalize();

                //mPose
                pStates[i]->mPose.mPosition *= scale;
                Vector3.Transform(ref pStates[i]->mPose.mPosition, ref rot, out temppos);
                pStates[i]->mPose.mPosition.X += temppos.X;
                pStates[i]->mPose.mPosition.Y += temppos.Y;
                pStates[i]->mPose.mPosition.Z += temppos.Z;
                pStates[i]->mPose.mPosition   += pos;

                if (rot.IsValid)
                {
                    pStates[i]->mPose.mRotation *= rot;
                }

                pStates[i]->mPose.mScale *= scale;

                Vector3.Transform(ref pStates[i]->mPose.mVelocity, ref rot, out temppos);
                pStates[i]->mPose.mVelocity.X = temppos.X;
                pStates[i]->mPose.mVelocity.Y = temppos.Y;
                pStates[i]->mPose.mVelocity.Z = temppos.Z;
                pStates[i]->mPose.mVelocity.Normalize();
            }
        }
Exemple #22
0
 public unsafe void UpdateParticle(McParticleEffector effector, float e, CGfxParticleSystem sys, CGfxParticle *p)
 {
 }
 //[Editor.MacrossMemberAttribute(Editor.MacrossMemberAttribute.enMacrossType.Callable | Editor.MacrossMemberAttribute.enMacrossType.Overrideable)]
 public virtual void DoParticleBorn([DisplayParamName("粒子系统对象(CGfxParticleSystem)")] CGfxParticleSystem sys, [DisplayParamName("粒子对象(CGfxParticle)")] ref CGfxParticle p)
 {
     //p.mLife = 100.0f;
 }
 //计算最终粒子姿态
 public unsafe void OnParticleCompose(CGfxParticleSystem sys, CGfxParticle **ppParticles, int num, float elaspe)
 {
     DoParticleCollectCompose(sys, ppParticles, num, sys.SubStates.Length, elaspe);
 }
        public virtual unsafe void DoParticleCollectCompose(CGfxParticleSystem sys, CGfxParticle **ppParticles, int particlenum, int substatenum, float elaspe)
        {
            bool usecompute = true;

            for (int i = 0; i < particlenum; i++)
            {
                if (sys.BillBoardType != CGfxParticleSystem.BILLBOARDTYPE.BILLBOARD_DISABLE || sys.TriggerNodes.Count > 0)
                {
                    prepos = ppParticles[i]->FinalPose.mPosition;
                }

                if (sys.ComposeNodes.Count > 0)
                {
                    usecomposenodes = false;
                    for (int ni = 0; ni < sys.ComposeNodes.Count; ni++)
                    {
                        if (sys.ComposeNodes[ni].CanUsed)
                        {
                            sys.ComposeNodes[ni].ComposeParticle(sys, ref *ppParticles[i], substatenum, elaspe, usecompute);
                            if (usecomposenodes == false)
                            {
                                (*ppParticles[i]).FinalPose = sys.ComposeNodes[ni].ResultPose;// TODO.
                            }
                            else
                            {
                                CGfxParticlePose.AddFunc(ref (*ppParticles[i]).FinalPose, ref (*ppParticles[i]).FinalPose, ref sys.ComposeNodes[ni].ResultPose);
                            }

                            usecomposenodes = true;
                        }
                    }
                }

                usecompute = false;

                if (usecomposenodes == false)
                {
                    if (sys.SubStates.Length > 0)
                    {
                        var ps = ppParticles[i]->GetState(0);
                        ppParticles[i]->FinalPose = ps->mPose;
                        CGfxParticlePose.Set(ref ppParticles[i]->FinalPose, ref ps->mPose);
                        var substate = sys.SubStates[0];
                        if (substate.TransformNode != null)
                        {
                            Quaternion.RotationYawPitchRoll(substate.TransformNode.YawPitchRoll.X, substate.TransformNode.YawPitchRoll.Y, substate.TransformNode.YawPitchRoll.Z, out substate.TransformNode.Rotation);
                            Matrix.Transformation(substate.TransformNode.Scale, substate.TransformNode.Rotation, substate.TransformNode.Translation, out matrix);

                            Vector3.Transform(ref (ppParticles[i]->FinalPose.mPosition), ref matrix, out matrixtovec4);
                            ppParticles[i]->FinalPose.mPosition.X = matrixtovec4.X;
                            ppParticles[i]->FinalPose.mPosition.Y = matrixtovec4.Y;
                            ppParticles[i]->FinalPose.mPosition.Z = matrixtovec4.Z;

                            if (substate.TransformNode.IgnoreRotation == false)
                            {
                                if (substate.RotationNodes == null || substate.RotationNodes.Count == 0)
                                {
                                    ppParticles[i]->FinalPose.mRotation = substate.TransformNode.Rotation;
                                }
                                else
                                {
                                    ppParticles[i]->FinalPose.mRotation *= substate.TransformNode.Rotation;
                                }
                            }

                            if (substate.TransformNode.IgnoreScale == false)
                            {
                                if (substate.ParticleScaleNode != null)
                                {
                                    ppParticles[i]->FinalPose.mScale *= substate.TransformNode.Scale;
                                }
                                else
                                {
                                    ppParticles[i]->FinalPose.mScale = substate.TransformNode.Scale;
                                }
                            }
                        }
                    }
                }
                //TODO..
                if (sys.TrailNode != null)
                {
                    sys.TrailNode.CreateAndUpdateTrailData(sys, ref *ppParticles[i], elaspe);
                }

                if (sys.TextureCutNode != null)
                {
                    sys.TextureCutNode.Update(elaspe, ref *ppParticles[i]);
                    ppParticles[i]->FinalPose.SetUserParamsY(1, (byte)sys.TextureCutNode.CurrentIndex);
                }


                //处理处罚结点
                if (sys.TriggerNodes.Count > 0)
                {
                    for (int j = 0; j < sys.TriggerNodes.Count; j++)
                    {
                        sys.TriggerNodes[j].RefreshUpdateEvent(ref ppParticles[i]->FinalPose, ref prepos);
                        sys.TriggerNodes[j].TriggerBornEvent(ref ppParticles[i]->FinalPose);
                        sys.TriggerNodes[j].TriggerUpdateEvent(ref ppParticles[i]->FinalPose, ref prepos);
                    }
                }

                if (sys.EnableEventReceiver)
                {
                    var tag = ppParticles[i]->Tag as ParticleTag;
                    if (tag != null)
                    {
                        if (tag.TriggerEvent != null)
                        {
                            if (tag.TriggerEvent.TriggerData.InheritPosition)
                            {
                                ppParticles[i]->FinalPose.mPosition += tag.TriggerEvent.Pose.mPosition;
                            }

                            if (tag.TriggerEvent.TriggerData.InheritScale)
                            {
                                ppParticles[i]->FinalPose.mScale *= tag.TriggerEvent.Pose.mScale;
                            }

                            if (tag.TriggerEvent.TriggerData.InheritRotation)
                            {
                                ppParticles[i]->FinalPose.mRotation *= tag.TriggerEvent.Pose.mRotation;
                            }

                            if (tag.TriggerEvent.TriggerData.InheritVelocity)//Todo
                            {
                                ppParticles[i]->FinalPose.mPosition += tag.TriggerEvent.Pose.mVelocity * elaspe;
                            }
                        }
                    }
                }

                if (sys.PointGravityNode != null)
                {
                    gravity = sys.PointGravityNode._Data.Point - ppParticles[i]->FinalPose.mPosition;
                    // var dis = gravity.Length();
                    //if (dis > 0.00001f)
                    {
                        ppParticles[i]->FinalPose.mAcceleration.X = 0.5f * sys.PointGravityNode._Data.Accelerated * ppParticles[i]->mLifeTick * ppParticles[i]->mLifeTick;

                        //if (dis < ppParticles[i]->FinalPose.mAcceleration.X)
                        //{
                        //    ppParticles[i]->FinalPose.mAcceleration.X = dis;
                        //}
                        gravity += ppParticles[i]->FinalPose.mVelocity;
                        gravity.Normalize();

                        ppParticles[i]->FinalPose.mPosition += gravity * ppParticles[i]->FinalPose.mAcceleration.X;
                    }
                }

                if (sys.BillBoardType != CGfxParticleSystem.BILLBOARDTYPE.BILLBOARD_DISABLE)
                {
                    ppParticles[i]->FacePose(sys, sys.BillBoardType, sys.CoordSpace, ref prepos);
                }

                ppParticles[i]->FinalPose.SetUserParamsX(1, 1);
            }
        }
Exemple #26
0
 public void SetParticleSystem(CGfxParticleSystem sys)
 {
     ParticleSys = sys;
 }
Exemple #27
0
        public async Task InitParticleSubSystemComponent(EngineNS.GamePlay.Actor.GActor actor, GParticleComponent particlecomponent, CGfxParticleSystem sys)
        {
            var rc = EngineNS.CEngine.Instance.RenderContext;

            ParticleModifier = new CGfxParticleModifier();
            ParticleModifier.SetParticleSystem(sys);

            GMeshComponentInitializer initializer = new GMeshComponentInitializer();

            await SetInitializer(rc, actor, particlecomponent, initializer);

            SpecialName       = string.IsNullOrEmpty(sys.Name) ? Guid.NewGuid().ToString() : sys.Name;
            EditorVisibleName = sys.EditorVisibleName;
            particlecomponent.AddComponent(this);

            Host = actor;

            var mPlacementData = Placement.mPlacementData;

            Placement = new GParticlePlacementComponent();
            await Placement.SetInitializer(rc, actor, this, mPlacementData as GComponentInitializer);

            Placement.SetMatrix(ref sys.Matrix);

            ((GParticlePlacementComponent)Placement).IsIgnore = !sys.IsBind;

            sys.HostActorMesh = this;
        }