Beispiel #1
0
 public List <NodeHit> intersect(Vector3 sphereCenter, float radius, Material.Property materialFlags = Material.Property.ALL)
 {
     return(myRoot.sphereIntersection(sphereCenter, radius, materialFlags));
 }
Beispiel #2
0
        public int bufferNode(ref IntPtr buffer, Node n, Material.Property pass)
        {
            int vertCount = 0;

            if (n.isLeaf == false)
            {
                for (int i = 0; i < 8; i++)
                {
                    vertCount += bufferNode(ref buffer, n.myChildren[i], pass);
                }
            }
            else
            {
                if (n.isVisible() == false)
                {
                    return(0);
                }

                if (n.myMaterial.property != pass)
                {
                    return(0);
                }

                TerrainVertex[] vertBuffer = new TerrainVertex[36];

                //calculated values
                Vector3[] verts = n.generateVerts();
                int       idx   = 0;
                for (int i = 0; i < 6; i++)
                {
                    if (n.faceVisible(i) == true)
                    {
                        Vector2 uv;
                        Vector3 v;

                        //first triangle
                        v  = n.localVertex(i, 0, ref verts);
                        uv = n.localUv(i, 0, ref verts);
                        vertBuffer[idx].pos      = TerrainVertex.encode(v);
                        vertBuffer[idx].uvx      = (UInt16)(uv.X * 100);
                        vertBuffer[idx].uvy      = (UInt16)(uv.Y * 100);
                        vertBuffer[idx].texIndex = (UInt16)n.localMaterial(i); idx++;

                        v  = n.localVertex(i, 1, ref verts);
                        uv = n.localUv(i, 1, ref verts);
                        vertBuffer[idx].pos      = TerrainVertex.encode(v);
                        vertBuffer[idx].uvx      = (UInt16)(uv.X * 100);
                        vertBuffer[idx].uvy      = (UInt16)(uv.Y * 100);
                        vertBuffer[idx].texIndex = (UInt16)n.localMaterial(i); idx++;

                        v  = n.localVertex(i, 2, ref verts);
                        uv = n.localUv(i, 2, ref verts);
                        vertBuffer[idx].pos      = TerrainVertex.encode(v);
                        vertBuffer[idx].uvx      = (UInt16)(uv.X * 100);
                        vertBuffer[idx].uvy      = (UInt16)(uv.Y * 100);
                        vertBuffer[idx].texIndex = (UInt16)n.localMaterial(i); idx++;

                        //second triangle
                        v  = n.localVertex(i, 0, ref verts);
                        uv = n.localUv(i, 0, ref verts);
                        vertBuffer[idx].pos      = TerrainVertex.encode(v);
                        vertBuffer[idx].uvx      = (UInt16)(uv.X * 100);
                        vertBuffer[idx].uvy      = (UInt16)(uv.Y * 100);
                        vertBuffer[idx].texIndex = (UInt16)n.localMaterial(i); idx++;

                        v  = n.localVertex(i, 2, ref verts);
                        uv = n.localUv(i, 2, ref verts);
                        vertBuffer[idx].pos      = TerrainVertex.encode(v);
                        vertBuffer[idx].uvx      = (UInt16)(uv.X * 100);
                        vertBuffer[idx].uvy      = (UInt16)(uv.Y * 100);
                        vertBuffer[idx].texIndex = (UInt16)n.localMaterial(i); idx++;

                        v  = n.localVertex(i, 3, ref verts);
                        uv = n.localUv(i, 3, ref verts);
                        vertBuffer[idx].pos      = TerrainVertex.encode(v);
                        vertBuffer[idx].uvx      = (UInt16)(uv.X * 100);
                        vertBuffer[idx].uvy      = (UInt16)(uv.Y * 100);
                        vertBuffer[idx].texIndex = (UInt16)n.localMaterial(i); idx++;
                    }
                }

                for (int i = 0; i < idx; i++)
                {
                    Marshal.StructureToPtr(vertBuffer[i], buffer, false);
                    buffer += TerrainVertex.stride;
                }

                //return the number of verts that are added
                return(idx);
            }

            return(vertCount);
        }
Beispiel #3
0
 public List <NodeHit> intersect(Ray r, float t0, float t1, Material.Property materialFlags = Material.Property.ALL)
 {
     return(myRoot.rayIntersection(r, t0, t1, materialFlags));
 }