Newton Plugin for Unity 3D

Share with us how are you using the powerrrr of the force

Moderator: Alain

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Tue Apr 26, 2016 2:06 am

Ok I committed the static linking set up to the visualStudio_2015_static_mt


Is saw what you did. Nice. I think I mislead you. Or maybe not, I do no know what is the best way to go about.

Basically the Memory allocation is problem the only call back you do no what to interface with C# all others we be call to C# delegate. The NewtonAllocMemory and NewtonFreeMemory callback

we would probably want to declare for function on the NetwonmWraper.

two for for allocation and free memory, and operator new and delete.
Ideally in all other languages this will be plug to the application, but I believe in c# it would be better that let C++ to handle the memory allocation.

basically we the goal is to let C# handle c sharp memory and C++ handle c++ memory. I do no thonmg si a good idea to have C Sharp garbage collector handling C ++ memory.

tomorrow morning I will add those function and the you can hook then to the wrapper again.
sorry, I did not think of that when I ask you to plug in the delegate stuff.
But this is applicable for all other DLL that will use.

Now in theory we should be able launch unity, and add the plugin in and it should create and destroy NewtonWorld?

Tomorrow morning I will also add another Environment variable, so that visual studio use it to copy the dll to the unity folder.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Sweenie » Tue Apr 26, 2016 4:46 am

Haha, you saw my little "Memory monitor"... :mrgreen:
I agree it's a bad idea to let C# handle Newtons memory allocation, I was just curious if it would work and it did. :lol:

Actually Marshal.AllocHGlobal allocates unmanaged memory so the Garbage Collector shouldn't touch it but let's not take any chances. :wink:

Now in theory we should be able launch unity, and add the plugin in and it should create and destroy NewtonWorld?


In your Unity scene you will first have to add an empty GameObject.
On that GameObject add the NewtonWorld component.

This code...
Code: Select all
public class NewtonWorld : MonoBehaviour


makes the NewtonWorld class a Component that you can attach to any GameObject(as Kaos mentioned).

In Unity a GameObject is basically just an empty Node(container) with one or several Components attached.
However, every GameObject created always contains a Transform Component as well.
Now, NewtonWorld wouldn't have any use for a transform matrix but it can't be removed so it's just ignored.
Haha, on the other hand, maybe NewtonWorld could use that transform matrix to transform the entire world. :lol:

You can also add Attributes to the class to add certain rules and behaviours.

Like this...

Code: Select all
[DisallowMultipleComponent]
[AddComponentMenu("Newton Physics/Newton World")]
public class NewtonWorld : MonoBehaviour


[DisallowMultipleComponent] prevents adding more than one NewtonWorld component to the GameObject

[AddComponentMenu("Newton Physics/Newton World")] adds the NewtonWorld component to the Component meny so that you can add it from there instead of dragging the object from the Assets browser.

Tomorrow morning I will also add another Environment variable, so that visual studio use it to copy the dll to the unity folder.


By that I hope you mean it will copy the dll to the users Unity project folder(assets/plugin) ?
The dll has to be imported for every new Unity project you create.

Now this is cool stuff.
You will notice that if Unity is running, it will detect that you updated the plugin and will Hot swap, that is, immediately recompile.

I think it even does that while you are playing your game, it should pause the game, serialize the scene, unload the plugin, load the new, and deserialise the scene again.

It will be interesting to see if our NewtonPlugin can handle that without crashing. :)

However, I think only the NewtonPlugin supports hot swapping.
The NewtonWrapper.dll will probably be locked so you can't overwrite.
In that case you will have to close Unity or just close your open project in the Unity Editor.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Kaos » Tue Apr 26, 2016 7:10 am

In your Unity scene you will first have to add an empty GameObject.
On that GameObject add the NewtonWorld component.


I somehow wonder: Why its necessary to have a newton world manager gameobject?

Therefore i have some questions about the design if i might ask and theories.

Since you can instance and destroy objects as much as you want its not a fixed list so each newton body will hook on to the world by themselves right? And this can happen at every moment in the game.

And you wanna have some kind of layers for collision and even newton worlds if that is not the same intention but i think not.

So only a gameobject can use fixed update and therefore use the dll ergo update the newton world but it should not be of concern which gameobject it actually calls first.

