Table of Contents

Class VoxelDestructor

Namespace
VoxelPlayground.Destruction
Assembly
GamePlay.dll
public class VoxelDestructor : MonoBehaviour, IVoxelDestructible
Inheritance
object
VoxelDestructor
Implements
Extension Methods

Fields

bindPosBone_deprecated

[HideInInspector]
public Transform bindPosBone_deprecated

Field Value

Transform

blackList

public List<Collider> blackList

Field Value

List<Collider>

EnableCreateFragmentObjects

public static bool EnableCreateFragmentObjects

Field Value

bool

entityConnectors

[HideInInspector]
public List<EntityConnector> entityConnectors

Field Value

List<EntityConnector>

indestructiable

public bool indestructiable

Field Value

bool

invincibleCollision

[NonSerialized]
[ShowInInspector]
public bool invincibleCollision

Field Value

bool

isFireImmune

public bool isFireImmune

Field Value

bool

isFortified

public bool isFortified

Field Value

bool

isPoisonImmune

public bool isPoisonImmune

Field Value

bool

massDensity

public float massDensity

Field Value

float

onCollisionEnterAction

public Action<Collision> onCollisionEnterAction

Field Value

Action<Collision>

OnExplodeToParts

public Action OnExplodeToParts

Field Value

Action

OnFragmentCreated

public Action<VoxelDestructor, VoxelDestructor, NativeSlice<int>> OnFragmentCreated

Field Value

Action<VoxelDestructor, VoxelDestructor, NativeSlice<int>>

ownerEntity

public Entity ownerEntity

Field Value

Entity

prefabName

public string prefabName

Field Value

string

preventsImpactDestructOther

public bool preventsImpactDestructOther

Field Value

bool

protector

public VoxelDestructor protector

Field Value

VoxelDestructor

rb

public Rigidbody rb

Field Value

Rigidbody

registerFragmentEvents

[InfoBox("Use for non-character big object", InfoMessageType.Info, null)]
public bool registerFragmentEvents

Field Value

bool

unyielding

public bool unyielding

Field Value

bool

voxelData

[InfoBox("voxelData,ownerEntity,rigidBody会自己找到引用", InfoMessageType.Info, null)]
public VoxelVolume voxelData

Field Value

VoxelVolume

Properties

IsHeatDissolved

public bool IsHeatDissolved { get; }

Property Value

bool

IsIndestructible

public bool IsIndestructible { get; }

Property Value

bool

VoxelData

public VoxelVolume VoxelData { get; }

Property Value

VoxelVolume

Methods

BoxSweepClear(Vector3, Vector3, Vector3, Matrix4x4, VoxelChunk, bool, float)

Clears voxels within a box-shaped area that sweeps between two points.

public void BoxSweepClear(Vector3 end1, Vector3 end2, Vector3 halfBox, Matrix4x4 boxLocalToWorld, VoxelChunk voxelChunkToClears, bool isByEasyKinematicPenetration = false, float hardnessCap = -1)

Parameters

end1 Vector3

World space position of the first endpoint of the sweep

end2 Vector3

World space position of the second endpoint of the sweep

halfBox Vector3

Half-extents of the box in local box space

boxLocalToWorld Matrix4x4

Matrix that transforms from box local space to world space

voxelChunkToClears VoxelChunk

The specific voxel chunk to clear

isByEasyKinematicPenetration bool

if true (i.e. damager is e.g. Mech, GiantZombie), then creates lesser Fragments since these kind of damage always produce too much frags that make phys slow

hardnessCap float

ControlledTick()

public void ControlledTick()

CylinderClear(Vector3, Vector3, float)

public void CylinderClear(Vector3 end1, Vector3 end2, float radius)

Parameters

end1 Vector3
end2 Vector3
radius float

DemolishAreaSphere(Vector3, float, float, Vector3, float, int, float, Action<int>)

Demolishes a spherical area of the voxel object, create fragments from demolished area.

public void DemolishAreaSphere(Vector3 center, float radius, float force = 0, Vector3 explodeDirection = default, float spreadAngle = 3.14159, int maxFragments = 30, float hardnessCap = 8, Action<int> onModified = null)

Parameters

center Vector3

World space position of the sphere center

radius float

Radius of the sphere in world space

force float

Optional force to apply to created fragments

explodeDirection Vector3

Optional direction for the explosion force

spreadAngle float

Optional angle to spread the explosion force, in radians. Default is PI (180 degrees). If spreadAngle is PI, the force will be applied in a random direction. If spreadAngle is 0, the force will be applied in the direction of the explosion.

