/// <summary>
        /// Get emitter by its name for the given asset rule
        /// </summary>
        /// <param name="ptxAssetRulePtr">Pointer to the PtfxAssetRule instance</param>
        /// <param name="emitterName">Name of the child emitter object</param>
        /// <returns></returns>
        private static PtxEventEmitter *GetPtfxEventEmitterByName(IntPtr ptxAssetRulePtr, string emitterName)
        {
            if (bInitialized == false)
            {
                return(null);
            }

            PtxEventEmitter *foundEmitter = null;

            var ptxRule = Marshal.PtrToStructure <PtxEffectRule>(ptxAssetRulePtr);

            for (var i = 0; i < ptxRule.EmittersCount; i++)
            {
                var emitter = ptxRule.Emitters[i];

                var szName = Marshal.PtrToStringAnsi(emitter->SzEmitterName);

                if (szName == emitterName)
                {
                    foundEmitter = emitter;

                    break;
                }
            }

            return(foundEmitter);
        }
Exemple #2
0
        private static void SetEmitterColour(IntPtr ptfxRule, string particleName, byte red, byte green, byte blue, byte alpha)
        {
            var behaviourHash = Game.GenerateHash("ptxu_Colour");

            PtxEventEmitter *emitter = GetPtfxEventEmitterByName(ptfxRule, particleName);

            var r = 1.0f / 255 * red;
            var g = 1.0f / 255 * green;
            var b = 1.0f / 255 * blue;
            var a = 1.0f / 255 * alpha;

            for (var i = 0; i < emitter->ParticleRule->BehavioursCount; i++)
            {
                Ptxu_Colour *behaviour = emitter->ParticleRule->Behaviours[i];

                if (behaviour->HashName != (uint)behaviourHash)
                {
                    continue;
                }

                for (var x = 0; x < behaviour->NumFrames; x++)
                {
                    PtxKeyframeProp *keyframe = behaviour->KeyframeProps[x];

                    if (keyframe->Current.Items == IntPtr.Zero)
                    {
                        continue;
                    }

                    var items = (PtxVarVector *)keyframe->Current.Items;

                    for (var y = 0; y < keyframe->Current.Count; y++)
                    {
                        if (items == null)
                        {
                            continue;
                        }

                        items[y].Min.R = r;
                        items[y].Min.G = g;
                        items[y].Min.B = b;
                        items[y].Min.A = a;

                        items[y].Max.R = r;
                        items[y].Max.G = g;
                        items[y].Max.B = b;
                        items[y].Max.A = a;
                    }
                }
            }
        }
Exemple #3
0
        private static PtxEventEmitter *GetPtfxEventEmitterByName(IntPtr ptxAssetRulePtr, string particleName)
        {
            PtxEffectRule ptxRule = Marshal.PtrToStructure <PtxEffectRule>(ptxAssetRulePtr);

            for (int i = 0; i < ptxRule.EmittersCount; i++)
            {
                PtxEventEmitter *emitter = ptxRule.Emitters[i];

                string szName = Marshal.PtrToStringAnsi(emitter->SzEmitterName);

                if (szName == particleName)
                {
                    return(emitter);
                }
            }

            return(null);
        }
        public static void SetPtfxColor(string baseAsset, string particleName, int emitterIndex, Color newColor)
        {
            if (bInitialized == false)
            {
                return;
            }

            string key = baseAsset + ':' + particleName;

            if (!ptfxRulePtrList.TryGetValue(key, out var result) &&
                !FindPtxEffectRule(GetPtfxRuleDictionary(baseAsset), particleName, out result))
            {
                return;
            }

            ptfxRulePtrList[key] = result;

            PtxEventEmitter *emitter = GetPtfxEventEmitterByIndex(result, emitterIndex);

            Debug.Assert(emitter != null);

            SetEmitterColour(emitter, newColor);
        }
 private static void SetEmitterColour(PtxEventEmitter *emitter, Color colour)
 {
     SetEmitterColour(emitter, colour.R, colour.G, colour.B, colour.A);
 }