What i mean is a gameobject has a newton body that newtonbody has a newtonworld assigned for id. and a collision layer. So it knows itself to what it should belong and to what react. Then it calls the newton plug and says like hey im part of this, update me.
Newton plug looks world up sees there is none and makes one. hooks the body in and starts its thread if there is one right from the start.

The call for the FixedUpdate comes in everytime for every object and the newton world is only made
once in the first call and when an object leaves newton world only checks if it was the last object and if thats the case it will end / destroy the world. A coroutine / thread is also working without being on the scene present.

So why must we have a newton manager object. What do i not see. Is it performance / calls you spare calls if doing it With a manager?
As for the object itself the Wrapper which would held the newton object will stay alive once called and running. So i dont think one needs a gameobject to keep that alive.

Physx is embeded into the engine so you cant see what it does under the hood and therefore it may have a manager that is otherwise connected and always there but lets say that isnt so. And there is no physx manager in a scene. So then it would work als the way i laid out above.


The only reason i see is to configure the world over a central script like setting iterations solver and gravity and stuff like that. But one could use standard when none given. Or set some of these even per object base maybe. So some objects you want a higher iteration solver as for others.
Is that a reason why some use multiple worlds? If those can still react in some ways. I dont know.
One other way to this of course would then be to use a config file of some sort that the plugin would read. That would have an advantage over and gameobject in respect of modding! Which is something that is not to underestimate thesedays.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Sweenie » Tue Apr 26, 2016 10:19 am

Hmm, that's an interesting idea.

So you mean the NewtonWorld will not be a Component but instead only exist in the wrapper?
The first body that is created initiates the world and the last body that is destroyed will cause the world to delete itself.

Likewise, the first body that gets the FixedUpdate call will trigger the NewtonWorldUpdate?
But how will the NewtonWorld know that the body "asking" the world to update is the first body to call in the current game loop?

Like this...

<First game loop>
Body A -> Update() -> World will update
Body B -> Update() -> World will not update, it's already been updated
Body C -> Update() -> No update
Body D -> Update() -> No update
<Second game loop>
Body A -> Update() -> Now how will the World know this is a new game loop?
Body B -> Update() ->
Body C -> Update() -> No update
Body D -> Update() -> No update
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Tue Apr 26, 2016 10:28 am

Sweenie wrote:Hmm, that's an interesting idea.

So you mean the NewtonWorld will not be a Component but instead only exist in the wrapper?
The first body that is created initiates the world and the last body that is destroyed will cause the world to delete itself.


I too was thinking that maybe the Newton world should be a component, but then how would we set parameter of and stuff in the newton world form Unity, only there is some find of system Component
the is no attached to a game object but to Unity system.
I am guessing the should be some king of fumtionality like that in Unity.
Imagine you are writing an utility, same a mesh reduction tool, does that has to be a component?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Kaos » Tue Apr 26, 2016 11:28 am

Edit: Yes i meant exactly that the world object should be handled in the plugin and not an gameobject component.

Likewise, the first body that gets the FixedUpdate call will trigger the NewtonWorldUpdate?

No actually it should only aks for its postion and roation and if its new or destroyed and stuff. it should otherwise dont control the world cycle at all.

Well you got a timestamp when the first one calls or better said the fist one calls the world is created and then the world coroutine is running and keeping track of time for itself.

every 0.02 miliseconds is one timestep(that would be standard this you can choose yourself) so the world knows whats going on and it doesent care for order of questioning of postions and rotations it just gives those out and recieves updates if object is new or should be destroyed and some things i dont have knowledge about yet.

Edit: i thought of something .. What i forget to add about the newtonbodies that they might be also have to give feedback of their new postion if handled by a user to the game engine back since they are the only ones who can actual over user interaction per mouseover and stuff. So they migh updating newton too. or Want more feedback if the userinteraction is possible.

In unity you cant rely one the order of things. Only with your order setting. which i already said why i think its kinds bad idea to use.
So this would elimenate this problem also.

Edit: another thing came to mind. Bodies then wouldnt have to be call fixedupdate anymore instead they could use update() since the physics thread is keeping the time and therefore when a user got less fps it you will have less calls to the plugin therefore you will save time. The thread keeps anything correct and the user wont the the substeps anyway. So he doesnt care if the gameobjects updates 2 times as much as he sees.
Edit again.. fixedupate exits i think only for physx so the physx objects or bodies who would use colliders and rigidbodys of both would need fixedUpdate still.

