Beispiel #1
0
        public ParticleEntity(ParticleDefinition definition)
        {
            this.Definition = definition;
            this.Tick = 0;
            this.Width = 4;
            this.Height = 4;

            // Determine particle values.
            this.Images = this.Definition.Images;
            this.Color = this.Definition.Color;
            this.Direction = (float)Random.NextDouble() * (this.Definition.DirectionMax - this.Definition.DirectionMin) + this.Definition.DirectionMin;
            this.Speed = (float)Random.NextDouble() * (this.Definition.SpeedMax - this.Definition.SpeedMin) + this.Definition.SpeedMin;
            this.Lifetime = (float)Random.NextDouble() * (this.Definition.LifetimeMax - this.Definition.LifetimeMin) + this.Definition.LifetimeMin;
        }
Beispiel #2
0
        private object DeserializeValue(XmlReader reader, ITypeMap typeMap, IXmlTemplateNode templateNode, ParticleDefinition particleDefinition, XRoadMessage message)
        {
            if (reader.IsNilElement())
            {
                reader.ReadToEndElement();
                return(null);
            }

            XName typeAttribute;

            if (typeMap.Definition.IsAnonymous && !(typeMap is IArrayTypeMap) && (typeAttribute = reader.GetTypeAttributeValue()) != null)
            {
                throw new UnknownTypeException($"Expected anonymous type, but `{typeAttribute}` was given.", particleDefinition, typeMap.Definition, typeAttribute);
            }

            var concreteTypeMap = typeMap;

            if (!particleDefinition.Content.IgnoreExplicitType)
            {
                concreteTypeMap = (typeMap.Definition.IsInheritable ? serializer.GetTypeMapFromXsiType(reader, particleDefinition) : null) ?? typeMap;
            }

            return(concreteTypeMap.Deserialize(reader, templateNode, particleDefinition.Content, message));
        }
Beispiel #3
0
    public void Initialise()
    {
        m_particleQuads = new BatchedQuadDef[m_MaxParticles];
        m_particleDefs = new ParticleDefinition[m_MaxParticles];

        for( int p = 0; p<m_MaxParticles; p++ )
        {
            m_particleQuads[p] = null;
            m_particleDefs[p] = new ParticleDefinition();
            m_particleDefs[p].m_Active = false;
        }

        m_particlesToSpawn = 0;
        m_particleDefSearchCursor = 0;
        m_running = false;
    }
Beispiel #4
0
    void SetParticleQuad( ParticleDefinition def, BatchedQuadDef quad, float time )
    {
        float normalTime = time - def.m_StartTime;
        normalTime /= (def.m_EndTime - def.m_StartTime);

        if( normalTime < 0.0f )
        {
            def.m_Active = false;
            PrimitiveLibrary.Get.ReleaseQuadDefinition( quad );
            return;
        }

        bool releaseParticle = false;
        if( normalTime > 1.0f )
        {
            normalTime = 1.0f;
            releaseParticle = true;
        }

        float rotationTime = normalTime;
        if( m_RotationPower < 0 )
        {
            rotationTime = 1.0f - rotationTime;
            for( int p = 0; p<-m_RotationPower; p++ )
                rotationTime *= rotationTime;
            rotationTime = 1.0f - rotationTime;
        }
        else if( m_RotationPower > 0 )
        {
            for( int p = 0; p<m_RotationPower; p++ )
                rotationTime *= rotationTime;
        }
        float rotation = def.m_IntialRotation + rotationTime*def.m_RotationOverTime;

        float scaleTime = normalTime;
        if( m_ScalePower < 0 )
        {
            scaleTime = 1.0f - scaleTime;
            for( int p = 0; p<-m_ScalePower; p++ )
                scaleTime *= scaleTime;
            scaleTime = 1.0f - scaleTime;
        }
        else if( m_ScalePower > 0 )
        {
            for( int p = 0; p<m_ScalePower; p++ )
                scaleTime *= scaleTime;
        }
        float scale = def.m_InitialScale + scaleTime*def.m_ScaleOverTime;

        float colourTime = normalTime;
        if( m_ColourPower < 0 )
        {
            colourTime = 1.0f - colourTime;
            for( int p = 0; p<-m_ColourPower; p++ )
                colourTime *= colourTime;
            colourTime = 1.0f - colourTime;
        }
        else if( m_ColourPower > 0 )
        {
            for( int p = 0; p<m_ColourPower; p++ )
                colourTime *= colourTime;
        }
        Color col = m_Colour + colourTime*m_ColourOverTime;

        quad.m_Position = transform.position;
        quad.m_Rotation = rotation;
        quad.m_Scale = new Vector2( scale, scale );
        quad.m_Colour = col;

        if( releaseParticle )
        {
            def.m_Active = false;
            PrimitiveLibrary.Get.ReleaseQuadDefinition( quad );
            return;
        }
    }
 public EmptyContentDefinition(ParticleDefinition particle, string runtimeName)
     : base(particle)
 {
 }
