A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by viggeen » Mon Jan 16, 2017 6:16 pm
Hello, i was wondering about the progress on the Unity plugin for newton-dynamics? How far has development come and does anyone have a time estimate on when it will be ready? I would love to take a look on an early version of the plugin if i'm allowed. I'm very curious about the engine since it seems to be a perfect fit for my next game project.
-
viggeen
-
- Posts: 3
- Joined: Sat Jan 14, 2017 3:18 pm
by viggeen » Tue Jan 17, 2017 4:32 pm
Okey that's sad that the development stalled, but thanks for the info!
-
viggeen
-
- Posts: 3
- Joined: Sat Jan 14, 2017 3:18 pm
by Sweenie » Wed Jan 18, 2017 5:35 pm
Hi.
I think I solved the editor problem.
It was tricky since most examples seems to use a method that doesn't work properly or feel "hacky".
Basically it seems what we had was a "readonly" editor. When we changed the values they weren't flagged as dirty and therefor the values wasn't serialized when saving the scene.
After ALOT of googling I finally found this page(a 4.6 tutorial though but seems to work) -->
https://unity3d.com/learn/tutorials/top ... inspectorsCheck the "Player Editor Part"
In that code they use an object called SerializedObject and SerializedProperty.
I tried changing our Editor code to that method and it actually seems to work.
So, to be able to edit for example the "m_numberOfThreads" member the code looks like this...
- Code: Select all
[CustomEditor(typeof(NewtonWorld))]
public class NewtonWorldEditor : Editor
{
SerializedProperty numThreadsProp;
void OnEnable()
{
// Setup the SerializedProperties
numThreadsProp = serializedObject.FindProperty("m_numberOfThreads");
}
public override void OnInspectorGUI()
{
// Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
serializedObject.Update();
// Show the custom GUI controls
EditorGUILayout.IntPopup(numThreadsProp, m_numberOfThreadsOptions, m_numberOfThreadsValues, new GUIContent("Worker threads"));
// Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
serializedObject.ApplyModifiedProperties();
}
static private GUIContent[] m_numberOfThreadsOptions = { new GUIContent("Single threaded"), new GUIContent("2 worker threads"), new GUIContent("3 worker threads"), new GUIContent("4 worker threads"), new GUIContent("8 worker threads") };
static private int[] m_numberOfThreadsValues = { 0, 2, 3, 4, 8 };
}
The SerializedObject & SerializedProperty will take care of setting the correct dirty flags and undo/redo support.
Sorry it took so long time to figure out.
-
Sweenie
-
- Posts: 498
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by Julio Jerez » Wed Jan 18, 2017 6:08 pm
oh awesome, I will try tonight, I really want to get a unity plugin is going specially now that we are doing the soft bodies. I see if I can update the plug in to the latest newton.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Sweenie » Wed Jan 18, 2017 6:12 pm
Great
Here is an updated version with two properties and how to detect which value was changed...
- Code: Select all
[CustomEditor(typeof(NewtonWorld))]
public class NewtonWorldEditor : Editor
{
SerializedProperty numThreadsProp;
SerializedProperty solverIterationsCountProp;
void OnEnable()
{
// Setup the SerializedProperties
numThreadsProp = serializedObject.FindProperty("m_numberOfThreads");
solverIterationsCountProp = serializedObject.FindProperty("m_solverIterationsCount");
}
public override void OnInspectorGUI()
{
// Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
serializedObject.Update();
// Show the custom GUI controls
int oldNumThreadsValue = numThreadsProp.intValue;
EditorGUILayout.IntPopup(numThreadsProp, m_numberOfThreadsOptions, m_numberOfThreadsValues, new GUIContent("Worker threads"));
int oldIterationsCountValue = solverIterationsCountProp.intValue;
EditorGUILayout.IntSlider(solverIterationsCountProp, 1, 99, new GUIContent("Solver iteration count"));
// Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
serializedObject.ApplyModifiedProperties();
if(oldNumThreadsValue != numThreadsProp.intValue)
{
Debug.Log("Threads property changed!");
}
if (oldIterationsCountValue != solverIterationsCountProp.intValue)
{
Debug.Log("Solver iterations property changed!");
}
}
static private GUIContent[] m_numberOfThreadsOptions = { new GUIContent("Single threaded"), new GUIContent("2 worker threads"), new GUIContent("3 worker threads"), new GUIContent("4 worker threads"), new GUIContent("8 worker threads") };
static private int[] m_numberOfThreadsValues = { 0, 2, 3, 4, 8 };
}
-
Sweenie
-
- Posts: 498
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by Julio Jerez » Wed Jan 18, 2017 7:07 pm
Ja ja, it worked like a charm
I committed the changes to update to where we last left.
There are two basic scenes, I only enabled the custom editor script for the world script, is very basics just a prove of concept, later I will completed with more setting.
the I will finish the custom editor script for setting shape parameters
and the one for setting joint.
once we have the basics functionality we can move on to the stuff we had planned.
thank Sweeney, awesome !!
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Wed Jan 18, 2017 7:32 pm
ok I tried to uncomment out class: newtoncollidereditor.cs
two thong happened:
1- when I enable it, the gismos (the yellow drawing that render the collision shape on top of the visual shape when selected, dissaper, I am guess It has to manually call the method to do that.
2- I try to add SerializedProperty m_positProp; buy it is still confusion to me, because while the world is find because the world unique at this time, these custom editor operate on data that is part of different MonoBehaviour.
the class looks like this
- Code: Select all
public class NewtonColliderEditor : Editor
{
// SerializedProperty m_positProp;
void OnEnable()
{
// SerializedProperty m_positProp;
}
public override void OnInspectorGUI()
{
NewtonCollider collision = (NewtonCollider)target;
collision.m_posit = EditorGUILayout.Vector3Field("posit", collision.m_posit);
collision.m_rotation = EditorGUILayout.Vector3Field("rotation", collision.m_rotation);
collision.m_inheritTransformScale = EditorGUILayout.Toggle("inherit transform scale", collision.m_inheritTransformScale);
collision.m_scale = EditorGUILayout.Vector3Field("scale", collision.m_scale);
...
...
any ideas how to result that one?
if you sync is all committed.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Sweenie » Thu Jan 19, 2017 5:31 am
I've updated the ColliderEditor.
I noticed GUILayout.Vector3Field didn't supported SerializedProperty so I tried to figure out how to setting the values directly like(the "easier" version).
I got the same problem that the values wasn't saved, but then I saw this in an example.
- Code: Select all
if(GUI.Changed)
{
Undo.RegisterUndo(t, "transform changed");
}
So I updated the NewtonColliderEditor to look like this...
- Code: Select all
[CustomEditor(typeof(NewtonCollider))]
public class NewtonColliderEditor : Editor
{
public override void OnInspectorGUI()
{
NewtonCollider collision = (NewtonCollider)target;
collision.m_posit = EditorGUILayout.Vector3Field("Pos", collision.m_posit);
collision.m_rotation = EditorGUILayout.Vector3Field("Rot", collision.m_rotation);
collision.m_inheritTransformScale = EditorGUILayout.Toggle("Inherit transform scale", collision.m_inheritTransformScale);
collision.m_scale = EditorGUILayout.Vector3Field("Scale", collision.m_scale);
if(GUI.changed)
{
Undo.RegisterCompleteObjectUndo(collision, "NewtonCollider property changed");
Debug.Log("NewtonCollider property changed");
}
}
}
Now it saves the values and the SerializedProperty doesn't seem to be needed.
Regarding the yellow debug lines, I can see them.
But I also upgraded to Unity 5.5.0, maybe there was a bug.
I updated the reference dlls to Unity 5.5.0 so try upgrading Unity before syncing my changes.
-
Sweenie
-
- Posts: 498
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by Sweenie » Thu Jan 19, 2017 5:43 am
Ah, now I just found this. Can't understand why I didn't see this before...
https://docs.unity3d.com/Manual/editor- ... itors.htmlIt seems SerializedProperty is the correct way to use this.
EditorGUILayout.Vector3Field didn't support SerializedProperty but the above example uses EditorGUILayout.PropertyField instead.
I think this is better because I think that handles undo & redo properly.
In this case, using PropertyField doesn't do anything fancy, it basically just mimics the basic edit functionality of a public vector3 field but the idea behind the CustomEditor is to be able to add extra stuff such as the IntPopup for int values and EnumPopups etc.
Also, it seems to be easier to detect which specific property was changed in the editor, like i did in the NewtonWorldEditor class.
-
Sweenie
-
- Posts: 498
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by Sweenie » Thu Jan 19, 2017 6:58 am
Ok, modified SphereColliderEditor to use SerializedProperty.
I'm a bit unsure if I do everything correctly regarding Custom Editors and Inheritance but it seems to work though.
-
Sweenie
-
- Posts: 498
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by Sweenie » Fri Jan 20, 2017 8:23 am
Changed all ColliderEditors to use SerializedProperty and created some validation helpers to make the code a bit cleaner and easier to read.
Values are now saved(serialized) when saving and Undo/Redo seems to work as well with one exception.
When changing for example the radius of the SphereCollider in the Editor we call Collision.RecreateEditorShape to update the visual debugging mesh.
But when changing the radius back to it's previous value by pressing Ctrl-Z (Undo) the radius property is changed back to it's previous values as it should but the code in OnInspectorGUI doesn't detect the value change since the Undo operation already changed both the Editor input and instance value.
However, i found a callback that is triggered when Undo is performed and managed to solve it that way.
For now I only implemented that on the SphereCollider. I will see if this could instead be handled by the Base Class somehow so we don't need to implement this on every single Collider Editor Class.
-
Sweenie
-
- Posts: 498
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by Sweenie » Fri Jan 20, 2017 11:17 am
Ok, I think it works now.
All values are serialized as they should and all collision editors seem to support undo/redo now.
-
Sweenie
-
- Posts: 498
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by Tigershan » Fri Feb 10, 2017 8:37 am
Hi I saw the wrapper class used it in unity, however, the result was indeterminstic because you used update, I think you should switch to fixed update(Has been tested, giving out deterministic results)
Also can you give out an example how collision was made I saw a todo: handle scene collision log.
Lastly, which is most important, I followed the instruction, however builds only works on windows platform, tested on mac, iOS and android(physics won't simulate at all)...
Is there some documentation on where /packages folder I should build to?
I have tried to build Win32 version of the Wrapper dll, but when I used the unity plugin:
it gives me these errors(wondering why x64 doesn't have these errors)
1>newton.i(113): error : Unable to find 'dMathDefines.h'
1>newton.i(114): error : Unable to find 'dVector.h'
1>newton.i(115): error : Unable to find 'dMatrix.h'
1>newton.i(116): error : Unable to find 'dQuaternion.h'
1>newton.i(117): error : Unable to find 'dLinearAlgebra.h'
1>newton.i(125): error : Unable to find 'CustomAlloc.h'
1>newton.i(126): error : Unable to find 'CustomJoint.h'
1>newton.i(127): error : Unable to find 'CustomHinge.h'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
Tigershan
-
- Posts: 2
- Joined: Fri Feb 10, 2017 8:25 am
by Sweenie » Fri Feb 10, 2017 6:47 pm
Updated the readme regarding other platforms, but for now it's just a windows project(Visual Studio 2015).
The build configuration for 32bit probably doesn't have any include paths setup. Stick to 64bit or copy the settings from the 64-bit config.(You need to build Newton as 32 bit as well)
Regarding the Update, using FixedUpdate would lock the time steps to Unitys physics time step settings and we want to control this from the NewtonWorld component instead. Also to be able to support interpolation we must update the NewtonWorld component every frame. The plugin handles the fixed timesteps itself.
Finally, please keep in mind the plugin is not finished and under development. Experiment with it as much as you like but it isn't ready for real use yet.
-
Sweenie
-
- Posts: 498
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 5 guests