Unity plugin progress?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Unity plugin progress?

Postby Julio Jerez » Fri Feb 24, 2017 7:38 pm

excelent, I modified function addForce to take three floats. so it should be all fine. now.

what is the meaning of keyword internal?

Code: Select all
    public bool m_isScene { get; set; }
    internal dNewtonBody m_body = null;
    private NewtonBodyCollision m_collision = null; 
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Fri Feb 24, 2017 7:57 pm

Internal members and functions should be visible only to other classes inside the same assembly. NewtonPlugin in this case. Havent checked if that works yet. If it does unity user scripts shouldnt see those members
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Sun Feb 26, 2017 12:41 am

Ok I added first pass at Terrain collision.
The terrain in unity is heavily dependent is the internal of their physics engine for editing in the editor.

I made so that it refresh in real time but is not very efficient because Unity does not supports dirty rectangle elevation updates, so I end up destroy and recreating the retain each time a change happens.
Maybe I can make a lithe better by adding an update function to the current terrain, rather that what is does now, but for now this work and we can always improve it.

I will also add catching the a render mesh rather that using newton debug display because drawing line in unity is horrendously slow. you can see that but making the terrain a lot bigger.

but all in all we now have height field collision that matches Unity terrains.
please see if this is ok.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Sun Feb 26, 2017 10:17 am

Terrain seems to be working fine. :D

Got a weird error when I added my bodyspawner script and ran it.
Got an error in the onAABBOverlap function claiming that collider0 was null.

Unfortunately I didn't save the scene so I need to recreate the scene again and see what went wrong.
I probably just missed something but I need to make sure there isn't a nasty bug.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Sun Feb 26, 2017 11:17 am

Please try to recreates again and check it may I can find what is wrong.

I added some of the condition that Unity inforce on terrains,
basically Terrain in unity can no be scaled, rotated or have local transforms.

Newton support all of the but if we allow for that then some body can apply those fumtionality because they are part of the common shape properties and they will have a shape that does not math unity.

I also filter the isTrigger option, because in newton only convex shapes can serve as trigger, so these are overriten as false each time.
is kind of a poor man way of graying out and option in the editor.

last thing I did was that I was going to write an elaborated scheme to catch the Gizmo, but I realize the since the shape math the unit visual mesh, then the using we only nee a flag that say show Gizmo.
I set it to true by default. that way the user can use for aligning of those shapes that do allow for scale and local transformations.

Now I will start adding the scene collision.
This is important for performance, we do no what world to be clustered with tons of static objects just because the are separate mesh.

The way I envisioned it is that we make a similar to compound, the user simple assign collision shape
to the Gameobject and made a child of another game object with a static body.

that way they can make world as complex as they like with out affecting performance and memory too much.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Sun Feb 26, 2017 11:24 am

I probably just missed something but I need to make sure there isn't a nasty bug.

That something we need to address, we are leaving too many possibility open for the game to crash.
building a physics scene like building a house of cards, it require many steps, for example adding a body without collision, or no assigning the word owner.

for this case we need to at leas add a log say what is wrong, but we also need to add a default behavior so that the game does no crash.

as the plugin become more elaborated these thing become more tedious, and it is bad that for example a person is working on a scene, try to test it and the editor crashes and the person lose his or her work.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Sun Feb 26, 2017 1:10 pm

I made the terrain mush bigger, applied a base texture and air brushed a lithe, and seem to work quiet nice, no effect in performance so far.

Unity support airbrushing terrain with mesh object like tress, and I suppose rocks.

we are no going to support that on simple terrain objects as newton can no have terrain with other shape.
what we will do is that when we implement scene collision scene collision, if a terrain game object is doped as a child of a static body, the code will take iterate over the terrain props, and create each one that has the collide specification it will add that shaper as a child shape of the collision tree.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Sun Feb 26, 2017 1:49 pm

Ok, I added a scene that creates 500 bodies falling on the terrain.
I runs, though i get update times of over 15 ms. On the other hand 500 bodies in a pile is not a normal case.

But I get a crash when i stop the scene. Thats a problem.
I doesn't crash every time, but eventually it will.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Sun Feb 26, 2017 2:10 pm

I saw that crash once, and I do not know what cause it.
15 ms for 500 bodies seems to long, was that a release build? can you check that in.

