Пример #1
0
        // EVALUATE //
        //
        // Evaluate when particle specific data IS available.
        override public void Evaluate(ref Vector4[] input)
        {
                        #if UNITY_EDITOR
            Vector4 v;
            if (ownerBlueprint.ownerEmitter.exampleInputParticleIndex < 0)
            {
                return;
            }

            if (showCurrentStack.GetValue())
            {
                v = input[ownerBlueprint.ownerEmitter.exampleInputParticleIndex];
            }
            else
            {
                v = AmpsHelpers.GetSystemProperty(ownerBlueprint, ownerBlueprint.ownerEmitter.exampleInputParticleIndex, (AmpsHelpers.eCurveInputs)property.GetValue());
            }

            label.value = v.x.ToString("F3") + ", " +
                          v.y.ToString("F3") + ", " +
                          v.z.ToString("F3") + ", " +
                          v.w.ToString("F3");
            moduleName.value = label.value;
                        #endif
        }
Пример #2
0
        // MANAGE SAMPLING //
        //
        // Does the actual sampling.
        override public void ManageSampling(int particleIndex)
        {
            Vector3  testedPosition = Vector3.zero;
            Collider theCollider;

            // If this is the first frame of a new particle then we skip sampling and wait for the next round
            // when the position stack will have been evaluated and updated from its default (0,0,0) value.
            if (particleIndex >= 0 && ownerBlueprint.ownerEmitter.particleTimes[particleIndex] < 0.1)
            {
                return;                                                                                                         // HACK: There are misses when it's less than 0.1 for some reason.
            }
            if ((particleIndex < 0 && ShouldSample()) || (particleIndex >= 0 && ShouldSample(particleIndex)))
            {
                if (particleIndex < 0)
                {
                    testedPosition = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, AmpsHelpers.eCurveInputs.EmitterPosition);
                }
                else
                {
                    testedPosition = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, AmpsHelpers.eCurveInputs.Position);
                }

                theCollider = sampledObject.GetValue().GetComponent <Collider>();
                if (theCollider != null)
                {
                    Vector3    theRayVector    = theCollider.transform.position - testedPosition;
                    Ray        theRay          = new Ray(testedPosition, Vector3.Normalize(theRayVector));
                    RaycastHit theRaycastHit   = new RaycastHit();
                    bool       gotIntersection = theCollider.Raycast(theRay, out theRaycastHit, theRayVector.magnitude);
                    //Debug.DrawLine(theCollider.transform.position, testedPosition);

                    if (gotIntersection)
                    {
                        isInsideFlags[particleIndex] = false;
                    }
                    else
                    {
                        isInsideFlags[particleIndex] = true;
                    }
                }
            }
        }
