/**
  *	Copy values array to another splatweight.  This function doesn't check
  *	that attribute layouts are matching; musht do this yourself.
  */
 public void CopyTo(z_SplatWeight other)
 {
     for (int i = 0; i < values.Length; i++)
     {
         other.values[i] = this.values[i];
     }
 }
 public void Lerp(z_SplatWeight lhs, z_SplatWeight rhs, float alpha, List <int> mask)
 {
     // optimize for some common values
     // unrolling the loop in these smaller cases can improve performances by ~33%
     if (mask.Count == 4)
     {
         values[mask[0]] = Mathf.LerpUnclamped(lhs.values[mask[0]], rhs.values[mask[0]], alpha);
         values[mask[1]] = Mathf.LerpUnclamped(lhs.values[mask[1]], rhs.values[mask[1]], alpha);
         values[mask[2]] = Mathf.LerpUnclamped(lhs.values[mask[2]], rhs.values[mask[2]], alpha);
         values[mask[3]] = Mathf.LerpUnclamped(lhs.values[mask[3]], rhs.values[mask[3]], alpha);
     }
     else if (mask.Count == 8)
     {
         values[mask[0]] = Mathf.LerpUnclamped(lhs.values[mask[0]], rhs.values[mask[0]], alpha);
         values[mask[1]] = Mathf.LerpUnclamped(lhs.values[mask[1]], rhs.values[mask[1]], alpha);
         values[mask[2]] = Mathf.LerpUnclamped(lhs.values[mask[2]], rhs.values[mask[2]], alpha);
         values[mask[3]] = Mathf.LerpUnclamped(lhs.values[mask[3]], rhs.values[mask[3]], alpha);
         values[mask[4]] = Mathf.LerpUnclamped(lhs.values[mask[4]], rhs.values[mask[4]], alpha);
         values[mask[5]] = Mathf.LerpUnclamped(lhs.values[mask[5]], rhs.values[mask[5]], alpha);
         values[mask[6]] = Mathf.LerpUnclamped(lhs.values[mask[6]], rhs.values[mask[6]], alpha);
         values[mask[7]] = Mathf.LerpUnclamped(lhs.values[mask[7]], rhs.values[mask[7]], alpha);
     }
     else
     {
         for (int i = 0; i < mask.Count; i++)
         {
             values[mask[i]] = Mathf.LerpUnclamped(lhs.values[mask[i]], rhs.values[mask[i]], alpha);
         }
     }
 }
Exemple #3
0
 public void LerpWeights(z_SplatSet lhs, z_SplatWeight rhs, float alpha)
 {
     for (int i = 0; i < weightCount; i++)
     {
         foreach (var cm in channelMap)
         {
             this.weights[cm.Value][i] = Vector4.LerpUnclamped(lhs.weights[cm.Value][i], rhs[cm.Key], alpha);
         }
     }
 }
		public static z_SplatWeight Lerp(z_SplatWeight lhs, z_SplatWeight rhs, float alpha)//, z_SplatWeight target)
		{
			int len = System.Math.Min(lhs.Length, rhs.Length);

			byte[] lerped = new byte[len];

			for(int i = 0; i < len; i++)
				lerped[i] = (byte) (lhs.components[i] * (1f-alpha) + rhs.components[i] * alpha);

			return new z_SplatWeight(lerped);
		}
Exemple #5
0
        private void RebuildColorTargets(z_SplatWeight blend, float strength)
        {
            if (blend == null || splat_cache == null || splat_target == null)
            {
                return;
            }

            minWeights = splat_target.GetMinWeights();

            splat_target.LerpWeights(splat_cache, blend, strength);
            splat_erase.LerpWeights(splat_cache, minWeights, strength);
        }
Exemple #6
0
        public z_SplatWeight GetMaxWeights()
        {
            z_SplatWeight max = new z_SplatWeight(channelMap);

            foreach (z_AttributeLayout al in attributeLayout)
            {
                Vector4 v = max[al.channel];
                v[(int)al.index] = al.max;
                max[al.channel]  = v;
            }

            return(max);
        }