And for configuration you can make an custom editor element that writes and config file in the asset folder so users can have a nice usablity and modders can still get to the file and do it direct since tthey cant use the editor directly for this. And the Plugin reads that config file. And some functionality you can put directly in the componets ergo bodies and joints themselves.


Edit: I see ti like this .. one should implement(program) things like in real world .. and in real world physics exists and control bodies and not bodies create and control the laws of physics.

edit: poor choice of words.. actual i believe it is said one should "model" after the real world not necessary implement. But in this case you i think it kinda is the same ;D
Last edited by Kaos on Tue Apr 26, 2016 1:32 pm, edited 1 time in total.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Kaos » Tue Apr 26, 2016 1:31 pm

I too was thinking that maybe the Newton world should be a component, but then how would we set parameter of and stuff in the newton world form Unity, only there is some find of system Component
the is no attached to a game object but to Unity system.
I am guessing the should be some king of fumtionality like that in Unity.
Imagine you are writing an utility, same a mesh reduction tool, does that has to be a component?


you mean the world should NOT be a component or it Should be??? because otherwise i dont fully get this.

In unity u can have Custom editors .. like the terrain tool and stuff so setting stuff up is not the problem and those dont have to be components.
And a meshreduction tool and all sorts of custom stuff. That is a big part of unitys business model which is making money from assetstore sales which are in big part unity editors plugins.

http://docs.unity3d.com/Manual/ExtendingTheEditor.html

So with something like this you can write a config file which then is read by the newtonplugin or the c++ dll even i dont know how far rights management goes in that respect so you cant control the whole filesystem and stuff over an unity app i think you can only read write in the app directory and maybe in some windows/user/appdata/folder. For savegames and stuff. But not outside those. This may even be more restricted on android and other systems.

And for other scripts on playtime you only need to call one script from a monobehaviour script so you know the game starts then the script can run relative independent or even manage the whole game if you want to.

Unity is a bit strange since it has not a conventional gameloop as in a normal engine.
But that doesent mean u cant implement your own and therefore your own order.
So normally you make one manager script or multiple yourself..
http://answers.unity3d.com/questions/16 ... -to-a.html
like they conclude here in the answers.

But for the physics stuff i dont think you need to do it like that. As i have laid out earlier.

So you have to have one script at least in every unity game. To start then whatever.
http://forum.unity3d.com/threads/the-ne ... pt.122049/
nice maddening thread ;D

I have a nice example i once did myself and where i had the first time this issue.
I wanted to create a space game where sunsystem would be created per script and not setup per hand so planets order count size and whatnot could change and rotation times around sun and stuff.

So where to start if you dont have one planet/object in the scene?

So you pack an empty somewhere put your worldcreate script on that and on start or awake it instantiates all gameobjects and gives all scripts that those have the values they need and then those could rotate around the sun and do stuff without the creator script had to touch these again.
So the worldcreator script didnt translated the planets it just created them.
Last edited by Kaos on Tue Apr 26, 2016 1:51 pm, edited 1 time in total.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Sweenie » Tue Apr 26, 2016 1:46 pm

I don't mind trying this out. It's actually a bit like my first wrapper was working. The one used on my vehicle demo.
That one created the world in the wrapper but Unity still controlled the updates though so no multithreading there.


Now, if I got this right, the Wrapper will create the world as soon as the first body, or any newton object for that matter need to access the world.
The first body that updates to fetch it's transform matrix from the World will also cause the wrapper to start the world update thread.

Now we have two threads running.

Unitys main thread and the Wrappers world update thread.

Now comes the part I find a bit tricky.
How do we synchronise these two threads?

It would be safe to create bodies and colliders during scene load since the world update thread wouldn't have started yet.

But during runtime, if I create a new body, it can't happen during a world update.

I know Newton has the function NewtonWorldCriticalSectionLock.

I suppose that could be implemented by us inside the NewtonBody initialisation to prevent that.

But what will happen if a user create a script that first creates a couple of bodies.
Then the user creates a joint that will attach these bodies. The newton update could run between the creation of the body and the joint.

In that case, the Unity users would be required to call the NewtonWorldCriticalSectionLock themselves.

