Collision free painting

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Collision free painting

Postby Bird » Thu Feb 08, 2024 12:10 pm

Hi Julio,

I'm finally getting around to adding collision free painting to my project in Newton 4.0. I'm having some trouble getting the proper contact info from Newton.

Here's a video on what I'm doing ....just dragging a 'phantom" node on top of a 2D static ground plane which is a static mesh body.
https://youtu.be/6sh9e9hkEjg

Here's the log of what's happening in the video. As you can see, for a while everything works correctly and I get 4 contacts where the 'phantom' touches the static ground. The all of a sudden, Newton reports 0 contacts. The log shows the world bounds of the 'phantom' and the static ground.
Code: Select all
63.815504       DEBUG [17700 NewtonPhantom.h->Update:60]        ---------------------------
63.815614       DEBUG [17700 NewtonPhantom.h->Update:72]        phantom min{ -4.05148, -0.0636214, -2.07488}
63.815658       DEBUG [17700 NewtonPhantom.h->Update:73]        phantom max{ -2.92376, 1.06362, -0.944919}
63.815709       DEBUG [17700 NewtonPhantom.h->Update:108]       CONTACTING static_ground
63.815736       DEBUG [17700 NewtonPhantom.h->Update:111]       min{ -5, 0, -5}
63.815759       DEBUG [17700 NewtonPhantom.h->Update:112]       max{ 5, 0, 5}
63.815776       DEBUG [17700 NewtonPhantom.h->Update:126]       CONTACT COUNT: 4
63.815828       DEBUG [15108 NewtonPhantom.h->Update:60]        ---------------------------
63.815900       DEBUG [15108 NewtonPhantom.h->Update:72]        phantom min{ -4.05148, -0.0636214, -2.07488}
63.815966       DEBUG [15108 NewtonPhantom.h->Update:73]        phantom max{ -2.92376, 1.06362, -0.944919}
63.816039       DEBUG [15108 NewtonPhantom.h->Update:108]       CONTACTING static_ground
63.816108       DEBUG [15108 NewtonPhantom.h->Update:111]       min{ -5, 0, -5}
63.816178       DEBUG [15108 NewtonPhantom.h->Update:112]       max{ 5, 0, 5}
63.816251       DEBUG [15108 NewtonPhantom.h->Update:126]       CONTACT COUNT: 4
63.846677       DEBUG [18228 NewtonPhantom.h->Update:60]        ---------------------------
63.846796       DEBUG [18228 NewtonPhantom.h->Update:72]        phantom min{ -4.01191, -0.0632749, -1.75242}
63.846850       DEBUG [18228 NewtonPhantom.h->Update:73]        phantom max{ -2.83238, 1.06327, -0.571427}
63.846940       DEBUG [18228 NewtonPhantom.h->Update:108]       CONTACTING static_ground
63.846988       DEBUG [18228 NewtonPhantom.h->Update:111]       min{ -5, 0, -5}
63.847064       DEBUG [18228 NewtonPhantom.h->Update:112]       max{ 5, 0, 5}
63.847089       DEBUG [18228 NewtonPhantom.h->Update:126]       CONTACT COUNT: 0
63.847127       DEBUG [15108 NewtonPhantom.h->Update:60]        ---------------------------
63.847194       DEBUG [15108 NewtonPhantom.h->Update:72]        phantom min{ -4.01191, -0.0632749, -1.75242}
63.847243       DEBUG [15108 NewtonPhantom.h->Update:73]        phantom max{ -2.83238, 1.06327, -0.571427}
63.847293       DEBUG [15108 NewtonPhantom.h->Update:108]       CONTACTING static_ground
63.847337       DEBUG [15108 NewtonPhantom.h->Update:111]       min{ -5, 0, -5}
63.847381       DEBUG [15108 NewtonPhantom.h->Update:112]       max{ 5, 0, 5}
63.847425       DEBUG [15108 NewtonPhantom.h->Update:126]       CONTACT COUNT: 0
63.877395       DEBUG [15108 NewtonPhantom.h->Update:60]        ---------------------------
63.877569       DEBUG [15108 NewtonPhantom.h->Update:72]        phantom min{ -4.01191, -0.0632749, -1.75242}
63.877631       DEBUG [15108 NewtonPhantom.h->Update:73]        phantom max{ -2.83238, 1.06327, -0.571427}
63.877684       DEBUG [15108 NewtonPhantom.h->Update:108]       CONTACTING static_ground
63.877727       DEBUG [15108 NewtonPhantom.h->Update:111]       min{ -5, 0, -5}
63.877761       DEBUG [15108 NewtonPhantom.h->Update:112]       max{ 5, 0, 5}
63.877795       DEBUG [15108 NewtonPhantom.h->Update:126]       CONTACT COUNT: 0
63.877827       DEBUG [9044 NewtonPhantom.h->Update:60] ---------------------------


And here's the NewtonPhantom class I'm using. Do you seen anything that I might be doing wrong?

Code: Select all
class NewtonPhantom : public ndModel
{
    // NewtonPhantom: A class representing a phantom collision shape in a physics simulation.
    // Phantom shapes can interact with other physics bodies to gather collision data
    // without affecting the physics simulation itself.

