Tanoda
LeapMeshGraphicEditorApi.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System.Collections.Generic;
10using UnityEngine;
11using UnityEngine.Assertions;
12using Leap.Unity.Space;
13
15
16 public abstract partial class LeapMeshGraphicBase : LeapGraphic {
17
18#if UNITY_EDITOR
19 public class MeshEditorApi : EditorApi {
20 protected readonly LeapMeshGraphicBase _meshGraphic;
21
22 public MeshEditorApi(LeapMeshGraphicBase meshGraphic) : base(meshGraphic) {
23 _meshGraphic = meshGraphic;
24 }
25
26 public override void RebuildEditorPickingMesh() {
27 base.RebuildEditorPickingMesh();
28
29 Assert.IsNotNull(_meshGraphic);
30
31 _meshGraphic.RefreshMeshData();
32
33 List<Vector3> pickingVerts = new List<Vector3>();
34 List<int> pickingTris = new List<int>();
35
36 pickingVerts.Clear();
37 pickingTris.Clear();
38
39 if (pickingMesh == null) {
40 pickingMesh = new Mesh();
41 pickingMesh.MarkDynamic();
42 pickingMesh.hideFlags = HideFlags.HideAndDontSave;
43 pickingMesh.name = "Graphic Picking Mesh";
44 }
45 pickingMesh.Clear(keepVertexLayout: false);
46
47 if (_meshGraphic.mesh == null) return;
48
49 var topology = MeshCache.GetTopology(_meshGraphic.mesh);
50 for (int i = 0; i < topology.tris.Length; i++) {
51 pickingTris.Add(topology.tris[i] + pickingVerts.Count);
52 }
53
55 if (_meshGraphic.anchor != null) {
56 transformer = _meshGraphic.anchor.transformer;
57 }
58
59 for (int i = 0; i < topology.verts.Length; i++) {
60 Vector3 localRectVert = _meshGraphic.attachedGroup.renderer.transform.InverseTransformPoint(_meshGraphic.transform.TransformPoint(topology.verts[i]));
61
62 if (transformer != null) {
63 localRectVert = transformer.TransformPoint(localRectVert);
64 }
65
66 localRectVert = _meshGraphic.attachedGroup.renderer.transform.TransformPoint(localRectVert);
67
68 pickingVerts.Add(localRectVert);
69 }
70
71 pickingMesh.SetVertices(pickingVerts);
72 pickingMesh.SetTriangles(pickingTris, 0, calculateBounds: true);
73 pickingMesh.RecalculateNormals();
74 }
75 }
76#endif
77 }
78}
ITransformer transformer
A utility getter that returns a transformer for this graphic. Even if the space anchor for this graph...
Definition: LeapGraphic.cs:120
This class is a base class for all graphics that can be represented by a mesh object.
abstract void RefreshMeshData()
When this method is called, the mesh property and the remappableChannels property must be assigned to...
Vector3 TransformPoint(Vector3 localRectPos)
Transform a point from rect space to warped space.