/** * Copy constructor. */ public z_SplatSet(z_SplatSet other) { int attribCount = other.attributeCount; this.attributeLayout = new z_AttributeLayout[attribCount]; System.Array.Copy(other.attributeLayout, 0, this.attributeLayout, 0, attribCount); this.channelMap = new Dictionary <z_MeshChannel, int>(); foreach (var kvp in other.channelMap) { this.channelMap.Add(kvp.Key, kvp.Value); } int channelCount = other.channelMap.Count; this.weightCount = other.weightCount; this.weights = new Vector4[channelCount][]; for (int i = 0; i < channelCount; i++) { this.weights[i] = new Vector4[weightCount]; System.Array.Copy(other.weights[i], this.weights[i], weightCount); } }
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 void CopyTo(z_SplatSet other) { if (other.weightCount != weightCount) { Debug.LogError("Copying splat set to mis-matched container length"); return; } for (int i = 0; i < channelMap.Count; i++) { System.Array.Copy(this.weights[i], other.weights[i], weightCount); } }
/** * Lerp each attribute value with matching `mask` to `rhs`. * weights, lhs, and rhs must have matching layout attributes. */ public void LerpWeights(z_SplatSet lhs, z_SplatSet rhs, int mask, float[] alpha) { Dictionary <int, uint> affected = new Dictionary <int, uint>(); foreach (z_AttributeLayout al in attributeLayout) { int mapIndex = channelMap[al.channel]; if (al.mask == mask) { if (!affected.ContainsKey(mapIndex)) { affected.Add(mapIndex, al.index.ToFlag()); } else { affected[mapIndex] |= al.index.ToFlag(); } } } foreach (var v in affected) { Vector4[] a = lhs.weights[v.Key]; Vector4[] b = rhs.weights[v.Key]; Vector4[] c = weights[v.Key]; for (int i = 0; i < weightCount; i++) { if ((v.Value & 1) != 0) { c[i].x = Mathf.Lerp(a[i].x, b[i].x, alpha[i]); } if ((v.Value & 2) != 0) { c[i].y = Mathf.Lerp(a[i].y, b[i].y, alpha[i]); } if ((v.Value & 4) != 0) { c[i].z = Mathf.Lerp(a[i].z, b[i].z, alpha[i]); } if ((v.Value & 8) != 0) { c[i].w = Mathf.Lerp(a[i].w, b[i].w, alpha[i]); } } } }
private void RebuildCaches(z_Mesh m, float strength) { vertexCount = m.vertexCount; triangleLookup = z_MeshUtility.GetAdjacentTriangles(m); if (meshAttributes == null) { // clear caches splat_cache = null; splat_current = null; splat_target = null; splat_erase = null; return; } splat_cache = new z_SplatSet(m, meshAttributes); splat_current = new z_SplatSet(splat_cache); splat_target = new z_SplatSet(vertexCount, meshAttributes); splat_erase = new z_SplatSet(vertexCount, meshAttributes); }
private void RebuildCaches(Mesh m, z_BrushSettings settings) { vertexCount = m.vertexCount; colors_cache = new z_SplatSet(m, meshAttributes); colors = new z_SplatSet(vertexCount, meshAttributes); target_colors = new z_SplatSet(vertexCount, meshAttributes); erase_colors = new z_SplatSet(vertexCount, meshAttributes); triangleLookup = z_MeshUtility.GetAdjacentTriangles(m); for(int i = 0; i < colors_cache.Length; i++) { target_colors[i] = z_SplatWeight.Lerp(colors_cache[i], brushColor, settings.strength); erase_colors[i] = z_SplatWeight.Lerp(colors_cache[i], z_SplatWeight.Channel0, settings.strength); } }
public void CopyTo(z_SplatSet other) { if(other.Length != Length) { Debug.LogWarning("Copying splat weights to mismatched container length."); other.weights = new z_SplatWeight[Length]; } System.Array.Copy(weights, other.weights, Length); }