예제 #1
0
        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 mesh       = block.GetSharedComponentData <MeshRenderer>();
            var boxes      = block.GetComponentData <BoundingBox>();
            var objToW     = block.GetReadOnlyComponentData <ObjectToWorld>();
            var initialBox = mesh.mesh.bounds;

            for (int i = 0; i < block.length; i++)
            {
                boxes[i].value = initialBox.TransformAabb(objToW[i].model);
            }
        }