Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Batch Explode(Vector3 position, float explosionRadius, int valueFilter, Exploder.ExplodeValueFilterOperation valueFilterOperation)
- {
- Batch batch = new Batch(this);
- Color tint = Material.GetColor("_Tint");
- Matrix4x4 transformMatrix = transform.worldToLocalMatrix;
- position += (transform.rotation * (Pivot));
- float explosionRadius2 = explosionRadius * explosionRadius;
- for (float x = position.x - explosionRadius; x <= position.x + explosionRadius; x += VoxelSize * 0.5f)
- for (float y = position.y - explosionRadius; y <= position.y + explosionRadius; y += VoxelSize * 0.5f)
- for (float z = position.z - explosionRadius; z <= position.z + explosionRadius; z += VoxelSize * 0.5f)
- {
- Vector3 checkPos = new Vector3(x, y, z);
- float distance = (checkPos - position).sqrMagnitude;
- if (distance <= explosionRadius2)
- {
- Vector3 localPos = transformMatrix.MultiplyPoint3x4(checkPos); //transform.InverseTransformPoint(pos);
- //if (!Frames[CurrentFrame].IsLocalPositionInBounds(localPos)) continue;
- int testX = (int)(localPos.x / VoxelSize);
- int testY = (int)(localPos.y / VoxelSize);
- int testZ = (int)(localPos.z / VoxelSize);
- if (testX < 0 || testY < 0 || testZ < 0 || testX >= XSize || testY >= YSize || testZ >= ZSize) continue;
- if (Frames[CurrentFrame].Voxels[testX + XSize * (testY + YSize * testZ)].Active &&
- FilterExplosion(Frames[CurrentFrame].Voxels[testX + XSize * (testY + YSize * testZ)].Value, valueFilter, valueFilterOperation) &&
- distance <= explosionRadius2)
- {
- Voxel v = Frames[CurrentFrame].Voxels[testX + XSize * (testY + YSize * testZ)];
- v.Color *= tint;
- batch.Add(v, testX, testY, testZ, checkPos - (transform.rotation * (Pivot)));
- SetVoxelStateAtArrayPosition(testX, testY, testZ, VoxelState.Hidden);
- }
- }
- }
- return batch;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement