Newton in a browser?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Newton in a browser?

Postby DarthGak » Mon Nov 27, 2017 11:42 pm

Hi, I have seen some old conversations about Newton running in a browser via emscripten/llvm. Somehow...
viewtopic.php?f=9&t=7640

But the links have expired and I can't find any code or samples. Has anyone done anything recently? More importantly does anyone have any pointers on how to config say visual studio so it will produce a module that can be run in JS?

Thanks
C.
DarthGak
 
Posts: 25
Joined: Sat Nov 25, 2006 4:55 pm

Re: Newton in a browser?

Postby DarthGak » Tue Nov 28, 2017 7:43 pm

I am giving up on this for now but I thought I would post my findings in case someone else wants to try.
Using the instructions here I was able to setup enscripten to build a test library in WebAssembly that worked in a browser and I was able to call from JS. So at least in theory it should be possible.
http://webassembly.org/getting-started/ ... ers-guide/

It looks like emscripten works as a GCC replacement so the Newton VS projects would not work. I looked into the Mingw32 version but it seems to be out of date with the main branch since the makefiles still reference \corelibrary_300\ directories. So I went back to newton 3.13 which was before the directory reorg and I could find as a source dump here.
https://github.com/MADEAPPS/newton-dynamics/releases

This version does not seem to compile for various reasons. First bad tab characters in the makefile but that maybe just because of the ming dev environment. The bigger problem is issues with Pthread. It seems to be multiply defining symbols and I don't know enough about ming and pthread to sort it out.
Code: Select all
gcc -c -Wall -Wno-strict-aliasing -DPTW32_BUILD -DPTW32_STATIC_LIB -D_NEWTON_STATIC_LIB -D_MINGW_32_VER -m32 -O2 -g -msse -msse3 -mfpmath=sse -ffloat-store -ffast-math -freciprocal-math -funsafe-math-optimizations -fsingle-precision-constant -I../../source/pthreads.2 -I../../source/core -I../../source/physics -I../../source/meshUtil -I../../source/openCL -o ../../source/core/dgAABBPolygonSoup.o ../../source/core/dgAABBPolygonSoup.cpp
In file included from ../../source/core/dgTypes.h:79:0,
                 from ../../source/core/dgStdafx.h:25,
                 from ../../source/core/dgAABBPolygonSoup.cpp:22:
../../source/pthreads.2/pthread.h:108:0: warning: "PTW32_LEVEL" redefined
 #define PTW32_LEVEL PTW32_LEVEL_MAX


The dependency of this version on Pthread is probably a deal breaker anyway. Apparently WebAssembly does not yet support threads.

If I decide to come back to it I will look into building a Posix version in a Linux environment. I assume those makefile are more up to date. It looks like the ming version may not have been touched in a few years at least.
DarthGak
 
Posts: 25
Joined: Sat Nov 25, 2006 4:55 pm

Re: Newton in a browser?

Postby DarthGak » Fri Dec 08, 2017 10:53 pm

Follow up on this. I finally got it working, as in running in a browser. But it ran so slow as to be unusable. With no rendering 16 spheres took 15 sec to advance 60 frames. The problem (I think) is that WebAssembly does not yet support SIMD instructions like SSE. So I could only compile to .JS and not pure WebAsm where all the speed would be. Once that is supported I'll try again.

For reference:
Requires Ming environment and WebAssembly setup.
http://webassembly.org/getting-started/ ... ers-guide/

Configure newton cmake under emscripten. Something like this.
Code: Select all
emcmake configure ./    <-Only needed once.

emcmake cmake ./    <-Generate newton makefiles
emmake make    <-Build JS version of lib.


Here is the Cmake change needed to compile the SDK directory with Webassembly/Emscripten.

Code: Select all
if (EMSCRIPTEN)
 target_include_directories(dScene PUBLIC thirdParty/tinyxml/)
 add_definitions(-std=c++11 -pthread -msse -msse3 -mssse3 -ffast-math -freciprocal-math -funsafe-math-optimizations -c )
 add_definitions(-DDG_USE_THREAD_EMULATION -D_NEWTON_STATIC_LIB -D_CUSTOM_JOINTS_STATIC_LIB -D_CRT_SECURE_NO_WARNINGS)
 add_definitions(-Wall -Wno-strict-aliasing -Wno-overloaded-virtual -Wno-unused-private-field -Wno-unused-variable)
endif (EMSCRIPTEN)


Here is a command line to compile and link a test program into JS.
Code: Select all
em++ --std=c++11 test.cpp libNewton.a -I ./dgNewton -I ./dMath -I ./dNewton -I ./dCustomJoints -I ./dContainers -I ./dAnimation -I ./dScene -I ./dgTimeTracker --emrun -o test.html


Run on local machine port 8080. Use Chrome for best speed.
Code: Select all
emrun --no_browser --port 8080 .
DarthGak
 
Posts: 25
Joined: Sat Nov 25, 2006 4:55 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 16 guests