Page 1 of 1

Bepu V.2 Scaling question

Posted: Sun Dec 15, 2019 5:29 pm
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));

Re: Bepu V.2 Scaling question

Posted: Sun Dec 15, 2019 6:35 pm
by Norbo
You can get a reference to an existing shape:

Code: Select all

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

Re: Bepu V.2 Scaling question

Posted: Mon Dec 16, 2019 7:18 am
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;

Re: Bepu V.2 Scaling question

Posted: Mon Dec 16, 2019 7:21 pm
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.

Re: Bepu V.2 Scaling question

Posted: Tue Dec 17, 2019 5:07 am
by b1fg2
is there any other way to scale the body when the gameobject is scaled?

Re: Bepu V.2 Scaling question

Posted: Tue Dec 17, 2019 7:16 pm
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.