public override void ProcessBlock(float deltaTime, BlockAccessor block) { var entities = block.GetEntityData(); var collider = block.GetSharedComponentData <MeshCollider>(); var hasRigidBody = block.TryGetComponentData(out Span <RigidBody> rbs); var hasScale = block.TryGetComponentData(out Span <Scale> scales); Vector3 defaultScale = Vector3.One; for (int i = 0; i < block.length; i++) { Vector3 scale = defaultScale; if (hasScale) { scale = new Vector3(scales[i].value.x, scales[i].value.y, scales[i].value.z); } Mesh mesh = new Mesh(collider.GetTriangles(), scale, PhysicsSystem.BufferPool); TypedIndex shapeIdx = PhysicsSystem.Simulation.Shapes.Add(mesh); BodyInertia inertia = new BodyInertia(); if (hasRigidBody) { mesh.ComputeOpenInertia(rbs[i].mass, out inertia); } afterUpdateCommands.AddComponent(entities[i], new InternalColliderHandle() { inertia = inertia, shapeIdx = shapeIdx }); } }
public override void ProcessBlock(float deltaTime, BlockAccessor block) { var entities = block.GetEntityData(); var colliders = block.GetReadOnlyComponentData <BoxCollider>(); var hasRigidBody = block.TryGetComponentData(out Span <RigidBody> rbs); var hasScale = block.TryGetComponentData(out Span <Scale> scales); vec3 defaultScale = vec3.Ones; for (int i = 0; i < block.length; i++) { vec3 scale = hasScale ? scales[i].value : defaultScale; Box box = new Box(colliders[i].width * scale.x, colliders[i].height * scale.y, colliders[i].length * scale.z); TypedIndex shapeIdx = PhysicsSystem.Simulation.Shapes.Add(box); BodyInertia inertia = new BodyInertia(); if (hasRigidBody) { box.ComputeInertia(rbs[i].mass, out inertia); } afterUpdateCommands.AddComponent(entities[i], new InternalColliderHandle() { inertia = inertia, shapeIdx = shapeIdx }); } }