Also, if the Unity main thread stops due to an exception, will that stop the world update thread?
I'm not too experienced with multithreading.

Also, how would we handle multiple worlds?
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Kaos » Tue Apr 26, 2016 2:26 pm

Sweenie wrote:I don't mind trying this out. It's actually a bit like my first wrapper was working. The one used on my vehicle demo.
That one created the world in the wrapper but Unity still controlled the updates though so no multithreading there.

Cool

Sweenie wrote:Now, if I got this right, the Wrapper will create the world as soon as the first body, or any newton object for that matter need to access the world.
The first body that updates to fetch it's transform matrix from the World will also cause the wrapper to start the world update thread.

You mean with the transform matrix that its wants to know its new transform.world. position and rotation right?
Wells then, yes.


Sweenie wrote:Now we have two threads running.

Unitys main thread and the Wrappers world update thread.

Now comes the part I find a bit tricky.
How do we synchronise these two threads?


Well i think in reality you would have at least 3 threads already. one for the renderer then physx and then ours ;D So who counts ;D



Sweenie wrote:It would be safe to create bodies and colliders during scene load since the world update thread wouldn't have started yet.

But during runtime, if I create a new body, it can't happen during a world update.

I know Newton has the function NewtonWorldCriticalSectionLock.

I suppose that could be implemented by us inside the NewtonBody initialisation to prevent that.

But what will happen if a user create a script that first creates a couple of bodies.
Then the user creates a joint that will attach these bodies. The newton update could run between the creation of the body and the joint.

In that case, the Unity users would be required to call the NewtonWorldCriticalSectionLock themselves.

Also, if the Unity main thread stops due to an exception, will that stop the world update thread?
I'm not too experienced with multithreading.

Also, how would we handle multiple worlds?


Well if a user creates a body during runtime which he should can do then the body will be on the scene as a graphic gameobject without an active physic component till the world registered it and answers its calls. And the world could at the end of each cycle see if a new body would collider with anything and would be legal and then if legal send that body that information. The body itself hast a script that then decides what to do .. be invisible tryagain be red to show user that the postion is invalid .. whatever u want.
And if ok it will get a message all is well you will be updated next time. The world will take it and next cycle process its collisions an stuff too.

So what i mean there is no adding destroying while in cycle only before or at the end. that can be controlled.


will that stop the world update thread?
I'm not too experienced with multithreading.


Great we think the same and i tried googling that .. because i thought too ..can a dll thread run wild ??? will the thread eventually live on?

But hey that problem would be exist anyway apart from this specifc way of doping things since newton has multihreading and stuff.
i believe that this is not possible and all threads of an crashed process will be canceled by the OS. And if the unity main thread crashes i wouldnt worry about the newton world because its not like unity will make a new one and starts the game up again or? So when unity crashes all processes that come from that main exe will be terminated If not specified and hooked in as an system process. Like Ue4 Shader compiler but that is diffrent from a thread. a thread should be bound to the main process of the exe.

https://blogs.technet.microsoft.com/mar ... d-threads/

There its also stated that the process has threads

Edit: so in my interpretation: one thread fails runs wild the process should recognize failure and then terminates all other.

But what will happen if a user create a script that first creates a couple of bodies.
Then the user creates a joint that will attach these bodies. The newton update could run between the creation of the body and the joint.


That one is a bit special since i wouldnt have thought a user would be allowed to do this at runtime ;D
The normal way would be its a prefab and than it would be fine cause all would be made together.

But if you want to allow that you have to put some code that lets the bodie sleep and not collide while user has controll via mouseover and stuff or while joint is added and that contstruct then has to call the world again to be registered and then get an ok and get further updates so no processing of bodies while editing.
Last edited by Kaos on Tue Apr 26, 2016 5:39 pm, edited 1 time in total.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Kaos » Tue Apr 26, 2016 2:48 pm

Also, how would we handle multiple worlds?


I missed that one.
Bodies need 2 ids one for collision layer and one for which world they belong too.

The whole world thing i dont know what newton actualy does so is this just a layer thing or a realy own thread with its own rules?

In the following i will tread it as it has its own rules and is its own world with its own layers.
So then its just its own thread.

The newton or plugin needs a switch statement that decides from what thread the asking body gets its information.

Edit: And of course a Class That holds and controlles these world threads .. a bit like a database connection handler. I come from webdev so there i used something like that.
Its just a singleton wich holds a list of threads then.

