Hydrogen Framework  1.3.1
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Hydrogen.Mesh Class Reference

Additional static functions and constants used to extend existing Mesh support inside of Unity. More...

Static Public Member Functions

static int NearestVertexIndex (this UnityEngine.Mesh mesh, UnityEngine.Vector3 targetPosition)
 Return the index of the closest vertex to the targetPosition on the Mesh. More...
 

Public Attributes

const int VerticesLimit = 65536
 The maximum vertices allowed in a Mesh. More...
 
const int VerticesArrayLimit = 65535
 The maximum vertices allowed in a Mesh when counting index 0 of an array as one. More...
 

Detailed Description

Additional static functions and constants used to extend existing Mesh support inside of Unity.

Definition at line 35 of file Mesh.cs.

Member Function Documentation

static int Hydrogen.Mesh.NearestVertexIndex ( this UnityEngine.Mesh  mesh,
UnityEngine.Vector3  targetPosition 
)
static

Return the index of the closest vertex to the targetPosition on the Mesh.

Returns
The vertex index on the mesh.
Parameters
meshThe mesh to compare against.
targetPositionThe position to check against.

Definition at line 54 of file Mesh.cs.

55  {
56  // Create local reference
57  UnityEngine.Vector3[] vertices = mesh.vertices;
58 
59  // Our best distance so far
60  float nearestDistance = UnityEngine.Mathf.Infinity;
61 
62  // The index (-1) if we don't find one
63  int best = vertices.Length - 1;
64 
65  for (var i = 0; i < (best + 1); i++) {
66  UnityEngine.Vector3 vertex = vertices [i];
67  UnityEngine.Vector3 difference = targetPosition - vertex;
68 
69  float differenceDist = difference.sqrMagnitude;
70 
71  if (differenceDist < nearestDistance) {
72  nearestDistance = differenceDist;
73  best = i;
74  }
75  }
76 
77  // Send it back!
78  return best;
79  }

Member Data Documentation

const int Hydrogen.Mesh.VerticesArrayLimit = 65535

The maximum vertices allowed in a Mesh when counting index 0 of an array as one.

This is useful for looping so you dont have to do -1 all the time.

Definition at line 46 of file Mesh.cs.

const int Hydrogen.Mesh.VerticesLimit = 65536

The maximum vertices allowed in a Mesh.

This is a limitation of the short integer.

Definition at line 41 of file Mesh.cs.