Exemple #7
0
        public z_SplatWeight GetMinWeights()
        {
            z_SplatWeight min = new z_SplatWeight(channelMap);

            foreach (z_AttributeLayout al in attributeLayout)
            {
                Vector4 v = min[al.channel];
                v[(int)al.index] = al.min;
                min[al.channel]  = v;
            }

            return(min);
        }
        /**
         *	Deep copy constructor.
         */
        public z_SplatWeight(z_SplatWeight rhs)
        {
            this.map = new Dictionary <z_MeshChannel, int>();

            foreach (var kvp in rhs.map)
            {
                this.map.Add(kvp.Key, kvp.Value);
            }

            int len = rhs.values.Length;

            this.values = new float[len];
            System.Array.Copy(rhs.values, this.values, len);
        }
Exemple #9
0
        /**
         *	Editor for blend.  Returns true if blend has been modified.
         */
        public static int OnInspectorGUI(int index, ref z_SplatWeight blend, z_AttributeLayout[] attribs)
        {
            // if(blend == null && attribs != null)
            //  blend = new z_SplatWeight( z_SplatWeight.GetChannelMap(attribs) );

            // bool mismatchedOrNullAttributes = blend == null || !blend.MatchesAttributes(attribs);

            Rect r    = GUILayoutUtility.GetLastRect();
            int  yPos = (int)Mathf.Ceil(r.y + r.height);

            index = z_GUILayout.ChannelField(index, attribs, thumbSize, yPos);

            return(index);
        }
        public void Lerp(z_SplatWeight lhs, z_SplatWeight rhs, float alpha)
        {
            int len = values.Length;

            if (len == 4)
            {
                values[0] = Mathf.LerpUnclamped(lhs.values[0], rhs.values[0], alpha);
                values[1] = Mathf.LerpUnclamped(lhs.values[1], rhs.values[1], alpha);
                values[2] = Mathf.LerpUnclamped(lhs.values[2], rhs.values[2], alpha);
                values[3] = Mathf.LerpUnclamped(lhs.values[3], rhs.values[3], alpha);
            }
            else if (len == 8)
            {
                values[0] = Mathf.LerpUnclamped(lhs.values[0], rhs.values[0], alpha);
                values[1] = Mathf.LerpUnclamped(lhs.values[1], rhs.values[1], alpha);
                values[2] = Mathf.LerpUnclamped(lhs.values[2], rhs.values[2], alpha);
                values[3] = Mathf.LerpUnclamped(lhs.values[3], rhs.values[3], alpha);
                values[4] = Mathf.LerpUnclamped(lhs.values[4], rhs.values[4], alpha);
                values[5] = Mathf.LerpUnclamped(lhs.values[5], rhs.values[5], alpha);
                values[6] = Mathf.LerpUnclamped(lhs.values[6], rhs.values[6], alpha);
                values[7] = Mathf.LerpUnclamped(lhs.values[7], rhs.values[7], alpha);
            }
            else if (len == 16)
            {
                values[0]  = Mathf.LerpUnclamped(lhs.values[0], rhs.values[0], alpha);
                values[1]  = Mathf.LerpUnclamped(lhs.values[1], rhs.values[1], alpha);
                values[2]  = Mathf.LerpUnclamped(lhs.values[2], rhs.values[2], alpha);
                values[3]  = Mathf.LerpUnclamped(lhs.values[3], rhs.values[3], alpha);
                values[4]  = Mathf.LerpUnclamped(lhs.values[4], rhs.values[4], alpha);
                values[5]  = Mathf.LerpUnclamped(lhs.values[5], rhs.values[5], alpha);
                values[6]  = Mathf.LerpUnclamped(lhs.values[6], rhs.values[6], alpha);
                values[7]  = Mathf.LerpUnclamped(lhs.values[7], rhs.values[7], alpha);
                values[8]  = Mathf.LerpUnclamped(lhs.values[8], rhs.values[8], alpha);
                values[9]  = Mathf.LerpUnclamped(lhs.values[9], rhs.values[9], alpha);
                values[10] = Mathf.LerpUnclamped(lhs.values[10], rhs.values[10], alpha);
                values[11] = Mathf.LerpUnclamped(lhs.values[11], rhs.values[11], alpha);
                values[12] = Mathf.LerpUnclamped(lhs.values[12], rhs.values[12], alpha);
                values[13] = Mathf.LerpUnclamped(lhs.values[13], rhs.values[13], alpha);
                values[14] = Mathf.LerpUnclamped(lhs.values[14], rhs.values[14], alpha);
                values[15] = Mathf.LerpUnclamped(lhs.values[15], rhs.values[15], alpha);
            }
            else
            {
                for (int i = 0; i < lhs.values.Length; i++)
                {
                    values[i] = Mathf.LerpUnclamped(lhs.values[i], rhs.values[i], alpha);
                }
            }
        }
		public static z_SplatWeight OnInspectorGUI(z_SplatWeight blend, Texture2D[] textures)
		{
			byte[] bytes = blend.components;

			if(bytes == null)
			{
				bytes = new byte[z_SplatWeight.MAX_TEXTURE_COMPONENTS];
				bytes[0] = 255;
				return new z_SplatWeight(bytes);
			}

			Texture2D[] channel_textures;

			// if textures array is longer than the number of channels available, truncate it.
			// if the opposite is true, do not care.
			if(textures == null)
			{
				channel_textures = z_Util.Fill<Texture2D>((Texture2D)null, bytes.Length);
			}
			else if(textures.Length > bytes.Length)
			{
				channel_textures = new Texture2D[bytes.Length];
				System.Array.Copy(textures, 0, channel_textures, 0, bytes.Length);
			}
			else
			{
				channel_textures = textures;
			}

			int index = System.Array.FindIndex(bytes, x => x > 0);

			EditorGUI.BeginChangeCheck();

			index = z_GUI.ChannelField(index, channel_textures, thumbSize);

			if(EditorGUI.EndChangeCheck())
			{
				for(int i = 0; i < bytes.Length; i++)
					bytes[i] = 0;
				bytes[index] = 255;
				return new z_SplatWeight(bytes);
			}
			else
			{
				return blend;
			}
		}