As for the before and after adding of objects a simple state machine could be used and given its state by the physics thread. And maybe even the bodies could have one themsleves so you now if a cycle is running or it has time to add stuff.

state machines are most used for animations cycles but there are the fastest way of having a switch statement that is somewhat lose and you can add and lose states which make them preferable to hardcodet switch statements that noone can update after a while.

you could also syncronize the world threads over an statemachine i guess. Because you could compare them and if one needs longer for computations it could wait till the other has reached a specific state.

What i find great about this is you could make a game where you have an heavy updated and high solver count physics world for you game character and important stuff and in the background could be seen a crane that is physically correct animated but with lesser acuracy and lesser update count that moves around and does stuff which will never interact with the player so its just eyecandy but better than an animation because its somewhat more flexible and could be scriptcontrolled. like demolish a building.

Edit: thinkging about worlds i gues its mostly used for dividing wind and leafs and trees and the like from character gameplay stuff that would make the most sense to me.



Edit: let me add one last thing. If this is all crazy and makes more work and is not possible than just stop me i dont mind. Its just some i kinda had in my head about this without having the inner workings of newton in mind.
So i thought i tell you cause it could be interesting till its not based on these hard fact and therefore and outside perspective.. but it could also be total unreasonable bullshit in you eyes .. :D


I will try to make a more clearer model with how i think this could work if you want.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Sweenie » Tue Apr 26, 2016 3:27 pm

Haha, well, you are not out of ideas, that's for sure. :)

I think I want to go with our original plan a little bit further and if that won't work we could give your idea a try.

I'm not sure I understood all parts but I think I got the basic idea.

However, managing the world in the wrapper might be the way to go without straying too far away from how Unity want things to work.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Kaos » Tue Apr 26, 2016 5:34 pm

No Problem.

You still solve the 2 Worlds problem then by using multiple objects with world.cs component and then add an id to the newtonbody components? Or how will a newtonbody do that and does newton have collision layers or not? I brought that up a few times but never got any answers.
And i couldnt find anything about it.

And i can see that you like having FixedUpdate and Awake and Start for the newton manager.

Even tho strictly speaking, you could just put calls in there and leave the functionality all in the plugin. So the sceneobject script only gives you the heartbeats ;D

That would also be a solution for me if a script would need a scene hook (awake start updates) but i dont want to use it as a component itself. That could then also control a state machine for keeping things under flow control of other things.

You wouldnt have to have the world as a component and if you all hell breaks lose and the world and manager dont get any updates anymore because theres not object giving them they could instantiate that themselves without losing the state of the world.

Dont know when this is useful just a mindplay.

Yeah ful of ideas ... I like those more than actual implementing and typing code i have to admit. Thinking about a solution is more fun than actually realising it most of the times.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Tue Apr 26, 2016 6:35 pm

we can make thong simpler by limiting to one world, and after we get something going we can generalized.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Sweenie » Tue Apr 26, 2016 7:06 pm

Actually Kaos, you gave me some ideas.

The part about a world ID, not having the world(s) in the scene tree and the part about creating the world when it's needed and destroying itself when no more bodies are using the world.