Пример #3
0
        public int randomSeed            = 0;                           // A curve specific random seed;

        // GET CURVE INPUT //
        //
        public float GetCurveInput(AmpsBlueprint ownerBlueprint, int particleIndex)
        {
            float   returnValue = 0;
            Vector3 v3          = Vector3.zero;
            Vector4 v4          = Vector4.zero;

            //Matrix4x4 toMatrix = AmpsHelpers.identityMatrix; // Slightly faster than Matrix4x4.identity;

            v4 = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, curveInput);

            // The only need to work with conversion to emitter space as everything
            // is world relative by default.
            if (curveInputCoordSystem == AmpsHelpers.eCoordSystems.Emitter)
            {
                //toMatrix = ownerBlueprint.ownerEmitter.emitterMatrixFull;
                if (AmpsHelpers.isPositionInput(curveInput))
                {
                    v3  = AmpsHelpers.ConvertVector4Vector3(v4);
                    v3 -= ownerBlueprint.ownerEmitter.transform.position;
                    v3  = AmpsHelpers.RotateAroundPoint(v3, ownerBlueprint.ownerEmitter.emitterPosition, ownerBlueprint.ownerEmitter.transform.rotation);
                    v4  = AmpsHelpers.ConvertVector3Vector4(v3, 0);
                }
                else if (AmpsHelpers.isRotationInput(curveInput))
                {
                    v3  = AmpsHelpers.ConvertVector4Vector3(v4);
                    v3 += ownerBlueprint.ownerEmitter.transform.rotation.eulerAngles;
                    v4  = AmpsHelpers.ConvertVector3Vector4(v3, 0);
                }
                else if (AmpsHelpers.isVelocityInput(curveInput))
                {
                    v3  = AmpsHelpers.ConvertVector4Vector3(v4);
                    v3 += ownerBlueprint.ownerEmitter.emitterMatrixPositionZero.MultiplyPoint3x4(v3);
                    v4  = AmpsHelpers.ConvertVector3Vector4(v3, 0);
                }
                else if (AmpsHelpers.isScaleInput(curveInput))
                {
                    v3    = AmpsHelpers.ConvertVector4Vector3(v4);
                    v3.x *= ownerBlueprint.ownerEmitter.transform.lossyScale.x;
                    v3.y *= ownerBlueprint.ownerEmitter.transform.lossyScale.y;
                    v3.z *= ownerBlueprint.ownerEmitter.transform.lossyScale.z;
                    v4    = AmpsHelpers.ConvertVector3Vector4(v3, 0);
                }
            }

            if (AmpsHelpers.isFloatInput(curveInput))
            {
                returnValue = v4.x;
            }
            else
            {
                //if (AmpsHelpers.isPositionInput(curveInput)) v = toMatrix.MultiplyPoint3x4(v);
                //else v = toMatrix.MultiplyVector(v);

                switch (curveInputVectorComponent)
                {
                case AmpsHelpers.eVectorComponents.X:
                    returnValue = v4.x;
                    break;

                case AmpsHelpers.eVectorComponents.Y:
                    returnValue = v4.y;
                    break;

                case AmpsHelpers.eVectorComponents.Z:
                    returnValue = v4.z;
                    break;

                case AmpsHelpers.eVectorComponents.W:
                    returnValue = v4.w;
                    break;

                case AmpsHelpers.eVectorComponents.Mag:
                    returnValue = new Vector3(v4.x, v4.y, v4.z).magnitude;
                    break;
                }
                // TODO: Handle Color.
            }

            // Normalize input.
            float finalInputRangeMin = inputRangeMin;
            float finalInputRangeMax = inputRangeMax;

            if (isInputRangeRandom)
            {
                System.Random theRandom = new System.Random(ownerBlueprint.ownerEmitter.randomSeed + randomSeed + ownerBlueprint.ownerEmitter.particleIds[particleIndex]);
                finalInputRangeMin = Mathf.Lerp(inputRangeMin, inputRangeRandomMin, (float)theRandom.NextDouble());
                finalInputRangeMax = Mathf.Lerp(inputRangeMax, inputRangeRandomMax, (float)theRandom.NextDouble());
            }

            if (finalInputRangeMax - finalInputRangeMin == 0)
            {
                returnValue = 0;
            }
            else
            {
                returnValue = (returnValue - finalInputRangeMin) / (finalInputRangeMax - finalInputRangeMin);
            }

            return(returnValue);
        }