Exemple #6
0
        private static void SetPtxParticleEmitterColour(IntPtr ptfxRule, string particleName, Color colour)
        {
            //Logger.Log(string.Format("SetPtxParticleEmitterColour() - Setting colour for emitter \"{0}\" to ({1}, {2}, {3})", particleName, colour.R, colour.G, colour.B));

            PtxEventEmitter *emitter = GetPtfxEventEmitterByName(ptfxRule, particleName);

            int behaviourHash = Game.GenerateHash("ptxu_Colour");

            for (int i = 0; i < emitter->ParticleRule->BehavioursCount; i++)
            {
                PtxBehaviour *behaviour = emitter->ParticleRule->Behaviours[i];

                if (behaviour->HashName == (uint)behaviourHash)
                {
                    for (int x = 0; x < behaviour->NumFrames - 1; x++)
                    {
                        behaviour->KeyframeProps[x]->Defaults.Vectors[0].Value[0] = (1.0f / 255) * colour.R; // r
                        behaviour->KeyframeProps[x]->Defaults.Vectors[0].Value[1] = (1.0f / 255) * colour.G; // g
                        behaviour->KeyframeProps[x]->Defaults.Vectors[0].Value[2] = (1.0f / 255) * colour.B; // b
                        behaviour->KeyframeProps[x]->Defaults.Vectors[0].Value[3] = (1.0f / 255) * colour.A; // a

                        behaviour->KeyframeProps[x]->Defaults.Vectors[1].Value[0] = (1.0f / 255) * colour.R; // r
                        behaviour->KeyframeProps[x]->Defaults.Vectors[1].Value[1] = (1.0f / 255) * colour.G; // g
                        behaviour->KeyframeProps[x]->Defaults.Vectors[1].Value[2] = (1.0f / 255) * colour.B; // b
                        behaviour->KeyframeProps[x]->Defaults.Vectors[1].Value[3] = (1.0f / 255) * colour.A; // a*/

                        if (behaviour->KeyframeProps[x]->F1 != null)
                        {
                            for (int y = 0; y < behaviour->KeyframeProps[x]->F1->Vars->UnkCount; y++)
                            {
                                behaviour->KeyframeProps[x]->F1->Vars->Vectors[y].Value[0] = (1.0f / 255) * colour.R; // r
                                behaviour->KeyframeProps[x]->F1->Vars->Vectors[y].Value[1] = (1.0f / 255) * colour.G; // g
                                behaviour->KeyframeProps[x]->F1->Vars->Vectors[y].Value[2] = (1.0f / 255) * colour.B; // b
                                behaviour->KeyframeProps[x]->F1->Vars->Vectors[y].Value[3] = (1.0f / 255) * colour.A; // a
                            }
                        }

                        if (behaviour->KeyframeProps[x]->F2 != null)
                        {
                            for (int y = 0; y < behaviour->KeyframeProps[x]->F2->Vars->UnkCount; y++)
                            {
                                behaviour->KeyframeProps[x]->F2->Vars->Vectors[y].Value[0] = (1.0f / 255) * colour.R; // r
                                behaviour->KeyframeProps[x]->F2->Vars->Vectors[y].Value[1] = (1.0f / 255) * colour.G; // g
                                behaviour->KeyframeProps[x]->F2->Vars->Vectors[y].Value[2] = (1.0f / 255) * colour.B; // b
                                behaviour->KeyframeProps[x]->F2->Vars->Vectors[y].Value[3] = (1.0f / 255) * colour.A; // a
                            }
                        }

                        if (behaviour->KeyframeProps[x]->F3 != null)
                        {
                            for (int y = 0; y < behaviour->KeyframeProps[x]->F3->Vars->UnkCount; y++)
                            {
                                behaviour->KeyframeProps[x]->F3->Vars->Vectors[y].Value[0] = (1.0f / 255) * colour.R; // r
                                behaviour->KeyframeProps[x]->F3->Vars->Vectors[y].Value[1] = (1.0f / 255) * colour.G; // g
                                behaviour->KeyframeProps[x]->F3->Vars->Vectors[y].Value[2] = (1.0f / 255) * colour.B; // b
                                behaviour->KeyframeProps[x]->F3->Vars->Vectors[y].Value[3] = (1.0f / 255) * colour.A; // a
                            }
                        }

                        if (behaviour->KeyframeProps[x]->F4 != null)
                        {
                            for (int y = 0; y < behaviour->KeyframeProps[x]->F4->Vars->UnkCount; y++)
                            {
                                behaviour->KeyframeProps[x]->F4->Vars->Vectors[y].Value[0] = (1.0f / 255) * colour.R; // r
                                behaviour->KeyframeProps[x]->F4->Vars->Vectors[y].Value[1] = (1.0f / 255) * colour.G; // g
                                behaviour->KeyframeProps[x]->F4->Vars->Vectors[y].Value[2] = (1.0f / 255) * colour.B; // b
                                behaviour->KeyframeProps[x]->F4->Vars->Vectors[y].Value[3] = (1.0f / 255) * colour.A; // a
                            }
                        }
                    }
                }
            }
        }