Beispiel #1
0
            public Material(FileReader reader, Header header) : base()
            {
                ParentLayout = header;

                Name              = reader.ReadString(20, true);
                TevColor          = reader.ReadColor8RGBA();
                TevConstantColors = reader.ReadColor8sRGBA(6);
                flags             = reader.ReadUInt32();

                uint texCount     = flags & 3;
                uint mtxCount     = (flags >> 2) & 3;
                uint texCoordGens = (flags >> 4) & 3;
                uint tevStages    = (flags >> 6) & 7;

                TextureMaps       = new TextureRef[texCount];
                TextureTransforms = new TextureTransform[mtxCount];

                for (int i = 0; i < texCount; i++)
                {
                    TextureMaps[i] = new TextureRef(reader, header);
                }

                for (int i = 0; i < mtxCount; i++)
                {
                    TextureTransforms[i] = new TextureTransform(reader);
                }
            }
Beispiel #2
0
 public Matrix3x4 GetTransform()
 {
     return(TextureTransform.GetTransform(
                Scale,
                Rotation,
                Translation,
                TextureTransformType.DccMaya));
 }
        /// <summary>
        ///     Draws the context, that was given to them.
        /// </summary>
        /// <param name="context"></param>
        protected virtual void DrawContext(ref DrawContext context)
        {
            context.ForcedType     = ForcedMeshType;
            context.TextureMatrix *= TextureTransform.GetMatrix();
            context.LastObject     = this;

            LastDrawingCamera = context.UseCamera;
        }
 private LocalTransform TransformTextureTransform(TextureTransform textureTransform)
 {
     if (textureTransform == null)
     {
         return(null);
     }
     return(null);
 }
Beispiel #5
0
        public override string GetStepParameters()
        {
            var parameters = new List <string>();

            parameters.Add(RepeatS != null ? RepeatS.ToStepValue() : "$");
            parameters.Add(RepeatT != null ? RepeatT.ToStepValue() : "$");
            parameters.Add(Mode != null ? Mode.ToStepValue() : "$");
            parameters.Add(TextureTransform != null ? TextureTransform.ToStepValue() : "$");
            parameters.Add(Parameter != null ? Parameter.ToStepValue() : "$");
            parameters.Add(URLReference != null ? URLReference.ToStepValue() : "$");

            return(string.Join(", ", parameters.ToArray()));
        }
        public static void AddConstrainedBillboard(this DynamicPrimitive dynamicPrimitive, Texture2D texture, Vector3 start, Vector3 end, float width, Matrix?textureTransform, Matrix?world, Color color, Vector3 cameraPosition)
        {
            //      aa --- ab
            //       |     |
            //       |     |
            //      ba --- bb
            VertexPositionColorTexture aa;
            VertexPositionColorTexture ab;
            VertexPositionColorTexture ba;
            VertexPositionColorTexture bb;

            CreateBillboard(start, end, width, cameraPosition, out aa.Position, out ab.Position,
                            out ba.Position, out bb.Position);

            if (textureTransform != null)
            {
                aa.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.One);
                ab.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.UnitX);
                ba.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.UnitY);
                bb.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.Zero);
            }
            else
            {
                aa.TextureCoordinate = Vector2.One;
                ab.TextureCoordinate = Vector2.UnitX;
                ba.TextureCoordinate = Vector2.UnitY;
                bb.TextureCoordinate = Vector2.Zero;
            }

            aa.Color     = ab.Color =
                ba.Color = bb.Color = color;

            dynamicPrimitive.BeginPrimitive(PrimitiveType.TriangleList, texture, world);
            {
                // Add new vertices and indices
                dynamicPrimitive.AddIndex((ushort)(0));
                dynamicPrimitive.AddIndex((ushort)(1));
                dynamicPrimitive.AddIndex((ushort)(2));
                dynamicPrimitive.AddIndex((ushort)(1));
                dynamicPrimitive.AddIndex((ushort)(3));
                dynamicPrimitive.AddIndex((ushort)(2));

                dynamicPrimitive.AddVertex(ref aa);
                dynamicPrimitive.AddVertex(ref ab);
                dynamicPrimitive.AddVertex(ref ba);
                dynamicPrimitive.AddVertex(ref bb);
            }
            dynamicPrimitive.EndPrimitive();
        }