 public:
    // Constructor: Initializes a new phantom shape with a given shape and scene.
    NewtonPhantom (ndScene* scene, ndShape* shape, RenderableNode  phantomNode) :
        ndModel(),
        phantomNode(phantomNode),
        phantomShape (shape),
        worldMatrix (ndGetIdentityMatrix()),
        notification (scene)
    {
        // The constructor initializes the phantom shape, world matrix, and notification system.
    }
    ~NewtonPhantom() = default;

 
    // GetContactCount: Returns the number of contact points detected.
    ndInt32 getContactCount() const
    {
        return contactCount;
    }

    // GetContactPoint: Returns the current contact point in the simulation.
    ndVector getContactPoint() const { return contactPoint; }

    // Update: Overridden function that updates the phantom's state in each simulation step.
    void Update (ndWorld* const world, ndFloat32) override
    {
        contactCount = -1;
        ndMatrix phantomPose;
        eigenToNewton (phantomNode->getSpaceTime().worldTransform, phantomPose);
        worldMatrix = phantomPose;

        // Calculates the current Axis-Aligned Bounding Box (AABB) in world space.
        ndVector boxMin, boxMax;
        phantomShape.CalculateAabb (worldMatrix, boxMin, boxMax);

        LOG (DBUG) << "phantom min{ " << boxMin.GetX() << ", " << boxMin.GetY() << ", " << boxMin.GetZ() << "}";
        LOG (DBUG) << "phantom max{ " << boxMax.GetX() << ", " << boxMax.GetY() << ", " << boxMax.GetZ() << "}";
       
        // Notify callback for bodies within the AABB.
        ndBodiesInAabbNotify notifyCallback;
        world->BodiesInAabb (notifyCallback, boxMin, boxMax);

        // Processes each body in the AABB.
        for (ndInt32 i = 0; i < notifyCallback.m_bodyArray.GetCount(); ++i)
        {
            ndBody* const nbody = const_cast<ndBody*> (notifyCallback.m_bodyArray[i]);
            ndBodyKinematic* const kBody = nbody->GetAsBodyKinematic();

            const ndShapeInstance& otherShape = kBody->GetCollisionShape();
            const ndMatrix& otherMatrix = notifyCallback.m_bodyArray[i]->GetMatrix();

            // Ignores collisions with phantom's 'resting on' body
            ndBodyNotify* const notify = nbody->GetNotifyCallback();
            Renderable* const node = static_cast<Renderable*> (notify->GetUserData());

           // if (node && restingOn && node == restingOn.get()) continue;

            // Ignores collisions with itself
            if (otherShape.GetShape() != phantomShape.GetShape())
            {
                if (node)
                {
                    LOG (DBUG) << "CONTACTING " << node->getName();
                    node->getSpaceTime().updateWorldBounds (true);
                    AlignedBox3f box = node->getSpaceTime().worldBound;
                    LOG (DBUG) << "min{ " << box.min().x() << ", " << box.min().y() << ", " << box.min().z() << "}";
                    LOG (DBUG) << "max{ " << box.max().x() << ", " << box.max().y() << ", " << box.max().z() << "}";
               }
                   

                ndFixSizeArray<ndContactPoint, 16> contactBuffer;
                ndVector phantomVelocity = ndVector::m_zero;
                ndVector otherVelocity = ndVector::m_zero;

                ndContactSolver contSolver;
                contSolver.CalculateContacts (&phantomShape, worldMatrix, phantomVelocity, &otherShape, otherMatrix, otherVelocity, contactBuffer, &notification);
                contactCount = contactBuffer.GetCount();
                LOG (DBUG) << "CONTACT COUNT: " << contactCount;
               
                if (contactCount)
                {
                   
                    for (int j = 0; j < contactCount; ++j)
                    {
                        const ndContactPoint& cPnt = contactBuffer[j];
                        contactPoint = cPnt.m_point;
                    }
                }
            }
            else
            {

            }
        }
    }

 private:
    RenderableNode phantomNode = nullptr;
    ndShapeInstance phantomShape;

    ndMatrix worldMatrix;
    ndContactNotify notification;
    ndInt32 contactCount = -1;
    ndVector contactPoint = ndVector (std::numeric_limits<float>::max());
}; // end class NewtonPhantom
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Collision free painting

Postby Bird » Tue May 28, 2024 6:42 pm

Hi Julio,

I know you're busy with other things but is there any chance you can look at this? I'm trying to make a new LightWave plugin and not having collision free painting is a show stopper for me.

If not, can you give me some hint to what the problem is so I can try to fix it my self.

Thanks
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Collision free painting

Postby Julio Jerez » Tue May 28, 2024 10:43 pm

I see if I can make a test demo in the sandbox this week.
Julio Jerez
Moderator
Moderator
 
Posts: 12258
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision free painting

Postby Bird » Wed May 29, 2024 6:17 am

Great. Thank you! Before you do anything, let me try to modify the "phantom_test" I made to see if I can get it to expose the problem .
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Collision free painting

