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(); }
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(); } } }
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); } } } }