Beispiel #7
0
        void Execute()
        {
            if (Unity == null || Gltf == null)
            {
                return;
            }

            Unity.SetTextureScale(PROP_NAME, Scale);
            Unity.SetTextureOffset(PROP_NAME, Offset);

            var(s, o) = TextureTransform.VerticalFlipScaleOffset(Scale, Offset);

            Gltf.SetTextureScale(PROP_NAME, s);
            Gltf.SetTextureOffset(PROP_NAME, o);
        }
Beispiel #8
0
        public override string GetStepParameters()
        {
            var parameters = new List <string>();

            parameters.Add(RepeatS != null ? RepeatS.ToStepValue() : "$");
            parameters.Add(RepeatT != null ? RepeatT.ToStepValue() : "$");
            parameters.Add(Mode != null ? Mode.ToStepValue() : "$");
            parameters.Add(TextureTransform != null ? TextureTransform.ToStepValue() : "$");
            parameters.Add(Parameter != null ? Parameter.ToStepValue() : "$");
            parameters.Add(Width != null ? Width.ToStepValue() : "$");
            parameters.Add(Height != null ? Height.ToStepValue() : "$");
            parameters.Add(ColourComponents != null ? ColourComponents.ToStepValue() : "$");
            parameters.Add(Pixel != null ? Pixel.ToStepValue() : "$");

            return(string.Join(", ", parameters.ToArray()));
        }