Postby Julio Jerez » Wed May 29, 2024 8:38 am

When you do that, can you also post a concise description of the functionality that you want?
It has been a long time since we did that, and it is just better to start with a fresh slate.
Julio Jerez
Moderator
Moderator
 
Posts: 12258
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision free painting

Postby Julio Jerez » Sat Jun 01, 2024 1:16 pm

ok I added the skeleton for the implementation of the object placement or collision free model.

It just places a single box in the middle of a big plane, like the video shows, and I copied your class.

I have an idea of what you want from pass experiments, but the video is not very clear.
There was an object placement in 3.14, I guess I can check that out, but is just better if you state the expected behavior.
Newton 4 is far better for that sort of things since it exposes all of the internal functionality that was difficult to get in previous versions.
from here I wait for your instructions.
Julio Jerez
Moderator
Moderator
 
Posts: 12258
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision free painting

Postby Bird » Sun Jun 02, 2024 1:15 pm

Okay, sorry for the delay.

I can't get the latest version from Github to work out of the box.
Assertion failed: (0) && "Could not load font file!", file E:\code\OpenSource\bleedingEdgeNewton\newton-dynamics\newton-4.00\thirdParty\imgui\imgui_draw.cpp, line 2151
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Collision free painting

Postby Julio Jerez » Sun Jun 02, 2024 1:54 pm

when to run cmake, in visual studio you have to run Install by clicking in the solution explorer.
this will copy the assets to the build folder.
Julio Jerez
Moderator
Moderator
 
Posts: 12258
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision free painting

Postby Bird » Sun Jun 02, 2024 2:03 pm

Here's a better video to show what I'm trying to do.
https://www.youtube.com/watch?v=IyI39oo ... eyworksInc

First I create a "Phantom" body that doesn't interact with other bodies in the scene but receives contact information as it moves along. I make the phantom "unseen by rays" so that the "pick ray" from the mouse goes through it and intersects with the underlying body. Then I use the ray hit point and underlying surface normal to place the phantom on top of the other objects in the scene. While dragging the phantom around, I'm always querying the contact information and when it is not contacting anything except the underlying body then I generate a new instance that doesn't intersect any other body except the underlying one.

In 3.14, you made this work for me even when the engine is not running. That way the artist could create his scene before running the physics simulation. That doesn't seem implemented in 4.0 though. I would love to have that feature again in 4.0 if it's possible. Thanks!
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Collision free painting

Postby Bird » Sun Jun 02, 2024 2:05 pm

Julio Jerez wrote:when to run cmake, in visual studio you have to run Install by clicking in the solution explorer.
this will copy the assets to the build folder.


Okay, working now. Thanks
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Collision free painting

Postby Bird » Sat Jun 08, 2024 9:26 am

Hi Julio,

I sent a pull request with a modified version of the object placement demo. I think I created a scene with a flat plane floor and the NewtonPhantom body centered a the origin. If I've done this correctly, I would expect to see 4 contact points but instead there is 0.
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Collision free painting

Postby Bird » Sat Jun 08, 2024 9:53 am

Never mind that last post. :)

I think I see that problem I'm having. If I move the Phantom cube up so it's resting on the flat plane then no contact is registered.

So if you modify the pull request to move the phantom up like this. There is no contact notification
Code: Select all
// create a Phantom model with a box shape that rests on the flat ground
NewtonPhantom* const phantom = new NewtonPhantom(scene->GetWorld()->GetScene());
ndMatrix phantomMatrix = ndGetIdentityMatrix();
phantomMatrix.m_posit.m_y = 0.5f;
phantom->transform(phantomMatrix);
ndSharedPtr<ndModel> phantomPtr(phantom);
scene->GetWorld()->AddModel(phantomPtr);
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Collision free painting

Postby Julio Jerez » Tue Jun 18, 2024 12:56 pm

alright I merge the pull request and I build it.

I quickly run it and and other than building, I assume, it is not supposed to do anything yet?
I will start implementing the functionality tonight.

I will compare to how it was in 3.14 and see how close It can come too.

I suppose I will have to add a collision only queried. that should not be hard to add.
Julio Jerez
Moderator
Moderator
 
Posts: 12258
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision free painting

Postby Bird » Tue Jun 18, 2024 1:10 pm

Great. Thanks for looking into this!

Yeah, I think I messed up the pull request but what I was trying to show was that a cube lying on a flat plane doesn't generate any contact notification like I was expecting it too.
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: Collision free painting

Postby Julio Jerez » Tue Jun 18, 2024 2:00 pm

what I am thinking is to add a core function, like in 3.14 that perform a collision query, that stop at the ndModel update.

from there the app can execute the call.

in your case for example you should have two loops.
one when you execute the collision for object placement, no physics, that run in on some kind of edit mode.
The another, a loop just like there is now, that does the full update.

the rest is to add the local mini solver they check if a body can be place in the scene. we already have one in 3.14 but we can probably improve on that.

how does that sound?
Julio Jerez
Moderator
Moderator
 
Posts: 12258
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests