public VoxelRenderer getRenderer(Index index) { VoxelRenderer rend = null; return(renderers.TryGetValue(index, out rend)? rend : null); }
private static void addDualVertices(LinkedList <Vector3[]> otherVerts, VoxelRenderer rend, int x, int y, int z, byte xyz) { Vector3[] otherVert1; Vector3[] otherVert2; switch (xyz) { case 0: otherVert1 = getVertex(rend, getY(x, y, z)); otherVert2 = getVertex(rend, getZ(x, y, z)); break; case 1: otherVert1 = getVertex(rend, getX(x, y, z)); otherVert2 = getVertex(rend, getZ(x, y, z)); break; case 2: otherVert1 = getVertex(rend, getX(x, y, z)); otherVert2 = getVertex(rend, getY(x, y, z)); break; default: return; } if (otherVert1 != null) { otherVerts.AddFirst(otherVert1); } if (otherVert2 != null) { otherVerts.AddFirst(otherVert2); } }
private void alignOtherEdge(VoxelUpdateInfo info, byte x, byte y, byte z) { VoxelRenderer other = info.renderers[1, 1, 1]; if (other == null) { if (info.blocks[1, 1, 1].GetType() == typeof(VoxelBlock)) { byte xStart = (byte)((VoxelBlock.CHILD_DIMENSION - 1) * (2 - x) / 2); byte xEnd = (byte)(1 + (VoxelBlock.CHILD_DIMENSION - 1) * (1 - x / 2)); byte yStart = (byte)((VoxelBlock.CHILD_DIMENSION - 1) * (2 - y) / 2); byte yEnd = (byte)(1 + (VoxelBlock.CHILD_DIMENSION - 1) * (1 - y / 2)); byte zStart = (byte)((VoxelBlock.CHILD_DIMENSION - 1) * (2 - z) / 2); byte zEnd = (byte)(1 + (VoxelBlock.CHILD_DIMENSION - 1) * (1 - z / 2)); for (byte xi = xStart; xi < xEnd; ++xi) { for (byte yi = yStart; yi < yEnd; ++yi) { for (byte zi = zStart; zi < zEnd; ++zi) { alignOtherEdge(new VoxelUpdateInfo(info, xi, yi, zi), x, y, z); } } } } return; } other.addEdge(info, (byte)(2 - x), (byte)(2 - y), (byte)(2 - z)); }
public void relinkRenderers(Dictionary <VoxelIndex, List <GameObject> > meshes) { lock (this) { //print("Start Renderers: " + renderers.Count); foreach (VoxelIndex index in meshes.Keys) { List <GameObject> objects = meshes[index]; //print("Mesh object count: " + objects.Count); VoxelRenderer rend; renderers.TryGetValue(index, out rend); if (rend == null) { rend = new VoxelRenderer(index, this); renderers[index] = rend; //} else { // print("already had renderer"); } VoxelHolder block = head.get(index); if (block is VoxelBlock) { //print("linking"); ((VoxelBlock)block).renderer = rend; //} else { // print("NOT BLOCK!"); } rend.obs = objects.ToArray(); } //print("End Renderers: " + renderers.Count); } }
public void updateAll(int x, int y, int z, byte detailLevel, VoxelTree control, bool force = false) { // check if this is a high enough detail level. If not, call the childrens' update methods if (!isRenderSize(control.sizes[detailLevel], control) && (!isRenderLod(x, y, z, control.sizes[detailLevel], control))) { for (byte xi = 0; xi < CHILD_DIMENSION; ++xi) { for (byte yi = 0; yi < CHILD_DIMENSION; ++yi) { for (byte zi = 0; zi < CHILD_DIMENSION; ++zi) { //VoxelUpdateInfo childInfo = new VoxelUpdateInfo(info, xi, yi, zi); if (children[xi, yi, zi].GetType() == typeof(Voxel)) { //if (!childInfo.isSolid()) children[xi, yi, zi] = new VoxelBlock((Voxel)children[xi, yi, zi]); //else //continue; } UpdateCheckJob job = new UpdateCheckJob((VoxelBlock)children[xi, yi, zi], control, (byte)(detailLevel + 1)); job.setOffset((byte)(x * CHILD_DIMENSION + xi), (byte)(y * CHILD_DIMENSION + yi), (byte)(z * CHILD_DIMENSION + zi)); control.enqueueCheck(job); } } } if (renderer != null) { //GameObject.Destroy(renderer.ob); //lock (myControl) { // myControl.enqueueJob(new DropRendererJob(renderer)); // renderer = null; //} renderer.old = true; } return; } // check if we already have a mesh if (renderer == null) { //clearSubRenderers(); renderer = new VoxelRenderer(new VoxelIndex(x, y, z, detailLevel), control); //info.renderers[1, 1, 1] = renderer; } else { renderer.old = false; if (!force) { return; } } // We should generate a mesh GenMeshJob updateJob = new GenMeshJob(this, control, detailLevel); updateJob.setOffset(x, y, z); control.enqueueUpdate(updateJob); }
public ApplyMeshJob(VoxelRenderer rend, byte detailLevel, int x, int y, int z) { //MonoBehaviour.print("CREATING!"); this.rend = rend; this.detailLevel = detailLevel; this.x = x; this.y = y; this.z = z; }
public void clearSuperRenderers(byte detailLevel, int x, int y, int z, VoxelTree control) { if (detailLevel > 0) { short factor = (short)(1 << (detailLevel - CHILD_COUNT_POWER)); byte xi = (byte)(x / factor); byte yi = (byte)(y / factor); byte zi = (byte)(z / factor); if (renderer != null && filledWithSubRenderers(false)) { control.enqueueJob(new DropRendererJob(renderer)); renderer = null; } ((VoxelBlock)children[xi, yi, zi]).clearSuperRenderers((byte)(detailLevel - CHILD_COUNT_POWER), x - xi * factor, y - yi * factor, z - zi * factor, control); } }
private static Vector3[] getVertex(VoxelRenderer rend, int hashIndex) { if (rend == null || rend.vertices == null) { return(null); } if (!rend.vertices.ContainsKey(hashIndex)) { return(null); } object index = rend.vertices[hashIndex]; return(new Vector3[] { rend.VERTS[(int)index], rend.NORMS[(int)index] }); }
public void relinkRenderers(Dictionary <Index, List <GameObject> > meshes) { lock (this) { //print("Start Renderers: " + renderers.Count); foreach (Index index in meshes.Keys) { List <GameObject> objects = meshes[index]; //print("Mesh object count: " + objects.Count); VoxelRenderer rend; renderers.TryGetValue(index, out rend); if (rend == null) { rend = new VoxelRenderer(index, this); renderers[index] = rend; //} else { // print("already had renderer"); } rend.obs = objects.ToArray(); } //print("End Renderers: " + renderers.Count); } }
public void clearSubRenderers(bool clearSelf, VoxelTree control) { if (clearSelf && renderer != null) { //control.enqueueJob(new DropRendererJob(renderer)); renderer.clear(); renderer = null; return; } for (byte xi = 0; xi < CHILD_DIMENSION; ++xi) { for (byte yi = 0; yi < CHILD_DIMENSION; ++yi) { for (byte zi = 0; zi < CHILD_DIMENSION; ++zi) { if (children[xi, yi, zi].GetType() != typeof(Voxel)) { ((VoxelBlock)children[xi, yi, zi]).clearSubRenderers(true, control); } } } } }
private static Vector3[] getVertex(VoxelRenderer rend, int hashIndex) { if (rend == null || rend.vertices == null) return null; if (!rend.vertices.ContainsKey(hashIndex)) return null; object index = rend.vertices[hashIndex]; return new Vector3[] { rend.VERTS[(int)index], rend.NORMS[(int)index] }; }
private static void addDualVertices(LinkedList<Vector3[]> otherVerts, VoxelRenderer rend, int x, int y, int z, byte xyz) { Vector3[] otherVert1; Vector3[] otherVert2; switch (xyz) { case 0: otherVert1 = getVertex(rend, getY(x, y, z)); otherVert2 = getVertex(rend, getZ(x, y, z)); break; case 1: otherVert1 = getVertex(rend, getX(x, y, z)); otherVert2 = getVertex(rend, getZ(x, y, z)); break; case 2: otherVert1 = getVertex(rend, getX(x, y, z)); otherVert2 = getVertex(rend, getY(x, y, z)); break; default: return; } if (otherVert1 != null) otherVerts.AddFirst(otherVert1); if (otherVert2 != null) otherVerts.AddFirst(otherVert2); }
public DropRendererJob(VoxelRenderer rend) { this.rend = rend; }
public void updateAll(uint x, uint y, uint z, byte detailLevel, OcTree control, bool force = false) { // check if this is a high enough detail level. If not, call the childrens' update methods VoxelRenderer renderer = control.getRenderer(new Index(detailLevel, x, y, z)); if (!isRenderSize(control.sizes[detailLevel], control) && (!isRenderLod(x, y, z, control.sizes[detailLevel], control))) { for (byte xi = 0; xi < CHILD_DIMENSION; ++xi) { for (byte yi = 0; yi < CHILD_DIMENSION; ++yi) { for (byte zi = 0; zi < CHILD_DIMENSION; ++zi) { if (children[xi, yi, zi].GetType() == typeof(Voxel)) { children[xi, yi, zi] = new VoxelBlock((Voxel)children[xi, yi, zi]); } UpdateCheckJob job = new UpdateCheckJob((VoxelBlock)children[xi, yi, zi], control, (byte)(detailLevel + 1)); job.setOffset((byte)(x * CHILD_DIMENSION + xi), (byte)(y * CHILD_DIMENSION + yi), (byte)(z * CHILD_DIMENSION + zi)); control.enqueueCheck(job); } } } return; } // check if we already have a mesh if (renderer == null) { renderer = new VoxelRenderer(new Index(detailLevel, x, y, z), control); } else if (!force) { return; } // We should generate a mesh GenMeshJob updateJob = new GenMeshJob(this, control, detailLevel); updateJob.setOffset(x, y, z); control.enqueueUpdate(updateJob); }
private bool mergeNormals(VoxelRenderer neighbor, int myIndex, int otherIndex) { if (vertices.ContainsKey(myIndex) && neighbor.vertices.ContainsKey(otherIndex)) { NORMS[vertices[myIndex]] = neighbor.NORMS[neighbor.vertices[otherIndex]]; return true; } return false; }
public void updateAll(uint x, uint y, uint z, byte detailLevel, Tree control, bool force = false) { // check if this is a high enough detail level. If not, call the childrens' update methods VoxelRenderer renderer = control.getRenderer(new Index(detailLevel, x, y, z)); if (!isRenderSize(control.sizes[detailLevel], control) && (!isRenderLod(x, y, z, control.sizes[detailLevel], control))) { for (byte xi = 0; xi < CHILD_DIMENSION; ++xi) { for (byte yi = 0; yi < CHILD_DIMENSION; ++yi) { for (byte zi = 0; zi < CHILD_DIMENSION; ++zi) { //VoxelUpdateInfo childInfo = new VoxelUpdateInfo(info, xi, yi, zi); if (children[xi, yi, zi].GetType() == typeof(Voxel)) { //if (!childInfo.isSolid()) children[xi, yi, zi] = new VoxelBlock((Voxel)children[xi, yi, zi]); //else //continue; } UpdateCheckJob job = new UpdateCheckJob((VoxelBlock)children[xi, yi, zi], control, (byte)(detailLevel + 1)); job.setOffset((byte)(x * CHILD_DIMENSION + xi), (byte)(y * CHILD_DIMENSION + yi), (byte)(z * CHILD_DIMENSION + zi)); control.enqueueCheck(job); } } } if (renderer != null) { //GameObject.Destroy(renderer.ob); //lock (myControl) { // myControl.enqueueJob(new DropRendererJob(renderer)); // renderer = null; //} renderer.old = true; } return; } // check if we already have a mesh if (renderer == null) { //clearSubRenderers(); renderer = new VoxelRenderer(new Index(detailLevel, x, y, z), control); //info.renderers[1, 1, 1] = renderer; } else { renderer.old = false; if (!force) return; } // We should generate a mesh GenMeshJob updateJob = new GenMeshJob(this, control, detailLevel); updateJob.setOffset(x, y, z); control.enqueueUpdate(updateJob); }
public void clearSubRenderers(bool clearSelf, VoxelTree control) { if (clearSelf && renderer != null) { //control.enqueueJob(new DropRendererJob(renderer)); renderer.clear(); renderer = null; return; } for (byte xi = 0; xi < CHILD_DIMENSION; ++xi) { for (byte yi = 0; yi < CHILD_DIMENSION; ++yi) { for (byte zi = 0; zi < CHILD_DIMENSION; ++zi) { if (children[xi, yi, zi].GetType() != typeof(Voxel)) ((VoxelBlock)children[xi, yi, zi]).clearSubRenderers(true, control); } } } }
public ApplyMeshJob(VoxelRenderer rend) { this.rend = rend; }