public VoxelRenderer(Index index, Tree control) : this(index, control, new Vector3( index.x * control.sizes[index.depth], index.y * control.sizes[index.depth], index.z * control.sizes[index.depth])) { }
protected void apply(Application app, VoxelBlock block, Index pos) { Index cornerChild = pos.getChild(); for(byte c = 0; c<VoxelBlock.CHILD_COUNT; ++c) { // TODO: use min and max to reduce number of values considered Index childPos = cornerChild.getNeighbor(c); Action action = checkMutation(app, childPos); // check if voxel is outside of modifier area if (!action.modify) continue; // check if voxel is inside of masked area Action maskAction = checkMasks(app.tree, childPos); if (!maskAction.modify) continue; // recurse or set full voxel if (childPos.depth < app.tree.maximumDetail && (maskAction.doTraverse || action.doTraverse)) apply(app, block.expand(childPos.xLocal, childPos.yLocal, childPos.zLocal), childPos); else block.children[childPos.xLocal, childPos.yLocal, childPos.zLocal] = mutate(app, childPos, action, block.children[childPos.xLocal, childPos.yLocal, childPos.zLocal].toVoxel()); // update meshes if appropriate if (childPos.depth == app.tree.maximumDetail - VoxelRenderer.VOXEL_COUNT_POWER) { UpdateCheckJob job = new UpdateCheckJob(block, app.tree, childPos.depth); job.setOffset((byte)childPos.x, (byte)childPos.y, (byte)childPos.z); job.setForce(true); app.jobs.Add(job); } } }
protected Action checkMasks(OcTree tree, Index p) { // skip if no masks if (tree.masks == null) return new Action(false, true); // check against each mask int voxelSize = 1 << (tree.maximumDetail - p.depth); Action action = new Action(false, true); foreach (VoxelMask mask in tree.masks) { if (mask.active) { // calculate relative position int comparison = (mask.maskAbove)? compareToVoxel((int)mask.yPosition, (int)p.y, voxelSize): -compareToVoxel((int)mask.yPosition, (int)p.y, voxelSize); // evaluate action based on relative position if (comparison == 0) action.doTraverse = true; else if (comparison < 0) return new Action(false, false); } } return action; }
public override LocalAction checkMutation(LocalApplication app, Index p, Vector3 diff, float voxelSize) { CubeApp cApp = (CubeApp)app; CubeAction action = new CubeAction(); if (p.depth >= app.tree.maximumDetail) voxelSize *= 0.5f; action.percentInside = 1; bool outside = false; bool inside = true; action.percentInside *= 1 - (2 - percentOverlapping(diff.x, cApp.halfDimension.x, voxelSize, ref outside, ref inside) - percentOverlapping(-diff.x, cApp.halfDimension.x, voxelSize, ref outside, ref inside)); if (outside) return action; action.percentInside *= 1 - (2 - percentOverlapping(diff.y, cApp.halfDimension.y, voxelSize, ref outside, ref inside) - percentOverlapping(-diff.y, cApp.halfDimension.y, voxelSize, ref outside, ref inside)); if (outside) return action; action.percentInside *= 1 - (2 - percentOverlapping(diff.z, cApp.halfDimension.z, voxelSize, ref outside, ref inside) - percentOverlapping(-diff.z, cApp.halfDimension.z, voxelSize, ref outside, ref inside)); if (outside) return action; action.modify = true; if (!overwriteShape || !inside) action.doTraverse = true; return action; }
public override LocalAction checkMutation(LocalApplication app, Index p, Vector3 diff, float voxelSize) { LineApplication lApp = (LineApplication) app; Vector3 cp = closestPointToPath(lApp.points, diff); Vector3 virtualDiff = diff - cp; LocalAction action = child.checkMutation(((LineApplication)app).childApp, p, virtualDiff, voxelSize); action.diff = virtualDiff; return action; }
protected override Action checkMutation(Application app, Index p) { LocalApplication lApp = (LocalApplication)app; float voxelSize = calculateVoxelSize(app, p); Vector3 diff = calculateDiff(lApp.position, p, voxelSize); LocalAction action = checkMutation(lApp, p, diff, voxelSize); action.voxelSize = voxelSize; return action; }
protected override Voxel mutate(Application app, Index pos, Action action, Voxel original) { BlurApp bApp = (BlurApp)app; BlurAction bAction = (BlurAction)action; float dis = Mathf.Sqrt(bAction.disSqr); float actualStrength = strength * (1 - (dis / bApp.radius)); if (actualStrength <= 0) return original; byte newOpacity = calculateOpacity(bApp.original, pos.x - app.min.x, pos.y - app.min.y, pos.z - app.min.z, actualStrength); return new Voxel(original.averageMaterialType(), newOpacity); }
public override Voxel mutate(LocalApplication app, Index p, LocalAction action, Voxel original) { CubeAction cAction = (CubeAction)action; byte newOpacity = (byte)((original.averageOpacity() * (1 - cAction.percentInside) + value.averageOpacity() * (cAction.percentInside))); byte newSubstance = original.averageMaterialType(); if (overwriteSubstance && cAction.percentInside > 0.5) newSubstance = value.averageMaterialType(); if (!overwriteShape) newOpacity = original.averageOpacity(); return new Voxel(newSubstance, newOpacity); }
public VoxelRenderer(Index index, Tree control, Vector3 localPosition) { this.index = index; this.position = localPosition; this.control = control; size = 0; ++rendCount; VERTS = new Vector3[0]; NORMS = new Vector3[0]; TRIS = new int[0]; lock(control) { control.renderers[index] = this; } }
public override Voxel mutate(LocalApplication app, Index p, LocalAction action, Voxel original) { SphereApp sApp = (SphereApp)app; SphereAction sAction = (SphereAction)action; float dis = Mathf.Sqrt(sAction.disSqr); float percentInside = Mathf.Min((sAction.maxRadius -dis) /(sAction.maxRadius -sAction.minRadius), 1); byte newOpacity = (byte)(original.averageOpacity() * (1 -percentInside) + value.averageOpacity() * percentInside); byte newSubstance = original.averageMaterialType(); if (overwriteSubstance && (dis < sApp.radius || percentInside > 0.5f)) newSubstance = value.averageMaterialType(); if (!overwriteShape) newOpacity = original.averageOpacity(); return new Voxel(newSubstance, newOpacity); }
protected override Action checkMutation(Application app, Index pos) { BlurApp bApp = (BlurApp)app; BlurAction action = new BlurAction(); float voxelSize = LocalMutator.calculateVoxelSize(app, pos); Vector3 diff = LocalMutator.calculateDiff(bApp.position, pos, voxelSize); action.disSqr = diff.sqrMagnitude; float maxRadius = bApp.radius + voxelSize; float maxRadSqr = maxRadius * maxRadius; if (action.disSqr > maxRadSqr) return action; action.doTraverse = true; action.modify = true; return action; }
public override LocalAction checkMutation(LocalApplication app, Index p, Vector3 diff, float voxelSize) { SphereApp sApp = (SphereApp)app; SphereAction action = new SphereAction(); action.disSqr = diff.sqrMagnitude; action.maxRadius = sApp.radius + voxelSize; float maxRadSqr = action.maxRadius * action.maxRadius; if (action.disSqr > maxRadSqr) return action; action.modify = true; action.minRadius = Mathf.Max(0, sApp.radius - voxelSize); float minRadSqr = action.minRadius * action.minRadius; if (!overwriteShape || action.disSqr >= minRadSqr) action.doTraverse = true; return action; }
public override Voxel mutate(LocalApplication app, Index p, LocalAction action, Voxel original) { SphereApp sApp = (SphereApp)app; SphereAction sAction = (SphereAction)action; float dis = Mathf.Sqrt(sAction.disSqr); byte newOpacity = (dis <= sAction.minRadius) ? value.averageOpacity() : (byte)((original.averageOpacity() * (dis - sAction.minRadius) + value.averageOpacity() * (sAction.maxRadius - dis)) / 2); byte newSubstance = original.averageMaterialType(); if (newOpacity >= 2 * original.averageOpacity() || (overwriteSubstance && dis < sApp.radius)) newSubstance = value.averageMaterialType(); if (!overwriteShape) newOpacity = original.averageOpacity(); return new Voxel(newSubstance, newOpacity); }
public abstract LocalAction checkMutation(LocalApplication app, Index p, Vector3 diff, float voxelSize);
public abstract Voxel mutate(LocalApplication app, Index p, LocalAction action, Voxel original);
public override void putInArray(ref Voxel[,,] array, Index position, uint xMin, uint yMin, uint zMin, uint xMax, uint yMax, uint zMax) { uint size = 1u << (VoxelBlock.CHILD_COUNT_POWER *position.depth); uint xStart = (uint)Mathf.Max(position.x, xMin) -xMin; uint xEnd = (uint)Mathf.Min(position.x +size, xMax) -xMin; uint yStart = (uint)Mathf.Max(position.y, yMin) -yMin; uint yEnd = (uint)Mathf.Min(position.y +size, yMax) -yMin; uint zStart = (uint)Mathf.Max(position.z, zMin) -zMin; uint zEnd = (uint)Mathf.Min(position.z +size, zMax) -zMin; for(uint xi=xStart; xi<xEnd; ++xi) { for(uint yi=yStart; yi<yEnd; ++yi) { for(uint zi=zStart; zi<zEnd; ++zi) { array[xi, yi, zi] = this; } } } }
protected override Voxel mutate(Application app, Index p, Action action, Voxel original) { return mutate((LocalApplication)app, p, (LocalAction)action, original); }
public override Voxel mutate(LocalApplication app, Index p, LocalAction action, Voxel original) { return child.mutate(((LineApplication)app).childApp, p, action, original); }
protected abstract Action checkMutation(Application app, Index pos);
public override void putInArray(ref Voxel[,,] array, Index position, uint xMin, uint yMin, uint zMin, uint xMax, uint yMax, uint zMax) { uint size = 1u << (CHILD_COUNT_POWER *position.depth -CHILD_COUNT_POWER); for(uint xi=0; xi<CHILD_DIMENSION; ++xi) { uint xPos = position.x +xi *size; if (xPos > xMax || xPos +size < xMin) continue; for (uint yi=0; yi<CHILD_DIMENSION; ++yi) { uint yPos = position.y +yi *size; if (yPos > yMax || yPos +size < yMin) continue; for (uint zi=0; zi<CHILD_DIMENSION; ++zi) { uint zPos = position.z +zi *size; if (zPos > zMax || zPos +size < zMin) continue; children[xi, yi, zi].putInArray(ref array, new Index((byte)(position.depth -1), xPos, yPos, zPos), xMin, yMin, zMin, xMax, yMax, zMax); } } } }
public override VoxelHolder get(Index i) { return get(i.depth, i.x, i.y, i.z); }
public override VoxelHolder get(Index i) { return this; }
protected abstract Voxel mutate(Application app, Index pos, Action action, Voxel original);
public static float calculateVoxelSize(Application app, Index p) { return 1 << (app.tree.maxDetail - p.depth); }
public static Vector3 calculateDiff(Vector3 position, Index p, float voxelSize) { Vector3 diff = new Vector3(p.x + 0.5f, p.y + 0.5f, p.z + 0.5f) * voxelSize -position; return diff; }
public abstract VoxelHolder get(Index i);
public VoxelRenderer getRenderer() { Index i = new Index(detailLevel, xOff, yOff, zOff); return control.getRenderer(i); }
public abstract void putInArray(ref Voxel[,,] array, Index position, uint xMin, uint yMin, uint zMin, uint xMax, uint yMax, uint zMax);