コード例 #1
0
        public void OnAddRemoveGraphics(List <int> dirtyIndexes)
        {
            MeshCache.Clear();

            while (_meshes.Count > group.graphics.Count)
            {
                _meshes.RemoveMesh(_meshes.Count - 1);
            }

            while (_meshes.Count < group.graphics.Count)
            {
                beginMesh();
                _generation.graphic      = group.graphics[_meshes.Count] as LeapMeshGraphicBase;
                _generation.graphicIndex = _meshes.Count;
                _generation.graphicId    = _meshes.Count;
                base.buildGraphic();
                finishAndAddMesh();
            }

            foreach (var dirtyIndex in dirtyIndexes)
            {
                beginMesh(_meshes[dirtyIndex]);
                _generation.graphic      = group.graphics[dirtyIndex] as LeapMeshGraphicBase;
                _generation.graphicIndex = dirtyIndex;
                _generation.graphicId    = dirtyIndex;
                base.buildGraphic();
                finishMesh();
                _generation.mesh = null;
            }

            prepareMaterial();
        }
コード例 #2
0
        protected virtual void buildUvs(UVChannelFlags channel)
        {
            using (new ProfilerSample("Build Uvs"))
            {
                var uvs        = MeshCache.GetUvs(_generation.graphic.mesh, channel);
                var targetList = _generation.uvs[channel.Index()];

                targetList.AddRange(uvs);

                //If we cannot remap this channel, just return
                if ((_generation.graphic.remappableChannels & channel) == 0)
                {
                    return;
                }

                UnityEngine.Object key;
                if (_textureFeatures.Count > 0)
                {
                    key = _textureFeatures[0].featureData[_generation.graphicIndex].texture;
                }
                else if (_spriteFeatures.Count > 0)
                {
                    key = _spriteFeatures[0].featureData[_generation.graphicIndex].sprite;
                }
                else
                {
                    return;
                }

                Rect rect = _atlasUvs.GetRect(channel.Index(), key);
                MeshUtil.RemapUvs(targetList, rect, uvs.Count);
            }
        }
コード例 #3
0
            public override void RebuildEditorPickingMesh()
            {
                base.RebuildEditorPickingMesh();

                Assert.IsNotNull(_meshGraphic);

                _meshGraphic.RefreshMeshData();

                List <Vector3> pickingVerts = new List <Vector3>();
                List <int>     pickingTris  = new List <int>();

                pickingVerts.Clear();
                pickingTris.Clear();

                if (pickingMesh == null)
                {
                    pickingMesh = new Mesh();
                    pickingMesh.MarkDynamic();
                    pickingMesh.hideFlags = HideFlags.HideAndDontSave;
                    pickingMesh.name      = "Graphic Picking Mesh";
                }
                pickingMesh.Clear(keepVertexLayout: false);

                if (_meshGraphic.mesh == null)
                {
                    return;
                }

                var topology = MeshCache.GetTopology(_meshGraphic.mesh);

                for (int i = 0; i < topology.tris.Length; i++)
                {
                    pickingTris.Add(topology.tris[i] + pickingVerts.Count);
                }

                ITransformer transformer = null;

                if (_meshGraphic.anchor != null)
                {
                    transformer = _meshGraphic.anchor.transformer;
                }

                for (int i = 0; i < topology.verts.Length; i++)
                {
                    Vector3 localRectVert = _meshGraphic.attachedGroup.renderer.transform.InverseTransformPoint(_meshGraphic.transform.TransformPoint(topology.verts[i]));

                    if (transformer != null)
                    {
                        localRectVert = transformer.TransformPoint(localRectVert);
                    }

                    localRectVert = _meshGraphic.attachedGroup.renderer.transform.TransformPoint(localRectVert);

                    pickingVerts.Add(localRectVert);
                }

                pickingMesh.SetVertices(pickingVerts);
                pickingMesh.SetTriangles(pickingTris, 0, calculateBounds: true);
                pickingMesh.RecalculateNormals();
            }
コード例 #4
0
        protected virtual void buildColors()
        {
            using (new ProfilerSample("Build Colors"))
            {
                Color totalTint;
                if (QualitySettings.activeColorSpace == ColorSpace.Linear)
                {
                    totalTint = _bakedTint.linear * _generation.graphic.vertexColor.linear;
                }
                else
                {
                    totalTint = _bakedTint * _generation.graphic.vertexColor;
                }

                var colors = MeshCache.GetColors(_generation.graphic.mesh);
                if (QualitySettings.activeColorSpace == ColorSpace.Linear)
                {
                    for (int i = 0; i < colors.Length; i++)
                    {
                        _generation.colors.Add(colors[i].linear * totalTint);
                    }
                }
                else
                {
                    for (int i = 0; i < colors.Length; i++)
                    {
                        _generation.colors.Add(colors[i] * totalTint);
                    }
                }
            }
        }