Beispiel #9
0
        /// <summary>
        ///	    Creates a very flexible time-based texture transformation which can alter the scale, position or
        ///	    rotation of a texture based on a wave function.
        /// </summary>
        /// <param name="layer">The texture unit to effect.</param>
        /// <param name="type">The type of transform, either translate (scroll), scale (stretch) or rotate (spin).</param>
        /// <param name="waveType">The shape of the wave, see WaveformType enum for details.</param>
        /// <param name="baseVal">The base value of the output.</param>
        /// <param name="frequency">The speed of the wave in cycles per second.</param>
        /// <param name="phase">The offset of the start of the wave, e.g. 0.5 to start half-way through the wave.</param>
        /// <param name="amplitude">Scales the output so that instead of lying within 0..1 it lies within 0..(1 * amplitude) for exaggerated effects</param>
        /// <returns>A newly created controller object that will be updated during the main render loop.</returns>
        public Controller <Real> CreateTextureWaveTransformer(TextureUnitState layer, TextureTransform type,
                                                              WaveformType waveType, Real baseVal, Real frequency, Real phase,
                                                              Real amplitude)
        {
            IControllerValue <Real>    val      = null;
            IControllerFunction <Real> function = null;

            // determine which type of controller value this layer needs
            switch (type)
            {
            case TextureTransform.TranslateU:
                val = new TexCoordModifierControllerValue(layer, true, false);
                break;

            case TextureTransform.TranslateV:
                val = new TexCoordModifierControllerValue(layer, false, true);
                break;

            case TextureTransform.ScaleU:
                val = new TexCoordModifierControllerValue(layer, false, false, true, false, false);
                break;

            case TextureTransform.ScaleV:
                val = new TexCoordModifierControllerValue(layer, false, false, false, true, false);
                break;

            case TextureTransform.Rotate:
                val = new TexCoordModifierControllerValue(layer, false, false, false, false, true);
                break;
            }             // switch

            // create a new waveform controller function
            function = new WaveformControllerFunction(waveType, baseVal, frequency, phase, amplitude, true);

            // finally, create the controller using frame time as the source value
            return(CreateController(this.frameTimeController, val, function));
        }
        public static void AddConstrainedBillboard(this DynamicPrimitive dynamicPrimitive, Texture2D texture, IEnumerable <Vector3> lineStrip, float width, Matrix?textureTransform, Matrix?world, Color color, Vector3 cameraPosition)
        {
            if (lineStrip == null)
            {
                throw new ArgumentNullException("lineStrip");
            }


            //      aa --- ab
            //       |     |
            //       |     |
            //      ba --- bb
            VertexPositionColorTexture aa;
            VertexPositionColorTexture ab;
            VertexPositionColorTexture ba;
            VertexPositionColorTexture bb;

            aa.Color     = ab.Color =
                ba.Color = bb.Color = color;

            aa.Position     = ab.Position =
                ba.Position = bb.Position = Vector3.Zero;


            // We want the texture to uniformly distribute on the line
            // even if each line segment may have different length.
            int   i           = 0;
            float totalLength = 0;
            float percentage  = 0;

            IEnumerator <Vector3> enumerator = lineStrip.GetEnumerator();

            enumerator.Reset();
            enumerator.MoveNext();
            Vector3 previous = enumerator.Current;

            while (enumerator.MoveNext())
            {
                totalLength += Vector3.Subtract(enumerator.Current, previous).Length();
                previous     = enumerator.Current;
            }

            dynamicPrimitive.BeginPrimitive(PrimitiveType.TriangleList, texture, world);
            {
                enumerator.Reset();
                enumerator.MoveNext();

                int     vertexCount  = 0;
                Vector3 start        = enumerator.Current;
                Vector3 lastSegment1 = Vector3.Zero;
                Vector3 lastSegment2 = Vector3.Zero;

                while (enumerator.MoveNext())
                {
                    CreateBillboard(start, enumerator.Current, width, cameraPosition, out aa.Position, out ab.Position,
                                    out ba.Position, out bb.Position);

                    if (textureTransform != null)
                    {
                        ba.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, new Vector2(percentage, 1));
                        bb.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, new Vector2(percentage, 0));
                    }
                    else
                    {
                        ba.TextureCoordinate = new Vector2(percentage, 1);
                        bb.TextureCoordinate = new Vector2(percentage, 0);
                    }

                    percentage += Vector3.Subtract(enumerator.Current, start).Length() / totalLength;

                    if (i > 1)
                    {
                        // Connect adjacent segments
                        ba.Position = (ba.Position + lastSegment1) / 2;
                        bb.Position = (bb.Position + lastSegment2) / 2;

                        // Adjust the connection points to the specified width
                        Vector3 append = Vector3.Subtract(bb.Position, ba.Position);

                        append.Normalize();
                        append *= width / 2;

                        ba.Position = start - append;
                        bb.Position = start + append;
                    }

                    lastSegment1 = aa.Position;
                    lastSegment2 = ab.Position;

                    int startIndex = vertexCount;

                    dynamicPrimitive.AddIndex((ushort)(startIndex + 0));
                    dynamicPrimitive.AddIndex((ushort)(startIndex + 3));
                    dynamicPrimitive.AddIndex((ushort)(startIndex + 1));
                    dynamicPrimitive.AddIndex((ushort)(startIndex + 0));
                    dynamicPrimitive.AddIndex((ushort)(startIndex + 2));
                    dynamicPrimitive.AddIndex((ushort)(startIndex + 3));

                    dynamicPrimitive.AddVertex(ref ba);
                    dynamicPrimitive.AddVertex(ref bb);

                    vertexCount += 2;

                    i++;

                    start = enumerator.Current;
                }

                // Last segment
                if (textureTransform != null)
                {
                    aa.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.One);
                    ab.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.UnitX);
                }
                else
                {
                    aa.TextureCoordinate = Vector2.One;
                    ab.TextureCoordinate = Vector2.UnitX;
                }

                dynamicPrimitive.AddVertex(ref aa);
                dynamicPrimitive.AddVertex(ref ab);
            }
            dynamicPrimitive.EndPrimitive();
        }
        public static void AddBillboard(this DynamicPrimitive dynamicPrimitive, Texture2D texture, ref Vector3 position, float width, float height, float rotation, Matrix?textureTransform, Matrix?world, Color color, ref Matrix viewInverse)
        {
            // http://www.flipcode.com/archives/Really_Fast_Billboarding_Alignment_Without_VP_Tricks.shtml

            //      aa --- ab
            //       |     |
            //       |     |
            //      ba --- bb
            VertexPositionColorTexture aa;
            VertexPositionColorTexture ab;
            VertexPositionColorTexture ba;
            VertexPositionColorTexture bb;

#if XBOX || WINDOWS_PHONE
            aa.Position = new Vector3();
            ab.Position = new Vector3();
            ba.Position = new Vector3();
            bb.Position = new Vector3();
#endif

            aa.Position.X = +width * 0.5f; aa.Position.Y = +height * 0.5f; aa.Position.Z = 0;
            ab.Position.X = -width * 0.5f; ab.Position.Y = +height * 0.5f; ab.Position.Z = 0;
            ba.Position.X = +width * 0.5f; ba.Position.Y = -height * 0.5f; ba.Position.Z = 0;
            bb.Position.X = -width * 0.5f; bb.Position.Y = -height * 0.5f; bb.Position.Z = 0;

            if (Math.Abs(rotation) > 1E-6F)
            {
                float x, y;
                float cos = (float)Math.Cos(rotation);
                float sin = (float)Math.Sin(rotation);

                x             = aa.Position.X; y = aa.Position.Y;
                aa.Position.X = x * cos + y * sin;
                aa.Position.Y = y * cos - x * sin;

                x             = ab.Position.X; y = ab.Position.Y;
                ab.Position.X = x * cos + y * sin;
                ab.Position.Y = y * cos - x * sin;

                x             = ba.Position.X; y = ba.Position.Y;
                ba.Position.X = x * cos + y * sin;
                ba.Position.Y = y * cos - x * sin;

                x             = bb.Position.X; y = bb.Position.Y;
                bb.Position.X = x * cos + y * sin;
                bb.Position.Y = y * cos - x * sin;
            }

            Vector3.TransformNormal(ref aa.Position, ref viewInverse, out aa.Position);
            Vector3.TransformNormal(ref ab.Position, ref viewInverse, out ab.Position);
            Vector3.TransformNormal(ref ba.Position, ref viewInverse, out ba.Position);
            Vector3.TransformNormal(ref bb.Position, ref viewInverse, out bb.Position);

            aa.Position += position;
            ab.Position += position;
            ba.Position += position;
            bb.Position += position;

            if (textureTransform != null)
            {
                aa.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.Zero);
                ab.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.UnitX);
                ba.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.UnitY);
                bb.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.One);
            }
            else
            {
                aa.TextureCoordinate = Vector2.Zero;
                ab.TextureCoordinate = Vector2.UnitX;
                ba.TextureCoordinate = Vector2.UnitY;
                bb.TextureCoordinate = Vector2.One;
            }

            aa.Color     = ab.Color =
                ba.Color = bb.Color = color;

            dynamicPrimitive.BeginPrimitive(PrimitiveType.TriangleList, texture, world);
            {
                // Add new vertices and indices
                dynamicPrimitive.AddIndex((ushort)(0));
                dynamicPrimitive.AddIndex((ushort)(2));
                dynamicPrimitive.AddIndex((ushort)(1));
                dynamicPrimitive.AddIndex((ushort)(1));
                dynamicPrimitive.AddIndex((ushort)(2));
                dynamicPrimitive.AddIndex((ushort)(3));

                dynamicPrimitive.AddVertex(ref aa);
                dynamicPrimitive.AddVertex(ref ab);
                dynamicPrimitive.AddVertex(ref ba);
                dynamicPrimitive.AddVertex(ref bb);
            }
            dynamicPrimitive.EndPrimitive();
        }
        public static void AddBillboard(this DynamicPrimitive dynamicPrimitive, Texture2D texture, ref Vector3 position, float width, float height, float rotation, Matrix?textureTransform, Matrix?world, Color color, ref Vector3 cameraPosition)
        {
            //      aa --- ab
            //       |     |
            //       |     |
            //      ba --- bb
            VertexPositionColorTexture aa;
            VertexPositionColorTexture ab;
            VertexPositionColorTexture ba;
            VertexPositionColorTexture bb;

            Vector3 up        = Vector3.Up;
            Matrix  transform = new Matrix();

            if (rotation != 0)
            {
                Matrix billboard = new Matrix();
                Matrix.CreateRotationZ(rotation, out transform);
                Matrix.CreateBillboard(ref position, ref cameraPosition, ref up, null, out billboard);
                Matrix.Multiply(ref transform, ref billboard, out transform);
            }
            else
            {
                Matrix.CreateBillboard(ref position, ref cameraPosition, ref up, null, out transform);
            }

            if (float.IsNaN(transform.M11))
            {
                transform     = Matrix.Identity;
                transform.M11 = -1;
            }

            transform.M41 = position.X;
            transform.M42 = position.Y;
            transform.M43 = position.Z;

#if XBOX || WINDOWS_PHONE
            aa.Position = new Vector3();
            ab.Position = new Vector3();
            ba.Position = new Vector3();
            bb.Position = new Vector3();
#endif
            aa.Position.X = +width * 0.5f; aa.Position.Y = +height * 0.5f; aa.Position.Z = 0;
            ab.Position.X = -width * 0.5f; ab.Position.Y = +height * 0.5f; ab.Position.Z = 0;
            ba.Position.X = +width * 0.5f; ba.Position.Y = -height * 0.5f; ba.Position.Z = 0;
            bb.Position.X = -width * 0.5f; bb.Position.Y = -height * 0.5f; bb.Position.Z = 0;

            Vector3.Transform(ref aa.Position, ref transform, out aa.Position);
            Vector3.Transform(ref ab.Position, ref transform, out ab.Position);
            Vector3.Transform(ref ba.Position, ref transform, out ba.Position);
            Vector3.Transform(ref bb.Position, ref transform, out bb.Position);

            if (textureTransform != null)
            {
                aa.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.Zero);
                ab.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.UnitX);
                ba.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.UnitY);
                bb.TextureCoordinate = TextureTransform.Transform(textureTransform.Value, Vector2.One);
            }
            else
            {
                aa.TextureCoordinate = Vector2.Zero;
                ab.TextureCoordinate = Vector2.UnitX;
                ba.TextureCoordinate = Vector2.UnitY;
                bb.TextureCoordinate = Vector2.One;
            }

            aa.Color     = ab.Color =
                ba.Color = bb.Color = color;

            dynamicPrimitive.BeginPrimitive(PrimitiveType.TriangleList, texture, world);
            {
                // Add new vertices and indices
                dynamicPrimitive.AddIndex((ushort)(0));
                dynamicPrimitive.AddIndex((ushort)(1));
                dynamicPrimitive.AddIndex((ushort)(2));
                dynamicPrimitive.AddIndex((ushort)(1));
                dynamicPrimitive.AddIndex((ushort)(3));
                dynamicPrimitive.AddIndex((ushort)(2));

                dynamicPrimitive.AddVertex(ref aa);
                dynamicPrimitive.AddVertex(ref ab);
                dynamicPrimitive.AddVertex(ref ba);
                dynamicPrimitive.AddVertex(ref bb);
            }
            dynamicPrimitive.EndPrimitive();
        }
		/// <summary>
		///	    Creates a very flexible time-based texture transformation which can alter the scale, position or
		///	    rotation of a texture based on a wave function.	
		/// </summary>
		/// <param name="layer">The texture unit to effect.</param>
		/// <param name="type">The type of transform, either translate (scroll), scale (stretch) or rotate (spin).</param>
		/// <param name="waveType">The shape of the wave, see WaveformType enum for details.</param>
		/// <param name="baseVal">The base value of the output.</param>
		/// <param name="frequency">The speed of the wave in cycles per second.</param>
		/// <param name="phase">The offset of the start of the wave, e.g. 0.5 to start half-way through the wave.</param>
		/// <param name="amplitude">Scales the output so that instead of lying within 0..1 it lies within 0..(1 * amplitude) for exaggerated effects</param>
		/// <returns>A newly created controller object that will be updated during the main render loop.</returns>
		public Controller<Real> CreateTextureWaveTransformer( TextureUnitState layer, TextureTransform type,
		                                                      WaveformType waveType, Real baseVal, Real frequency, Real phase,
		                                                      Real amplitude )
		{
			IControllerValue<Real> val = null;
			IControllerFunction<Real> function = null;

			// determine which type of controller value this layer needs
			switch ( type )
			{
				case TextureTransform.TranslateU:
					val = new TexCoordModifierControllerValue( layer, true, false );
					break;

				case TextureTransform.TranslateV:
					val = new TexCoordModifierControllerValue( layer, false, true );
					break;

				case TextureTransform.ScaleU:
					val = new TexCoordModifierControllerValue( layer, false, false, true, false, false );
					break;

				case TextureTransform.ScaleV:
					val = new TexCoordModifierControllerValue( layer, false, false, false, true, false );
					break;

				case TextureTransform.Rotate:
					val = new TexCoordModifierControllerValue( layer, false, false, false, false, true );
					break;
			} // switch

			// create a new waveform controller function
			function = new WaveformControllerFunction( waveType, baseVal, frequency, phase, amplitude, true );

			// finally, create the controller using frame time as the source value
			return CreateController( this.frameTimeController, val, function );
		}
