Bepu V.2 Scaling question

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
b1fg2
Posts: 16
Joined: Mon Sep 24, 2018 3:36 pm

Bepu V.2 Scaling question

Post by b1fg2 » Sun Dec 15, 2019 5:29 pm

Is anyone can guide me about how to scale a body that already added in the world in runtime? Or i have too keep on recreate new shape and body when i scale, and addinto simulation again?

Code: Select all

 
 	var _shape = new Sphere(radius);
            _shape.ComputeInertia(mass, out var _bodyInertia);
            var _rigidPose = new RigidPose(new Vector3(0,0,0));
            var _body = BodyDescription.CreateDynamic(_rigidPose, _bodyInertia, new CollidableDescription(Physic.Shapes.Add((Sphere)_shape), margin), new BodyActivityDescription(0.01f));

Norbo
Site Admin
Posts: 4835
Joined: Tue Jul 04, 2006 4:45 am

Re: Bepu V.2 Scaling question

Post by Norbo » Sun Dec 15, 2019 6:35 pm

You can get a reference to an existing shape:

Code: Select all

ref var shape = ref Simulation.Shapes.GetShape<Sphere>(shapeIndex);

b1fg2
Posts: 16
Joined: Mon Sep 24, 2018 3:36 pm

Re: Bepu V.2 Scaling question

Post by b1fg2 » Mon Dec 16, 2019 7:18 am

i try it in update loop, it become very laggy.

Code: Select all

ref var shape = ref Simulation.Shapes.GetShape<Sphere>(shapeIndex);
shape.Radius +=0.01f;

Norbo
Site Admin
Posts: 4835
Joined: Tue Jul 04, 2006 4:45 am

Re: Bepu V.2 Scaling question

Post by Norbo » Mon Dec 16, 2019 7:21 pm

That gives a direct memory reference, so changing the radius isn't directly responsible for the slowdown. There might be some consequence of increased size that's causing issues- if the sphere gets so large that it's colliding with a million objects, for example.

b1fg2
Posts: 16
Joined: Mon Sep 24, 2018 3:36 pm

Re: Bepu V.2 Scaling question

Post by b1fg2 » Tue Dec 17, 2019 5:07 am

is there any other way to scale the body when the gameobject is scaled?

Norbo
Site Admin
Posts: 4835
Joined: Tue Jul 04, 2006 4:45 am

Re: Bepu V.2 Scaling question

Post by Norbo » Tue Dec 17, 2019 7:16 pm

Scaling boils down to a change in the shape, so there's no option other than GetShape<T> or remove/readd. There are no special hooks for connecting to external events or anything like that.

Post Reply