Пример #4
0
        // MANAGE EVENT //
        //
        void ManageEvent(Vector4 input, bool isInputFloat, int particleIndex)
        {
            bool    shouldTriggerEvent = false;
            Vector4 rawProperty;
            bool    isRawPropertyFloat = isInputFloat;
            float   thePropertyValue   = 0;

            if (useCurrentStack.GetValue() == false)
            {
                rawProperty        = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)property.GetValue());
                isRawPropertyFloat = AmpsHelpers.isFloatInput((AmpsHelpers.eCurveInputs)property.GetValue());
            }
            else
            {
                rawProperty = input;
            }

            if (isRawPropertyFloat)
            {
                thePropertyValue = rawProperty.x;
            }
            else
            {
                switch (propertyVectorComponent.GetValue())
                {
                case (int)AmpsHelpers.eVectorComponents.X:
                    thePropertyValue = rawProperty.x;
                    break;

                case (int)AmpsHelpers.eVectorComponents.Y:
                    thePropertyValue = rawProperty.y;
                    break;

                case (int)AmpsHelpers.eVectorComponents.Z:
                    thePropertyValue = rawProperty.z;
                    break;

                case (int)AmpsHelpers.eVectorComponents.W:
                    thePropertyValue = rawProperty.w;
                    break;

                case (int)AmpsHelpers.eVectorComponents.Mag:
                    thePropertyValue = new Vector3(rawProperty.x, rawProperty.y, rawProperty.z).magnitude;
                    break;
                }
            }

            switch (condition.GetValue())
            {
            case (int)eConditions.Greater:
                shouldTriggerEvent = thePropertyValue > value.GetValue();
                break;

            case (int)eConditions.Less:
                shouldTriggerEvent = thePropertyValue < value.GetValue();
                break;

            case (int)eConditions.Equal:
                shouldTriggerEvent = thePropertyValue == value.GetValue();
                break;

            case (int)eConditions.NotEqual:
                shouldTriggerEvent = thePropertyValue != value.GetValue();
                break;
            }

            if (shouldTriggerEvent)
            {
                AmpsEmitter[] childEmitters = ownerBlueprint.ownerEmitter.transform.GetComponentsInChildren <AmpsEmitter>();
                for (int i = 0; i < childEmitters.Length; i++)
                {
                    switch ((eActions)action.GetValue())
                    {
                    case eActions.ResetAndPlay:
                        childEmitters[i].Play();
                        break;

                    case eActions.PlayIfNotPlaying:
                        if (childEmitters[i].isStopped)
                        {
                            childEmitters[i].Play();
                        }
                        else if (childEmitters[i].isPaused)
                        {
                            childEmitters[i].Unpause();
                        }
                        break;

                    case eActions.Pause:
                        if (childEmitters[i].isPaused == false)
                        {
                            childEmitters[i].Pause();
                        }
                        break;

                    default:
                        break;
                    }
                }

                timeOfLastEvent = ownerBlueprint.ownerEmitter.emitterTime;
            }
        }
Пример #5
0
        // MANAGE EVENT //
        //
        void ManageEvent(Vector4 input, bool isInputFloat, int particleIndex)
        {
            bool    shouldTriggerEvent = false;
            Vector4 rawProperty;
            bool    isRawPropertyFloat = isInputFloat;
            float   thePropertyValue   = 0;

            if (useCurrentStack.GetValue() == false)
            {
                rawProperty        = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)property.GetValue());
                isRawPropertyFloat = AmpsHelpers.isFloatInput((AmpsHelpers.eCurveInputs)property.GetValue());
            }
            else
            {
                rawProperty = input;
            }

            if (isRawPropertyFloat)
            {
                thePropertyValue = rawProperty.x;
            }
            else
            {
                switch (propertyVectorComponent.GetValue())
                {
                case (int)AmpsHelpers.eVectorComponents.X:
                    thePropertyValue = rawProperty.x;
                    break;

                case (int)AmpsHelpers.eVectorComponents.Y:
                    thePropertyValue = rawProperty.y;
                    break;

                case (int)AmpsHelpers.eVectorComponents.Z:
                    thePropertyValue = rawProperty.z;
                    break;

                case (int)AmpsHelpers.eVectorComponents.W:
                    thePropertyValue = rawProperty.w;
                    break;

                case (int)AmpsHelpers.eVectorComponents.Mag:
                    thePropertyValue = new Vector3(rawProperty.x, rawProperty.y, rawProperty.z).magnitude;
                    break;
                }
            }

            switch (condition.GetValue())
            {
            case (int)eConditions.Greater:
                shouldTriggerEvent = thePropertyValue > value.GetValue();
                break;

            case (int)eConditions.Less:
                shouldTriggerEvent = thePropertyValue < value.GetValue();
                break;

            case (int)eConditions.Equal:
                shouldTriggerEvent = thePropertyValue == value.GetValue();
                break;

            case (int)eConditions.NotEqual:
                shouldTriggerEvent = thePropertyValue != value.GetValue();
                break;
            }

            if (shouldTriggerEvent)
            {
                EventData theEventData = new EventData();
                theEventData.eventName     = eventName.GetValue();
                theEventData.particleIndex = particleIndex;
                theEventData.DataSlot1     = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)sentProperty1.GetValue());
                theEventData.DataSlot2     = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)sentProperty2.GetValue());
                theEventData.DataSlot3     = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)sentProperty3.GetValue());
                theEventData.DataSlot4     = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, (AmpsHelpers.eCurveInputs)sentProperty4.GetValue());

                                #if UNITY_EDITOR
                AmpsEmitter[] selfAndChildEmitters = ownerBlueprint.ownerEmitter.transform.root.GetComponentsInChildren <AmpsEmitter>();
                for (int i = 0; i < selfAndChildEmitters.Length; i++)
                {
                    selfAndChildEmitters[i].AmpsHandleEvent(theEventData);
                }
                                #else
                ownerBlueprint.ownerEmitter.BroadcastMessage("AmpsHandleEvent", theEventData, SendMessageOptions.DontRequireReceiver);
                                #endif

                currentEventCount++;
                timeOfLastEvent = ownerBlueprint.ownerEmitter.emitterTime;
            }
        }