What do you guys think about this? (It's just a prototype but I think it might work)
(You may have to copy paste it to notepad or something to be able to read it easier. :)
Code: Select all
using UnityEngine;
using System.Collections.Generic;
using System;
using Random = UnityEngine.Random;

public static class WorldManager
{
    private static Dictionary<int, NewtonWorld> worlds = new Dictionary<int, NewtonWorld>();

    public static IntPtr GetWorldPtr(int worldID)
    {
        if (!worlds.ContainsKey(worldID))
        {
            worlds.Add(worldID, new NewtonWorld());
        }

        return worlds[worldID].WorldPtr;
    }

    public static void RegisterGameObject(int worldID, int goID)
    {
        worlds[worldID].gameObjects.Add(goID);
        Debug.Log("[Add]World " + worldID.ToString() + " now contains " + worlds[worldID].gameObjects.Count.ToString() + " objects");
    }

    public static void UnregisterGameObject(int worldID, int goID)
    {
        worlds[worldID].gameObjects.Remove(goID);

        Debug.Log("[Remove]World " + worldID.ToString() + " now contains " + worlds[worldID].gameObjects.Count.ToString() + " objects");

        if (worlds[worldID].gameObjects.Count == 0)
        {
            worlds[worldID].DestroyWorld();
            worlds.Remove(worldID);

            Debug.Log("Destroying world " + worldID.ToString() + "(No more object references)");
        }
    }

}

internal class NewtonWorld
{
    public IntPtr m_world = IntPtr.Zero;
    public List<int> gameObjects = new List<int>();

    public NewtonWorld()
    {
        m_world = new IntPtr(Random.Range(999, 9999));
        // Create Newton World here
        //m_world = NewtonWrapper.NewtonCreate();
    }

    public void DestroyWorld()
    {
        m_world = IntPtr.Zero;
        // Destroy Newton World here
        // NewtonWrapper.DestroyWorld(m_world);
    }

    public System.IntPtr WorldPtr
    {
        get
        {
            return m_world;
        }
    }

}


And the NewtonBody use it like this...
Code: Select all
using UnityEngine;
using System.Collections;

public class NewtonBody : MonoBehaviour
{
    public int WorldID = 0;

    private System.IntPtr pWorld;

    void awake()
    {
    }

    void Start()
    {

        pWorld = WorldManager.GetWorldPtr(WorldID);

        // Create NewtonBody here

        Debug.Log(name + ": created in world " + WorldID.ToString() + "(" + pWorld.ToString()+")");

        WorldManager.RegisterGameObject(WorldID, this.gameObject.GetInstanceID());
    }

    void Update()
    {

    }

    void OnDestroy()
    {
        // Delete NewtonBody here
        Debug.Log(name + ": destroyed and removed from world " + WorldID.ToString() + " (" + pWorld.ToString() + ")");

        WorldManager.UnregisterGameObject(WorldID, this.gameObject.GetInstanceID());


    }

}


I don't know how many worlds Newton allows, but with this setup you can create how many worlds you want, just by setting a world ID on the body.

Regarding Layers.

Can't recall Newton has anything regarding layers, but it has collision callbacks so you can filter collisions any way you want.
We can make something that works like layers in Unity using those.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Kaos » Wed Apr 27, 2016 12:05 am

Awesome if all the typing were good for something in the end haha.
That makes my Day and i hadnt had my first coffee yet.

http://docs.unity3d.com/ScriptReference ... Field.html
you may use this for worldID and other stuff so that unity could save a level state to disk?

Also i like about this that you can set a private field in the inspector. So no public ID.
No script can directly set it without getter and setter, but you can still edit it in the editor.
Just saying as i dont know your knowledge about unity, even if i suspect its far greater than mine.
And some things may be useful to Julio to know even if i suspect he read through the unity guides in one night and might be also know more than me. :D



So your way of filtering is the way nvidia does it too.
http://docs.nvidia.com/gameworks/conten ... #filtering

There is nothing noted about making multiple collision threads each just for one layer. That was what i had in mind since i thought somehow why test for collision something that is not on that layer.
That would only bring performance if objects may only on one specific layer and only one specific layer could collide with one other.
But since object canonly on one but "multiple" layers can be checked against each other it makes no sense todo it that way cause the threads would multiply and it would actually be more work todo.
http://docs.unity3d.com/Manual/LayerBasedCollision.html

So yeah filtering is the way to go here.

The Classes look fine but i would change the id to something string based or use Tags from unity .. Because its simpler for the user to setup the tags are already there and its easier to get sorted in the head which is what world instead of numbers.
Edit: That can be done later or forget about it.

And now for the Coffee.


Edit: I talked about the tags since Nvidia is using the layers. So the layers can be used for the filtering and therefore the other things thats already there are the tags. The other option is to make an own inspector and you own list for that. That would also work but tags are nothing special for the engine just something but quicker get to things in scripts and sorting.

NOT to confuse with the sorting layer which is for sprite rendering as i just saw.

The one thing thats not so great for the layer filtering stuff is the collision layer matrix scripting abillities.
http://docs.unity3d.com/ScriptReference ... ision.html
It may be better to write and own inspector and matrix for newton than using the built in functionality.
Coffee is finally ready. :D


Edit: And you use a lot of debugs. try this one these you can leave in the code without having them to remove.. http://docs.unity3d.com/ScriptReference ... Build.html
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

PreviousNext

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 6 guests

cron