Bepu V.2 Scaling question

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

Bepu V.2 Scaling question

Post by b1fg2 »

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: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Bepu V.2 Scaling question

Post by Norbo »

You can get a reference to an existing shape:

Code: Select all

ref var shape = ref Simulation.Shapes.GetShape<Sphere>(shapeIndex);
b1fg2
Posts: 19
Joined: Mon Sep 24, 2018 3:36 pm

Re: Bepu V.2 Scaling question

Post by b1fg2 »

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: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Bepu V.2 Scaling question

Post by Norbo »

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: 19
Joined: Mon Sep 24, 2018 3:36 pm

Re: Bepu V.2 Scaling question

Post by b1fg2 »

is there any other way to scale the body when the gameobject is scaled?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Bepu V.2 Scaling question

Post by Norbo »

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