public void GenerateTickHeadContent(MeshGenerationContext context)
        {
            const float tipY   = 20f;
            const float height = 6f;
            const float width  = 11f;
            const float middle = 6f;

            Color color;

            if (EditorGUIUtility.isProSkin)
            {
                color = m_DebugPlayhead ? ColorUtility.FromHtmlString("#234A6C") : Color.white;
            }
            else
            {
                color = m_DebugPlayhead ? ColorUtility.FromHtmlString("#2E5B8D") : Color.white;
            }

            MeshWriteData mesh = context.Allocate(3, 3);

            Vertex[] vertices = new Vertex[3];
            vertices[0].position = new Vector3(middle, tipY, Vertex.nearZ);
            vertices[1].position = new Vector3(width, tipY - height, Vertex.nearZ);
            vertices[2].position = new Vector3(0, tipY - height, Vertex.nearZ);

            vertices[0].tint = color;
            vertices[1].tint = color;
            vertices[2].tint = color;

            mesh.SetAllVertices(vertices);
            mesh.SetAllIndices(new ushort[] { 0, 2, 1 });
        }
            void OnGenerateVisualContent(MeshGenerationContext mgc)
            {
                Rect r = contentRect;

                if (r.width < 0.01f || r.height < 0.01f)
                {
                    return; // Skip rendering when too small.
                }
                Color color = resolvedStyle.color;

                k_Vertices[0].tint = Color.black;
                k_Vertices[1].tint = Color.black;
                k_Vertices[2].tint = color;
                k_Vertices[3].tint = color;

                float left   = 0;
                float right  = r.width;
                float top    = 0;
                float bottom = r.height;

                k_Vertices[0].position = new Vector3(left, bottom, Vertex.nearZ);
                k_Vertices[1].position = new Vector3(left, top, Vertex.nearZ);
                k_Vertices[2].position = new Vector3(right, top, Vertex.nearZ);
                k_Vertices[3].position = new Vector3(right, bottom, Vertex.nearZ);

                MeshWriteData mwd = mgc.Allocate(k_Vertices.Length, k_Indices.Length);

                mwd.SetAllVertices(k_Vertices);
                mwd.SetAllIndices(k_Indices);
            }
            void OnGenerateVisualContent(MeshGenerationContext mgc)
            {
                Rect r = contentRect;

                if (r.width < 0.01f || r.height < 0.01f)
                {
                    return; // Skip rendering when too small.
                }
                float left   = 0;
                float right  = r.width;
                float top    = 0;
                float bottom = r.height;

                k_Vertices[0].position = new Vector3(left, bottom, Vertex.nearZ);
                k_Vertices[1].position = new Vector3(left, top, Vertex.nearZ);
                k_Vertices[2].position = new Vector3(right, top, Vertex.nearZ);
                k_Vertices[3].position = new Vector3(right, bottom, Vertex.nearZ);

                MeshWriteData mwd = mgc.Allocate(k_Vertices.Length, k_Indices.Length, m_Texture);

                // Remap 0..1 to the uv region.
                Rect uvs = mwd.uvRegion;

                k_Vertices[0].uv = new Vector2(uvs.xMin, uvs.yMin);
                k_Vertices[1].uv = new Vector2(uvs.xMin, uvs.yMax);
                k_Vertices[2].uv = new Vector2(uvs.xMax, uvs.yMax);
                k_Vertices[3].uv = new Vector2(uvs.xMax, uvs.yMin);

                mwd.SetAllVertices(k_Vertices);
                mwd.SetAllIndices(k_Indices);
            }
            void OnGenerateVisualContent(MeshGenerationContext mgc)
            {
                Rect r = contentRect;

                if (r.width < 0.01f || r.height < 0.01f)
                {
                    return; // Skip rendering when too small.
                }
                float radiusX = r.width / 2;
                float radiusY = r.height / 2;

                k_Vertices[0].position = new Vector3(radiusX, radiusY, Vertex.nearZ);

                float angle = 0;

                for (int i = 1; i < 7; ++i)
                {
                    k_Vertices[i].position = new Vector3(
                        radiusX + radiusX * Mathf.Cos(angle),
                        radiusY - radiusY * Mathf.Sin(angle),
                        Vertex.nearZ);
                    angle += 2f * Mathf.PI / 6;
                }

                MeshWriteData mwd = mgc.Allocate(k_Vertices.Length, k_Indices.Length);

                mwd.SetAllVertices(k_Vertices);
                mwd.SetAllIndices(k_Indices);
            }
예제 #5
0
        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());
            }
        }