protected void ClearSubMeshes(MeshParts parts) { foreach (LayerSubMesh current in this.subMeshes) { current.Clear(parts); } }
static void Prefix(LayerSubMesh __instance, ref MeshParts parts) { if (__instance.material == MatBases.SunShadowFade) { parts &= ~MeshParts.UVs; } }
private void ClearSubMeshes(MeshParts parts, List <LayerSubMesh> subMeshes) { for (int i = 0; i < subMeshes.Count; i++) { subMeshes[i].Clear(parts); } }
protected void ClearSubMeshes(MeshParts parts) { foreach (LayerSubMesh subMesh in subMeshes) { subMesh.Clear(parts); } }
private void ClearSubMeshes(MeshParts parts) { for (int i = 0; i < this.subMeshes.Count; i++) { this.subMeshes[i].Clear(parts); } }
internal void FinalizeMesh(MeshParts tags, LayerSubMesh subMesh) { if (subMesh.verts.Count > 0) { subMesh.FinalizeMesh(tags); } }
protected void ClearSubMeshes(MeshParts parts) { foreach (LayerSubMesh layerSubMesh in this.subMeshes) { layerSubMesh.Clear(parts); } }
private void DrawLine(MeshParts mp, float2 u, float2 v, float width, Color clr) { float2 dlt = v - u; float2 S = new float2(math.length(RectScale * dlt), math.cmin(RectScale) * width); dlt = RectScale * dlt; float2x2 R = float2x2.Rotate(math.atan2(dlt.y, dlt.x)); float2x2 RS = math.mul(R, float2x2.Scale(S)); Func <float2, float2> T = (vtx) => (RectScale * vtx); Func <float2, float2> T2 = (vtx) => (math.mul(RS, vtx) + T(u)); int vtxOffset = mp.vertices.Count; for (int iVtx = 0; iVtx < 4; iVtx++) { mp.vertices.Add(new Vertex { position = (Vector2)T2(RectCourners[iVtx] - new float2(0, 0.5f)), tint = clr, uv = Vector2.zero }); } mp.triangles.Add(vtxOffset + new int3(0, 1, 2)); mp.triangles.Add(vtxOffset + new int3(3, 0, 2)); }
public void AddModelMeshPart(ModelMeshPart meshpart, bool finalise = true) { if (finalise) { meshpart.Finalise(); } MeshParts.Add(meshpart); }
internal void FinalizeMesh(MeshParts tags, List <LayerSubMesh> subMeshes) { for (int i = 0; i < subMeshes.Count; i++) { if (subMeshes[i].verts.Count > 0) { subMeshes[i].FinalizeMesh(tags); } } }
protected void FinalizeMesh(MeshParts tags) { for (int i = 0; i < this.subMeshes.Count; i++) { if (this.subMeshes[i].verts.Count > 0) { this.subMeshes[i].FinalizeMesh(tags); } } }
public void FinalizeMesh(MeshParts parts) { if (this.finalized) { Log.Warning("Finalizing mesh which is already finalized. Did you forget to call Clear()?", false); } if ((byte)(parts & MeshParts.Verts) != 0 || (byte)(parts & MeshParts.Tris) != 0) { this.mesh.Clear(); } if ((byte)(parts & MeshParts.Verts) != 0) { if (this.verts.Count > 0) { this.mesh.SetVertices(this.verts); } else { Log.Error("Cannot cook Verts for " + this.material.ToString() + ": no ingredients data. If you want to not render this submesh, disable it.", false); } } if ((byte)(parts & MeshParts.Tris) != 0) { if (this.tris.Count > 0) { this.mesh.SetTriangles(this.tris, 0); } else { Log.Error("Cannot cook Tris for " + this.material.ToString() + ": no ingredients data.", false); } } if ((byte)(parts & MeshParts.Colors) != 0) { if (this.colors.Count > 0) { this.mesh.SetColors(this.colors); } } if ((byte)(parts & MeshParts.UVs) != 0) { if (this.uvs.Count > 0) { this.mesh.SetUVs(0, this.uvs); } } this.finalized = true; }
private void AddRect(MeshParts mp, float2 pos, float2 size, Color clr) { Func <float2, float2> T = (vtx) => (RectScale * vtx); int vtxOffset = mp.vertices.Count; for (int iVtx = 0; iVtx < 4; iVtx++) { mp.vertices.Add(new Vertex { position = (Vector2)T(size * RectCourners[iVtx] + pos), tint = clr, uv = Vector2.zero }); } mp.triangles.Add(vtxOffset + new int3(2, 1, 0)); mp.triangles.Add(vtxOffset + new int3(0, 1, 2)); mp.triangles.Add(vtxOffset + new int3(3, 0, 2)); }
public void Clear(MeshParts parts) { if ((parts & MeshParts.Verts) != 0) { verts.Clear(); } if ((parts & MeshParts.Tris) != 0) { tris.Clear(); } if ((parts & MeshParts.Colors) != 0) { colors.Clear(); } if ((parts & MeshParts.UVs) != 0) { uvs.Clear(); } finalized = false; }
public void Clear(MeshParts parts) { if ((byte)(parts & MeshParts.Verts) != 0) { this.verts.Clear(); } if ((byte)(parts & MeshParts.Tris) != 0) { this.tris.Clear(); } if ((byte)(parts & MeshParts.Colors) != 0) { this.colors.Clear(); } if ((byte)(parts & MeshParts.UVs) != 0) { this.uvs.Clear(); } this.finalized = false; }
protected override void OnGenerateVisualContent(MeshGenerationContext cxt) { var mp = new MeshParts(); List <int3> curTri = new List <int3>(); Color[] clrByDepth = new Color[_subDiv + 1]; for (int iClr = 0; iClr < clrByDepth.Length; iClr++) { float t = iClr / (float)(clrByDepth.Length); clrByDepth[iClr] = Color.HSVToRGB(t, 1, 1); } for (int iTriVtx = 0; iTriVtx < 3; iTriVtx++) { Vertex vtx = new Vertex(); vtx.position = (Vector2)T_LsFromNs(TriangleMat[iTriVtx]); vtx.tint = clrByDepth[_subDiv]; // it circular mp.vertices.Add(vtx); } curTri.Add(new int3(2, 1, 0)); for (int iDiv = 0; iDiv < _subDiv; iDiv++) { List <int3> nxtTri = new List <int3>(); foreach (var outerTri in curTri) { int vtxOffset = mp.vertices.Count; for (int iTriVtx = 0; iTriVtx < 3; iTriVtx++) { var pntLS = Vector3.zero; for (int iEdge = 0; iEdge < 3; iEdge++) { pntLS += (iEdge == iTriVtx) ? Vector3.zero: mp.vertices[outerTri[iEdge]].position; } pntLS /= 2; Vertex vtx = new Vertex(); vtx.position = pntLS; vtx.tint = clrByDepth[iDiv]; mp.vertices.Add(vtx); } for (int iTriVtx = 0; iTriVtx < 3; iTriVtx++) { // Broad cast it to xyz; int3 newTri = outerTri[iTriVtx]; if (iTriVtx == 0) { newTri.yz = vtxOffset + new int2(2, 1); } else if (iTriVtx == 1) { newTri.xz = vtxOffset + new int2(2, 0); } else if (iTriVtx == 2) { newTri.xy = vtxOffset + new int2(1, 0); } nxtTri.Add(newTri); } nxtTri.Add(vtxOffset + new int3(0, 1, 2)); } curTri = nxtTri; } foreach (var tri in curTri) { mp.triangles.Add(tri); //indices.AddRange(new ushort[] { (ushort)tri.z, (ushort)tri.y, (ushort)tri.x }); } if (GeneBankManager.Inst && GeneBankManager.Inst.GenomeCount > 0) { ApplyGenomeColors(mp.vertices); } AddPoint(mp, T_NsFromBs(_value_bs), math.cmin(layout.size / 30), Color.white); MeshWriteData meshData = cxt.Allocate(mp.vertices.Count, mp.triangles.Count * 3); meshData.SetAllVertices(mp.vertices.ToArray()); meshData.SetAllIndices(mp.GetIndices()); }
private void OnGenerateVisualContent(MeshGenerationContext cxt) { MeshParts mp = new MeshParts(); MultiLayerPerception mlp = _TestMLP; AddRect(mp, 0, 1, Color.gray); if (mlp != null) { using (IWorker oneshotSyncWorker = WorkerFactory.CreateWorker(_testMLP.model, _extraLayers, WorkerFactory.Device.GPU)) { using (Tensor obsTensor = new Tensor(new TensorShape(1, mlp._shape.inputSize))) { if (_observe.Length < mlp._shape.inputSize) { _observe = new float[mlp._shape.inputSize]; } for (int iINode = 0; iINode < mlp._shape.inputSize; iINode++) { obsTensor[iINode] = _observe[iINode]; } oneshotSyncWorker.Execute(obsTensor).FlushSchedule(); } for (int iINode = 0; iINode < mlp._shape.inputSize; iINode++) { AddRect(mp, GetNodePos(0, iINode), NodeSize, ActNodeColor(_observe[iINode])); } using (Tensor hvr = oneshotSyncWorker.PeekOutput(MultiLayerPerception.LayerNames.Hidden)) { using (Tensor hva = oneshotSyncWorker.PeekOutput(MultiLayerPerception.LayerNames.HiddenActive)) { for (int iHNode = 0; iHNode < mlp._shape.hiddenSize; iHNode++) { AddRect(mp, GetNodePos(1, iHNode), NodeSize, RawNodeColor(hvr[iHNode])); AddRect(mp, GetNodePos(1, iHNode) + new float2(0.5f, 0) * NodeSize, new float2(0.5f, 1) * NodeSize, ActNodeColor(hva[iHNode])); } } } using (Tensor ovr = oneshotSyncWorker.PeekOutput(MultiLayerPerception.LayerNames.Output)) { using (Tensor ova = oneshotSyncWorker.PeekOutput()) { for (int iONode = 0; iONode < mlp._shape.outputSize; iONode++) { AddRect(mp, GetNodePos(2, iONode), NodeSize, RawNodeColor(ovr[iONode])); AddRect(mp, GetNodePos(2, iONode) + new float2(0.5f, 0) * NodeSize, new float2(0.5f, 1) * NodeSize, ActNodeColor(ova[iONode])); } } } } string[] layerNames = new string[] { MultiLayerPerception.LayerNames.Hidden, MultiLayerPerception.LayerNames.Output }; float2 xBuf = NodeSize / 2; xBuf.y = 0; int prvLayer = 0; int curLayer = 1; foreach (string layerName in layerNames) { TensorShape tShape = _testMLP.GetLayerShape(layerName); for (int iPNode = 0; iPNode < tShape.flatHeight; iPNode++) { for (int iCNode = 0; iCNode < tShape.flatWidth; iCNode++) { float2 posI = GetNodePos(prvLayer, iPNode) + NodeSize / 2; float2 posW = GetNodePos(curLayer, iCNode) + NodeSize / 2; float t = 0.5f + mlp.GetWeight(layerName, iPNode, iCNode); DrawLine(mp, posI + xBuf, posW - xBuf, 0.025f, TurboColorMap.Map(t)); } } prvLayer = curLayer; curLayer++; } } MeshWriteData meshData = cxt.Allocate(mp.vertices.Count, mp.IndicesCount); if (meshData.vertexCount > 0) { meshData.SetAllVertices(mp.vertices.ToArray()); meshData.SetAllIndices(mp.GetIndices()); } }