maxFragments int
hardnessCap float

won't modify if the voxel's hardness >= hardnessCap (fac=0), easier modify if voxel's hardness is lesser than hardnessCap

onModified Action<int>

DemolishAtRandomPoint(float, VoxelVolume)

public Vector3 DemolishAtRandomPoint(float radius, VoxelVolume _voxelData = null)

Parameters

radius float
_voxelData VoxelVolume

Returns

Vector3

DissolveContactPlane(Vector3, Vector3)

Construct a plane, center at hitPoint and face normal; empty everything under this plane

This should only be used for COLLAPSE TO GROUND, but not for other usecases like hand hit

public void DissolveContactPlane(Vector3 hitPoint, Vector3 normal)

Parameters

hitPoint Vector3

hit point

normal Vector3

hit impulse direction

ExplodeToPartsAndDestroy(VoxelVolume, MonoBehaviour, bool, bool)

public static void ExplodeToPartsAndDestroy(VoxelVolume mc, MonoBehaviour coroutineCarrier, bool specialEffect = false, bool randomRemoval = true)

Parameters

mc VoxelVolume
coroutineCarrier MonoBehaviour
specialEffect bool
randomRemoval bool

ExplodeToPartsAndDestroySelf(bool, bool)

[Button("Test ExplodeToParts")]
public void ExplodeToPartsAndDestroySelf(bool specialEffect = false, bool randomRemoval = true)

Parameters

specialEffect bool
randomRemoval bool

IncrementalHeatDissolve()

public void IncrementalHeatDissolve()

Init(VoxelVolume, Entity)

public void Init(VoxelVolume voxelData, Entity entity)

Parameters

voxelData VoxelVolume
entity Entity

IOnFragmentCreated(IVoxelDestructible, IVoxelDestructible, NativeSlice<int>)

public void IOnFragmentCreated(IVoxelDestructible source, IVoxelDestructible target, NativeSlice<int> fragmentIndices)

Parameters

source IVoxelDestructible
target IVoxelDestructible
fragmentIndices NativeSlice<int>

IsCharacter()

public bool IsCharacter()

Returns

bool

ModifyAtPos(Vector3, float, Action<int>)

public void ModifyAtPos(Vector3 center_worldSpace, float radius, Action<int> onModified = null)

Parameters

center_worldSpace Vector3
radius float
onModified Action<int>

ModifyAtPos(Vector3, float, float, Vector3, float, int, float, Action<int>)

public void ModifyAtPos(Vector3 center_worldSpace, float radius, float force = 0, Vector3 explodeDirection = default, float spreadAngle = 3.14159, int maxFragments = 20, float hardnessCap = -1, Action<int> onModified = null)

Parameters

center_worldSpace Vector3
radius float
force float
explodeDirection Vector3
spreadAngle float
maxFragments int
hardnessCap float
onModified Action<int>

ModifyAtRandomPoint(float)

public Vector3 ModifyAtRandomPoint(float radius = 0.13)

Parameters

radius float

Returns

Vector3

ModifyPropertyAtPos(Vector3, float, Property, int)

public void ModifyPropertyAtPos(Vector3 center_worldSpace, float radius, PointDataV2.Property property = Property.Water, int step = 1)

Parameters

center_worldSpace Vector3
radius float
property PointDataV2.Property
step int

ModifyToBulletHoleColor(float3, float)

public PointDataV2 ModifyToBulletHoleColor(float3 center_WS, float radius_WS = 0.01875)

Parameters

center_WS float3
radius_WS float

Returns

PointDataV2

OnFragmentDetected(NativeList<PointDataV2>, NativeList<int3>, NativeList<int>, NativeSlice<int>, List<NativeSlice<int>>, NativeArray<bool>, bool, VoxelVolume)

public void OnFragmentDetected(NativeList<PointDataV2> fragsSource, NativeList<int3> boundsSource, NativeList<int> solidCountsSource, NativeSlice<int> mainIslandIdSource, List<NativeSlice<int>> islandsSource, NativeArray<bool> unyieldingFragSource, bool unyieldingMainland, VoxelVolume mc)

Parameters

fragsSource NativeList<PointDataV2>
boundsSource NativeList<int3>
solidCountsSource NativeList<int>
mainIslandIdSource NativeSlice<int>
islandsSource List<NativeSlice<int>>
unyieldingFragSource NativeArray<bool>
unyieldingMainland bool
mc VoxelVolume