Beispiel #14
0
 public Result SetTextureStageState(int stage, TextureStage type, TextureTransform textureTransform)
 {
     return(_device.SetTextureStageState(stage, type, textureTransform));
 }
Beispiel #15
0
		/// <summary>
		///    Sets up a general time-relative texture modification effect.
		/// </summary>
		/// <remarks>
		///    This can be called multiple times for different values of <paramref name="transType"/>, but only the latest effect
		///    applies if called multiple time for the same <paramref name="transType"/>.
		///    <p/>
		///    This option has no effect in the programmable pipeline.
		/// </remarks>
		/// <param name="transType">The type of transform, either translate (scroll), scale (stretch) or rotate (spin).</param>
		/// <param name="waveType">The shape of the wave, see <see cref="WaveformType"/> enum for details</param>
		/// <param name="baseVal">The base value for the function (range of output = {base, base + amplitude}).</param>
		/// <param name="frequency">The speed of the wave in cycles per second.</param>
		/// <param name="phase">The offset of the start of the wave, e.g. 0.5 to start half-way through the wave.</param>
		/// <param name="amplitude">Scales the output so that instead of lying within [0..1] it lies within [0..(1 * amplitude)] for exaggerated effects.</param>
		public void SetTransformAnimation( TextureTransform transType, WaveformType waveType, float baseVal, float frequency,
		                                   float phase, float amplitude )
		{
			var effect = new TextureEffect();
			effect.type = TextureEffectType.Transform;
			effect.subtype = transType;
			effect.waveType = waveType;
			effect.baseVal = baseVal;
			effect.frequency = frequency;
			effect.phase = phase;
			effect.amplitude = amplitude;

			AddEffect( effect );
		}
Beispiel #16
0
 public Material()
 {
     TextureMaps       = new TextureRef[0];
     TextureTransforms = new TextureTransform[0];
 }