Here are the examples of the csharp api MeshVoxelizerProject.MeshRayTracer.IntersectRayTriTwoSided(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3, out float, out float, out float, out float, out float) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
19
View Source File : MeshRayTracer.cs
License : MIT License
Project Creator : Scrawk
License : MIT License
Project Creator : Scrawk
private void TraceRecursive(int nodeIndex, Vector3 start, Vector3 dir, ref MeshRay ray)
{
AABBNode node = Nodes[nodeIndex];
if (node.Faces == null)
{
// find closest node
AABBNode leftChild = Nodes[node.Children+0];
AABBNode rightChild = Nodes[node.Children+1];
float[] dist = new float[]{float.PositiveInfinity, float.PositiveInfinity};
IntersectRayAABB(start, dir, leftChild.Bounds.Min, leftChild.Bounds.Max, out dist[0]);
IntersectRayAABB(start, dir, rightChild.Bounds.Min, rightChild.Bounds.Max, out dist[1]);
int closest = 0;
int furthest = 1;
if (dist[1] < dist[0])
{
closest = 1;
furthest = 0;
}
if (dist[closest] < ray.distance)
TraceRecursive(node.Children + closest, start, dir, ref ray);
if (dist[furthest] < ray.distance)
TraceRecursive(node.Children + furthest, start, dir, ref ray);
}
else
{
float t, u, v, w, s;
for (int i=0; i < node.Faces.Length; ++i)
{
int indexStart = node.Faces[i]*3;
Vector3 a = Vertices[Indices[indexStart + 0]];
Vector3 b = Vertices[Indices[indexStart + 1]];
Vector3 c = Vertices[Indices[indexStart + 2]];
if (IntersectRayTriTwoSided(start, dir, a, b, c, out t, out u, out v, out w, out s))
{
if (t < ray.distance)
{
ray.distance = t;
ray.u = u;
ray.v = v;
ray.w = w;
ray.faceSign = s;
ray.faceIndex = node.Faces[i];
}
}
}
}
}
19
View Source File : MeshRayTracer.cs
License : MIT License
Project Creator : Scrawk
License : MIT License
Project Creator : Scrawk
public MeshRay TraceRaySlow(Vector3 start, Vector3 dir)
{
float minT, minU, minV, minW, minS;
minT = minU = minV = minW = minS = float.PositiveInfinity;
float t, u, v, w, s;
bool hit = false;
int minIndex = 0;
for (int i = 0; i < NumFaces; ++i)
{
Vector3 a = Vertices[Indices[i*3+0]];
Vector3 b = Vertices[Indices[i*3+1]];
Vector3 c = Vertices[Indices[i * 3 + 2]];
if (IntersectRayTriTwoSided(start, dir, a, b, c, out t, out u, out v, out w, out s))
{
if (t < minT)
{
minT = t;
minU = u;
minV = v;
minW = w;
minS = s;
minIndex = i;
hit = true;
}
}
}
MeshRay ray = new MeshRay();
ray.distance = minT;
ray.u = minU;
ray.v = minV;
ray.w = minW;
ray.faceSign = minS;
ray.faceIndex = minIndex;
ray.hit = hit;
return ray;
}