コード例 #5
0
        protected virtual void buildTopology()
        {
            using (new ProfilerSample("Build Topology"))
            {
                var topology = MeshCache.GetTopology(_generation.graphic.mesh);

                int vertOffset = _generation.verts.Count;
                for (int i = 0; i < topology.tris.Length; i++)
                {
                    _generation.tris.Add(topology.tris[i] + vertOffset);
                }

                if (_doesRequireNormals)
                {
                    var normals = MeshCache.GetNormals(_generation.graphic.mesh);
                    for (int i = 0; i < topology.verts.Length; i++)
                    {
                        Vector3 meshVert;
                        Vector3 meshNormal;
                        graphicVertNormalToMeshVertNormal(topology.verts[i], normals[i], out meshVert, out meshNormal);

                        _generation.verts.Add(meshVert);
                        _generation.normals.Add(meshNormal);
                    }
                }
                else
                {
                    for (int i = 0; i < topology.verts.Length; i++)
                    {
                        _generation.verts.Add(graphicVertToMeshVert(topology.verts[i]));
                    }
                }
            }
        }
コード例 #6
0
        protected virtual void buildColors()
        {
            using (new ProfilerSample("Build Colors")) {
                Color totalTint = _bakedTint * _generation.graphic.vertexColor;

                var colors = MeshCache.GetColors(_generation.graphic.mesh);
                for (int i = 0; i < colors.Length; i++)
                {
                    _generation.colors.Add(colors[i] * totalTint);
                }
            }
        }
コード例 #7
0
        protected virtual void setupForBuilding()
        {
            using (new ProfilerSample("Mesh Setup")) {
                MeshCache.Clear();
                loadAllSupportedFeatures();
                prepareMeshes();
                prepareMaterial();

                if (_textureFeatures.Count != 0)
                {
                    _atlas.UpdateTextureList(_textureFeatures);
                }

                if (_spriteFeatures.Count != 0)
                {
#if UNITY_EDITOR
                    Packer.RebuildAtlasCacheIfNeeded(EditorUserBuildSettings.activeBuildTarget);
#endif
                    extractSpriteRects();
                    uploadSpriteTextures();
                }
            }
        }
コード例 #8
0
        public override void OnUpdateRenderer()
        {
            using (new ProfilerSample("Update Dynamic Renderer")) {
                base.OnUpdateRenderer();

                using (new ProfilerSample("Check For Dirty Graphics")) {
                    for (int i = 0; i < group.graphics.Count; i++)
                    {
                        var graphic = group.graphics[i];
                        if (graphic.isRepresentationDirty || _meshes[i] == null)
                        {
                            MeshCache.Clear();

                            beginMesh(_meshes[i]);
                            _generation.graphic      = graphic as LeapMeshGraphicBase;
                            _generation.graphicIndex = i;
                            _generation.graphicId    = i;
                            base.buildGraphic();
                            finishMesh();
                            _meshes[i]       = _generation.mesh;
                            _generation.mesh = null;

                            graphic.isRepresentationDirty = false;
                        }
                    }
                }

                if (renderer.space == null)
                {
                    using (new ProfilerSample("Draw Meshes")) {
                        Assert.AreEqual(group.graphics.Count, _meshes.Count);
                        for (int i = 0; i < group.graphics.Count; i++)
                        {
                            if (!group.graphics[i].isActiveAndEnabled)
                            {
                                continue;
                            }

                            drawMesh(_meshes[i], group.graphics[i].transform.localToWorldMatrix);
                        }
                    }
                }
                else if (renderer.space is LeapRadialSpace)
                {
                    var curvedSpace = renderer.space as LeapRadialSpace;
                    using (new ProfilerSample("Build Material Data And Draw Meshes")) {
                        _curved_worldToAnchor.Clear();
                        _curved_graphicParameters.Clear();
                        for (int i = 0; i < _meshes.Count; i++)
                        {
                            var graphic = group.graphics[i];
                            if (!graphic.isActiveAndEnabled)
                            {
                                _curved_graphicParameters.Add(Vector4.zero);
                                _curved_worldToAnchor.Add(Matrix4x4.identity);
                                continue;
                            }

                            var transformer = graphic.anchor.transformer;

                            Vector3 localPos = renderer.transform.InverseTransformPoint(graphic.transform.position);

                            Matrix4x4 mainTransform = renderer.transform.localToWorldMatrix * transformer.GetTransformationMatrix(localPos);
                            Matrix4x4 deform        = renderer.transform.worldToLocalMatrix * Matrix4x4.TRS(renderer.transform.position - graphic.transform.position, Quaternion.identity, Vector3.one) * graphic.transform.localToWorldMatrix;
                            Matrix4x4 total         = mainTransform * deform;

                            _curved_graphicParameters.Add((transformer as IRadialTransformer).GetVectorRepresentation(graphic.transform));
                            _curved_worldToAnchor.Add(mainTransform.inverse);

                            //Safe to do this before we upload material data
                            //meshes are drawn at end of frame anyway!
                            drawMesh(_meshes[i], total);
                        }
                    }

                    using (new ProfilerSample("Upload Material Data")) {
                        _material.SetFloat(SpaceProperties.RADIAL_SPACE_RADIUS, curvedSpace.radius);
                        _material.SetMatrixArraySafe("_GraphicRendererCurved_WorldToAnchor", _curved_worldToAnchor);
                        _material.SetMatrix("_GraphicRenderer_LocalToWorld", renderer.transform.localToWorldMatrix);
                        _material.SetVectorArraySafe("_GraphicRendererCurved_GraphicParameters", _curved_graphicParameters);
                    }
                }
            }
        }