PlaneCut(Vector3, Vector3, Vector3)

plane cut a voxel

YEnd ++++++++ ++++++++ ++++++++ ++++++++ ++++++++ O XEnd

public void PlaneCut(Vector3 originWorldSpace, Vector3 xDirectionWorldSpace, Vector3 yDirectionWorldSpace)

Parameters

originWorldSpace Vector3

Above O point in world space

xDirectionWorldSpace Vector3

Above XEnd-O vector in worldspace

yDirectionWorldSpace Vector3

Above YEnd-O vector in worldspace

ProjectTexture(Vector3, float, NativeArray<Color32>, int, Vector3, float, SplatType, float)

public void ProjectTexture(Vector3 center, float radius, NativeArray<Color32> projectTexture, int textureDim, Vector3 projectDirection, float projectDepth, SplatType splatType = SplatType.Blood, float opacity = 1)

Parameters

center Vector3
radius float
projectTexture NativeArray<Color32>
textureDim int
projectDirection Vector3
projectDepth float
splatType SplatType
opacity float

RaycastWithProtector(Vector3, Vector3, ref RaycastHitVoxel)

public bool RaycastWithProtector(Vector3 origin, Vector3 direction, ref RaycastHitVoxel raycastHitVoxel)

Parameters

origin Vector3
direction Vector3
raycastHitVoxel RaycastHitVoxel

Returns

bool

RestoreColorStep()

public void RestoreColorStep()

ScreenSpaceLineClear(Vector2, Vector2, Matrix4x4, VoxelChunk, float)

public void ScreenSpaceLineClear(Vector2 screenSpacePos1, Vector2 screenSpacePos2, Matrix4x4 worldToScreen, VoxelChunk chunkToClear, float thicknessInPixel = 8)

Parameters

screenSpacePos1 Vector2
screenSpacePos2 Vector2
worldToScreen Matrix4x4
chunkToClear VoxelChunk
thicknessInPixel float

SetColliderIgnore(Collider, bool)

public void SetColliderIgnore(Collider collider, bool ignore)

Parameters

collider Collider
ignore bool

SetUnyieldingAndIskinematic(bool)

public void SetUnyieldingAndIskinematic(bool value)

Parameters

value bool

ShockWaveCrack(Vector3, Vector3, float, CrackType)

Generate cracks inside voxels There are two types of cracks, depends on crackType param

  • CrackType.SurfaceShatter, generate a spider web like crack, on hit point surface, image you throw a pebble onto glass window, it generate crack on surface
  • CrackType.VerticalCrack, generate a vertical crack on side of hit plane, image you throw a rock onto ground, crack does not appear on contact plane, but on its side
public void ShockWaveCrack(Vector3 hitPoint, Vector3 hitDirection, float radiusWorldSpace, VoxelDestructor.CrackType crackType)

Parameters

hitPoint Vector3

collision point

hitDirection Vector3

collision impulse direction. for CrackType.SurfaceShatter, it is the plane normal. for CrackType.VerticalCrack, it is where crack grows

radiusWorldSpace float

crack affected size in world space unit

crackType VoxelDestructor.CrackType

see above explanation and CrackType enum docs

ShockWavePeelOffPiece(float, int)

Generate some random holes all around the volume

public void ShockWavePeelOffPiece(float pieceRadiusWorldSpace, int pieceCounts = 10)

Parameters

pieceRadiusWorldSpace float

max radius of piece in world space, actual piece will range in half of this radius to radius

pieceCounts int

num of holes to remove

SmashPartInsideVolume(Vector3, Vector3, Matrix4x4, out GameObject)

For smasher, voxels inside a volume of the original marching cube will be emptied, and flatte to make an new object

+Z +Y | / | / |/ C-------- +X

public void SmashPartInsideVolume(Vector3 smashVolumeStartWorld, Vector3 smashVolumeWorldSize, Matrix4x4 smashVolumeLocalToWorld, out GameObject smashedFragment)

Parameters

smashVolumeStartWorld Vector3

Above C position, volume bottom center

smashVolumeWorldSize Vector3

x, y, z: in above illustration

smashVolumeLocalToWorld Matrix4x4

x, y, z: in above illustration

smashedFragment GameObject

SphereSweepClear(Vector3, Vector3, float)

public void SphereSweepClear(Vector3 end1World, Vector3 end2World, float radiusWorld)

Parameters

end1World Vector3
end2World Vector3
radiusWorld float