we need to find out it is Newton SDK, or if it is c# overhead.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Sun Feb 26, 2017 2:17 pm

Oh I see, you check it in and I get the crash when stopping,
Code: Select all
>   NewtonWrapper.dll!_VCrtDbgReportW(int nRptType, void * returnAddress, const wchar_t * szFile, int nLine, const wchar_t * szModule, const wchar_t * szFormat, char * arglist) Line 481   C++
    NewtonWrapper.dll!_CrtDbgReportW(int report_type, const wchar_t * file_name, int line_number, const wchar_t * module_name, const wchar_t * format, ...) Line 273   C++
    NewtonWrapper.dll!dgWorldDynamicUpdate::CalculateClusterReactionForces(const dgBodyCluster * const cluster, int threadID, float timestep, float maxAccNorm) Line 1019   C++
    NewtonWrapper.dll!dgWorldDynamicUpdate::ResolveClusterForces(dgBodyCluster * const cluster, int threadID, float timestep) Line 51   C++
    NewtonWrapper.dll!dgWorldDynamicUpdate::CalculateClusterReactionForcesKernel(void * const context, void * const worldContext, int threadID) Line 775   C++
    NewtonWrapper.dll!dgThreadHive::dgThreadBee::RunNextJobInQueue(int threadId) Line 97   C++


seems reproducible, I will debug it.
It looks as if it try to destroy the work in the middle of an update, I will invertigate more.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Sun Feb 26, 2017 3:03 pm

Ok I think I figure out the crash, it has to do with asyncropsun update.
we are running in a asycronous loop which mean the time should be zero, this why is crash on exit.
the 15 ms seem to be the time that take to iterate the scne whi sound ridicules.


when I serialize the scene and play in the sand box, it takes at most 6ms to uptake, and go to about 2 to 3 mms on average.

this means that c# overhead is huge, a weird thing is that it seem to take the same amend of time either in debug or release. I see updated for 12 to 15 ms and my pc is vey fast.
The unity profile does no provide detail because is lump every think und the Game NetwonUpdate.

It seem as if some how iteration over the work to update the transform is what take the time.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Sun Feb 26, 2017 3:11 pm

I removed asynchronous update for now, that should take care of the crash.

on the performance, I find it very peculiar that release and debug run at the same speed, is almost as if it is linking to the debug library in both debug and release.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Sun Feb 26, 2017 3:27 pm

I think I found a potential problem, it seem that teh code in link to 32 bit static library,
I know that sound impossible, but when I step over the code I see mix of debug and release sequence of intrutions.
this is how the path look like

C:\Development\newton-dynamics\packages\projects\visualStudio_2015_static_mt\Win32\dMath\Release
C:\Development\newton-dynamics\packages\projects\visualStudio_2015_static_mt\Win32\dContainers\Release
C:\Development\newton-dynamics\packages\projects\visualStudio_2015_static_mt\Win32\dCustomJoints\Release
C:\Development\newton-dynamics\coreLibrary_300\projects\windows\project_vs2015_static_mt\Win32\core\Release
C:\Development\newton-dynamics\coreLibrary_300\projects\windows\project_vs2015_static_mt\Win32\physics\Release
C:\Development\newton-dynamics\coreLibrary_300\projects\windows\project_vs2015_static_mt\Win32\newton\Release


I will check what is going on there, but it does no look correct.
I need to do some errand now, I will continue in the afternoon.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Sun Feb 26, 2017 4:01 pm

I changed the bodyspawner script so that it spreads out the bodies in a 100 meter radius instead.
Now the framerate never goes over 2.5 ms

I also tested disabling the transformupdate and collision updates in the plugin and I still got between 15-20 ms without updating any transforms.(if the bodies are piled up, not spread out)

500 bodies in a pile would probably generate a massive amounts of contacts.
Could that be the cause of the slowdown?
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Sun Feb 26, 2017 4:13 pm

Yes is does generate lot of contacts but I would no expect to be that slow.

if I comment out the two delegate callbacks, it still takes 18 ms to do the update.
all indication seems point to NewtonUpdate, so the is no much we can do really.
I will try to profile at work with vtune and see if I can see anything that stands out.
because when I serialize the scene in only takes about 6 at the pick, and average about 2.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 16 guests

cron