Exemple #12
0
        // Called when the mouse begins hovering an editable object.
        public override void OnBrushEnter(z_EditableObject target, z_BrushSettings settings)
        {
            base.OnBrushEnter(target, settings);

            if (target.editMesh == null)
            {
                return;
            }

            likelySupportsTextureBlending = CheckForTextureBlendSupport(target.gameObject);

            if (likelySupportsTextureBlending && (brushColor == null || !brushColor.MatchesAttributes(meshAttributes)))
            {
                brushColor = new z_SplatWeight(z_SplatWeight.GetChannelMap(meshAttributes));
                SetBrushColorWithAttributeIndex(z_Math.Clamp(selectedAttributeIndex, 0, meshAttributes.Length - 1));
            }

            RebuildCaches(target.editMesh, settings.strength);
            RebuildColorTargets(brushColor, settings.strength);
        }
Exemple #13
0
        public override void OnEnable()
        {
            base.OnEnable();

            modeIcons[0].image = z_IconUtility.GetIcon("Icon/Brush");
            modeIcons[1].image = z_IconUtility.GetIcon("Icon/Roller");

            likelySupportsTextureBlending = false;
            meshAttributesContainer       = null;
            brushColor = null;

            foreach (GameObject go in Selection.gameObjects)
            {
                likelySupportsTextureBlending = CheckForTextureBlendSupport(go);

                if (likelySupportsTextureBlending)
                {
                    break;
                }
            }
        }
		/// Inspector GUI shown in the Editor window.  Base class shows z_BrushSettings by default
		public override void DrawGUI(z_BrushSettings brushSettings)
		{
			base.DrawGUI(brushSettings);

			GUILayout.Label("Paint Settings", z_GUI.headerTextStyle);

			GUILayout.BeginHorizontal();
			GUILayout.FlexibleSpace();
			paintMode = (z_PaintMode) GUILayout.Toolbar( (int) paintMode, modeIcons, "Command", null);
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();

			GUILayout.Space(4);

			// GUILayout.Label( brushColor.ToString() );
			// GUILayout.Label( meshAttributes.ToString("\n"));
			// GUILayout.Space(4);
			
			if(!likelySupportsTextureBlending)
				EditorGUILayout.HelpBox("It doesn't look like any of the materials on this object support texture blending!\n\nSee the readme for information on creating custom texture blend shaders.", MessageType.Warning);
			else
				brushColor = z_SplatWeightEditor.OnInspectorGUI(brushColor, textures);

		}
		private void RebuildColorTargets(z_SplatWeight blend, float strength)
		{
			if( colors_cache == null ||
				target_colors == null ||
				colors_cache.Length != target_colors.Length)
				return;

			for(int i = 0; i < colors_cache.Length; i++)
			{
				target_colors[i] = z_SplatWeight.Lerp(colors_cache[i], blend, strength);
				erase_colors[i] = z_SplatWeight.Lerp(colors_cache[i], z_SplatWeight.Channel0, strength);
			}
		}