Пример #6
0
        // MANAGE SAMPLING //
        //
        // Does the actual sampling.
        override public void ManageSampling(int particleIndex)
        {
            int finalParticleIndex = (particleIndex < 0 ? 0 : particleIndex);

            AmpsHelpers.eCurveInputs wantedProperty = (AmpsHelpers.eCurveInputs)property.GetValue();
            bool isWantedPropertyParticleRelated    = AmpsHelpers.isParticleRelatedInput(wantedProperty);
            bool shouldIndeedSample = (particleIndex < 0 && ShouldSample()) || (particleIndex >= 0 && ShouldSample(particleIndex));

            if (wasParentChecked == false)
            {
                if (ownerBlueprint.ownerEmitter.transform.parent != null)
                {
                    parentEmitter = ownerBlueprint.ownerEmitter.transform.parent.GetComponent <AmpsEmitter>();
                }
                wasParentChecked = true;
            }

            if (sampleFromParent.GetValue())
            {
                // Leave if it's not time yet to sample.
                if (shouldIndeedSample == false)
                {
                    return;
                }

                // INVALID SAMPLE: Parent doesn't exist or has no emitter component or no blueprint.
                if (parentEmitter == null ||
                    parentEmitter.blueprint == null)
                {
                    isValidSample[finalParticleIndex] = false;
                    return;
                }

                // Try to get valid parent particle index.
                if (parentParticleIndices[finalParticleIndex] < 0)
                {
                    parentParticleIndices[finalParticleIndex] = parentEmitter.GetRandomParticleIndex(ownerBlueprint.ownerEmitter.particleIds[finalParticleIndex]);
                }

                // TODO: Invalid sample case: particle id at current particle index is different, ie we did lose
                // original particle index as it got replaced by another.

                // INVALID SAMPLE: Invalid parent particle index.
                //
                // TODO: We might have an invalid parent particle index but we might not need it anymore since
                // we already got a valid sample from it before and we don't need a new one for the time being.
                if (parentParticleIndices[finalParticleIndex] < 0)
                {
                    isValidSample[finalParticleIndex] = false;
                    return;
                }

                // INVALID SAMPLE: Parent particle is dead.
                if (parentParticleIndices[finalParticleIndex] >= 0 &&
                    parentEmitter.particleMarkers.IsActive(parentParticleIndices[finalParticleIndex]) == false)
                {
                    parentParticleIndices[finalParticleIndex] = -1;
                    isValidSample[finalParticleIndex]         = false;
                    return;
                }

                // INVALID SAMPLE: Asking for particle specific data but have no valid particle index.
                if (isWantedPropertyParticleRelated && parentParticleIndices[finalParticleIndex] < 0)
                {
                    return;
                }

                samples[finalParticleIndex] = AmpsHelpers.GetSystemProperty(parentEmitter.blueprint,
                                                                            parentParticleIndices[finalParticleIndex],
                                                                            wantedProperty);
                isValidSample[finalParticleIndex] = true;
            }
            else
            {
                // Leave if it's not time yet to sample.
                if (shouldIndeedSample == false)
                {
                    return;
                }

                // INVALID SAMPLE: Asking for particle specific data but have no valid particle index.
                if (isWantedPropertyParticleRelated && finalParticleIndex < 0)
                {
                    return;
                }

                samples[finalParticleIndex] = AmpsHelpers.GetSystemProperty(ownerBlueprint,
                                                                            finalParticleIndex,
                                                                            wantedProperty);
                isValidSample[finalParticleIndex] = true;
            }
        }