Beispiel #6
0
        /// <summary>
        /// Create a Particle material.
        /// </summary>
        /// <param name="m"></param>
        /// <param name="textureManager"></param>
        /// <returns></returns>
        protected virtual glTFMaterial CreateParticleMaterial(Material m, TextureExportManager textureManager)
        {
            ParticleDefinition particleDefinition = UniStandardParticle.Utils.GetParticleParametersFromMaterial(m);

            var vgoParticle = new VGO_materials_particle()
            {
                renderMode               = (ParticleBlendMode)particleDefinition.RenderMode,
                colorMode                = (ParticleColorMode)particleDefinition.ColorMode,
                flipBookMode             = (ParticleFlipBookMode)particleDefinition.FlipBookMode,
                cullMode                 = particleDefinition.CullMode,
                softParticlesEnabled     = particleDefinition.SoftParticlesEnabled,
                softParticleFadeParams   = particleDefinition.SoftParticleFadeParams.ToArray(),
                cameraFadingEnabled      = particleDefinition.CameraFadingEnabled,
                cameraFadeParams         = particleDefinition.CameraFadeParams.ToArray(),
                distortionEnabled        = particleDefinition.DistortionEnabled,
                grabTextureIndex         = -1,
                distortionStrengthScaled = particleDefinition.DistortionStrengthScaled,
                distortionBlend          = particleDefinition.DistortionBlend,
                colorAddSubDiff          = particleDefinition.ColorAddSubDiff.linear.ToArray(),
                mainTexIndex             = -1,
                mainTexSt                = particleDefinition.MainTexSt.ToArray(),
                color  = particleDefinition.Color.linear.ToArray(),
                cutoff = particleDefinition.Cutoff,
                metallicGlossMapIndex = -1,
                metallic         = particleDefinition.Metallic,
                glossiness       = particleDefinition.Glossiness,
                bumpMapIndex     = -1,
                bumpScale        = particleDefinition.BumpScale,
                lightingEnabled  = particleDefinition.LightingEnabled,
                emissionEnabled  = particleDefinition.EmissionEnabled,
                emissionColor    = particleDefinition.EmissionColor.linear.ToArray(),
                emissionMapIndex = -1,
            };

            // Textures
            vgoParticle.grabTextureIndex      = textureManager.CopyAndGetIndex(particleDefinition.GrabTexture, RenderTextureReadWrite.sRGB);
            vgoParticle.mainTexIndex          = textureManager.CopyAndGetIndex(particleDefinition.MainTex, RenderTextureReadWrite.sRGB);
            vgoParticle.metallicGlossMapIndex = textureManager.CopyAndGetIndex(particleDefinition.MetallicGlossMap, RenderTextureReadWrite.sRGB);
            vgoParticle.bumpMapIndex          = textureManager.ConvertAndGetIndex(particleDefinition.BumpMap, new NormalConverter());
            vgoParticle.emissionMapIndex      = textureManager.CopyAndGetIndex(particleDefinition.EmissionMap, RenderTextureReadWrite.sRGB);

            var material = new glTFMaterial();

            material.name = m.name;

            // Alpha Mode
            switch (vgoParticle.renderMode)
            {
            case ParticleBlendMode.Opaque:
                material.alphaMode = glTFBlendMode.OPAQUE.ToString();
                break;

            case ParticleBlendMode.Cutout:
                material.alphaMode = glTFBlendMode.MASK.ToString();
                break;

            case ParticleBlendMode.Fade:
            case ParticleBlendMode.Transparent:
            case ParticleBlendMode.Additive:
            case ParticleBlendMode.Subtractive:
            case ParticleBlendMode.Modulate:
                material.alphaMode = glTFBlendMode.BLEND.ToString();
                break;

            default:
                break;
            }

            // Alpha Cutoff
            if (vgoParticle.renderMode == ParticleBlendMode.Cutout)
            {
                material.alphaCutoff = vgoParticle.cutoff;
            }

            // Double Sided
            switch (vgoParticle.cullMode)
            {
            case UnityEngine.Rendering.CullMode.Off:
                material.doubleSided = true;
                break;

            case UnityEngine.Rendering.CullMode.Front:
            case UnityEngine.Rendering.CullMode.Back:
                material.doubleSided = false;
                break;

            default:
                break;
            }

            // PBR Metallic Roughness
            {
                if (vgoParticle.color != null)
                {
                    if (material.pbrMetallicRoughness == null)
                    {
                        material.pbrMetallicRoughness = new glTFPbrMetallicRoughness();
                    }

                    material.pbrMetallicRoughness.baseColorFactor = vgoParticle.color;
                }

                if (vgoParticle.mainTexIndex != -1)
                {
                    if (material.pbrMetallicRoughness == null)
                    {
                        material.pbrMetallicRoughness = new glTFPbrMetallicRoughness();
                    }

                    material.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo()
                    {
                        index = vgoParticle.mainTexIndex,
                    };

                    //material.pbrMetallicRoughness.metallicFactor = 1.0f;
                    //material.pbrMetallicRoughness.roughnessFactor = 1.0f;
                }
            }

            // Normal Texture
            if (vgoParticle.bumpMapIndex != -1)
            {
                material.normalTexture = new glTFMaterialNormalTextureInfo()
                {
                    index = vgoParticle.bumpMapIndex,
                };
            }

            // Emissive
            if (vgoParticle.emissionEnabled)
            {
                material.emissiveFactor = vgoParticle.emissionColor;

                if (vgoParticle.emissionMapIndex != -1)
                {
                    material.emissiveTexture = new glTFMaterialEmissiveTextureInfo()
                    {
                        index = vgoParticle.emissionMapIndex,
                    };
                }
            }

            // extensions
            material.extensions = new glTFMaterial_extensions()
            {
                VGO_materials          = new VGO_materials(m.shader.name),
                VGO_materials_particle = vgoParticle,
            };

            if (m.shader.name == ShaderName.Particles_Standard_Unlit)
            {
                material.extensions.KHR_materials_unlit = new KHR_materials_unlit();
            }

            return(material);
        }