@gg-web-engine/ammo 0.0.59 → 0.0.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build_gg_ammo/README.md +39 -7
- package/build_gg_ammo/ammo_patches.txt +56 -0
- package/build_gg_ammo/patch_files/CMakeLists.txt +121 -0
- package/build_gg_ammo/patch_files/Dockerfile +13 -0
- package/dist/ammo.js/ammo.js +1001 -36
- package/dist/ammo.js/ammo.wasm.js +988 -1313
- package/dist/ammo.js/ammo.wasm.wasm +0 -0
- package/package.json +14 -13
- package/test/ammo-factory.spec.ts +88 -0
- package/test/components/ammo-raycast-vehicle.component.spec.ts +139 -0
- package/test/components/ammo-world.component.spec.ts +50 -0
- package/tsconfig.json +2 -1
package/build_gg_ammo/README.md
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
This is a place where I build proprietary ammo.js for gg-web-engine.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
The build fetches [AndyGura/ammo.js](https://github.com/AndyGura/ammo.js) (my own fork, itself
|
|
4
|
+
originally forked from the now-deleted `i12345/ammo.js`, which was in turn a more up-to-date fork
|
|
5
|
+
of the unmaintained upstream [kripken/ammo.js](https://github.com/kripken/ammo.js)) at the pinned
|
|
6
|
+
commit in `Makefile`, then applies the patches below on top before compiling. Whichever ammo.js
|
|
7
|
+
repo `AMMOJS_GIT_REPO` points at only supplies the JS/TS build tooling (Emscripten/CMake/
|
|
8
|
+
webidl2ts wiring) - the actual Bullet source is fetched separately from `BULLET_GIT_REPO` at its
|
|
9
|
+
own pinned commit (see `Makefile`), and `ammo.idl` plus the vehicle raycaster source are replaced
|
|
10
|
+
wholesale by `patch_files/` regardless of what the fetched repo ships, so this build isn't
|
|
11
|
+
sensitive to the fetched ammo.js repo's own Bullet submodule pin or `ammo.idl` version.
|
|
10
12
|
|
|
13
|
+
Reasons to build own ammo.js instead of using a stock upstream one:
|
|
14
|
+
1) The crucial feature, which bullet does not have: use collision groups for raycast vehicle. I
|
|
15
|
+
already made a [PR](https://github.com/bulletphysics/bullet3/pull/4559) to bullet.
|
|
16
|
+
1) Expose `m_erp2` property of `btContactSolverInfo`, needed for fighting with object clipping
|
|
17
|
+
problem, which appeared in bullet 2.84. Also made a PR to the (now-deleted) `i12345/ammo.js`
|
|
18
|
+
about it.
|
|
19
|
+
|
|
20
|
+
(A third reason used to live here: `ammo.d.ts` was missing the `getPointer`/`compare` module
|
|
21
|
+
functions, hand-patched into the generated output. That's no longer necessary - the
|
|
22
|
+
[PR](https://github.com/anotherpit/webidl2ts/pull/2) fixing it in `webidl2ts` merged, and
|
|
23
|
+
`AndyGura/ammo.js`'s `package.json` depends on `github:anotherpit/webidl2ts` unpinned, so a fresh
|
|
24
|
+
`npm i` already pulls the fix.)
|
|
25
|
+
|
|
26
|
+
`patch_files/CMakeLists.txt` and `patch_files/Dockerfile` are a different kind of patch: not a
|
|
27
|
+
gg-web-engine feature, but keeping the build itself compiling against a moving Emscripten. The
|
|
28
|
+
`Dockerfile` pins `emscripten/emsdk` to an exact tag instead of `:latest`, and `CMakeLists.txt`
|
|
29
|
+
merges `EXTRA_EXPORTED_RUNTIME_METHODS` into `EXPORTED_RUNTIME_METHODS` and links the final
|
|
30
|
+
`ammo.js`/`ammo.wasm.js` with `em++` instead of `emcc` - both required once this build was re-run
|
|
31
|
+
against a current Emscripten (removed `EXTRA_EXPORTED_RUNTIME_METHODS` outright, and `emcc` no
|
|
32
|
+
longer defaults to C++ linkage the way it used to, so linking Bullet's C++ objects with plain
|
|
33
|
+
`emcc` fails with "undefined symbol: operator new"). If a future emsdk bump breaks the build again,
|
|
34
|
+
expect it to show up as one of these two symptoms first.
|
|
11
35
|
|
|
12
36
|
All changed file diffs in ammo.js and bullet can be found [here](./ammo_patches.txt) and [here](./bullet_patches.txt) appropriately
|
|
13
37
|
|
|
@@ -15,3 +39,11 @@ All changed file diffs in ammo.js and bullet can be found [here](./ammo_patches.
|
|
|
15
39
|
### How to build
|
|
16
40
|
1) Docker has to be installed and started
|
|
17
41
|
1) enter this directory and run `make all`
|
|
42
|
+
1) commit the resulting changes under `../src/ammo.js` along with any `Makefile`/`*_patches.txt`
|
|
43
|
+
changes
|
|
44
|
+
|
|
45
|
+
Or trigger the `Rebuild self-built ammo.js` GitHub Actions workflow (`workflow_dispatch`) instead -
|
|
46
|
+
it runs the same `make all` in CI and commits the result back to the branch, so this no longer
|
|
47
|
+
requires a local Docker install. That workflow also runs automatically (without committing) on any
|
|
48
|
+
PR touching this directory, as a check that the build recipe still works - see
|
|
49
|
+
`.github/workflows/build_ammo.yml`.
|
|
@@ -1,3 +1,59 @@
|
|
|
1
|
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
2
|
+
index 0512013..39cf63c 100644
|
|
3
|
+
--- a/CMakeLists.txt
|
|
4
|
+
+++ b/CMakeLists.txt
|
|
5
|
+
@@ -35,15 +35,13 @@ set(ALLOW_MEMORY_GROWTH 0 CACHE STRING "Allow Memory Growth")
|
|
6
|
+
|
|
7
|
+
set(EMCC_ARGS
|
|
8
|
+
--extern-pre-js ${AMMO_FRONT_MATTER_FILE}
|
|
9
|
+
- --llvm-lto 1
|
|
10
|
+
--post-js glue.js
|
|
11
|
+
--post-js ${AMMO_ONLOAD_FILE}
|
|
12
|
+
-O3
|
|
13
|
+
-s ALLOW_MEMORY_GROWTH=${ALLOW_MEMORY_GROWTH}
|
|
14
|
+
-s ALLOW_TABLE_GROWTH=1
|
|
15
|
+
-s EXPORTED_FUNCTIONS=["_malloc","_free"]
|
|
16
|
+
- -s EXPORTED_RUNTIME_METHODS=["UTF8ToString"]
|
|
17
|
+
- -s EXTRA_EXPORTED_RUNTIME_METHODS=["addFunction"]
|
|
18
|
+
+ -s EXPORTED_RUNTIME_METHODS=["UTF8ToString","addFunction"]
|
|
19
|
+
-s EXPORT_NAME="Ammo"
|
|
20
|
+
-s MODULARIZE=1
|
|
21
|
+
-s NO_EXIT_RUNTIME=1
|
|
22
|
+
@@ -103,7 +101,10 @@ add_custom_target(ammo-bindings ALL DEPENDS glue.js glue.o)
|
|
23
|
+
#######################################
|
|
24
|
+
add_custom_command(
|
|
25
|
+
OUTPUT ammo.js
|
|
26
|
+
- COMMAND emcc glue.o ${BULLET_LIBS} ${EMCC_JS_ARGS} -o ammo.js
|
|
27
|
+
+ # em++ (not emcc): the final link pulls in libBulletCollision/Dynamics/etc, which are C++ and
|
|
28
|
+
+ # need operator new/delete resolved from libc++ - modern emscripten's emcc no longer defaults
|
|
29
|
+
+ # to C++ linkage the way it used to, and fails with "undefined symbol: operator new" otherwise.
|
|
30
|
+
+ COMMAND em++ glue.o ${BULLET_LIBS} ${EMCC_JS_ARGS} -o ammo.js
|
|
31
|
+
DEPENDS ammo-bindings ${AMMO_FRONT_MATTER_FILE} ${AMMO_ONLOAD_FILE} ${BULLET_TARGETS}
|
|
32
|
+
COMMENT "Building ammo javascript"
|
|
33
|
+
VERBATIM)
|
|
34
|
+
@@ -113,7 +114,7 @@ add_custom_target(ammo-javascript ALL DEPENDS ammo.js)
|
|
35
|
+
#######################################
|
|
36
|
+
add_custom_command(
|
|
37
|
+
OUTPUT ammo.wasm.js ammo.wasm.wasm
|
|
38
|
+
- COMMAND emcc glue.o ${BULLET_LIBS} ${EMCC_WASM_ARGS} -o ammo.wasm.js
|
|
39
|
+
+ COMMAND em++ glue.o ${BULLET_LIBS} ${EMCC_WASM_ARGS} -o ammo.wasm.js
|
|
40
|
+
DEPENDS ammo-bindings ${AMMO_FRONT_MATTER_FILE} ${AMMO_ONLOAD_FILE} ${BULLET_TARGETS}
|
|
41
|
+
COMMENT "Building ammo webassembly"
|
|
42
|
+
VERBATIM)
|
|
43
|
+
diff --git a/Dockerfile b/Dockerfile
|
|
44
|
+
index e7f427c..a582408 100644
|
|
45
|
+
--- a/Dockerfile
|
|
46
|
+
+++ b/Dockerfile
|
|
47
|
+
@@ -1,4 +1,8 @@
|
|
48
|
+
-FROM emscripten/emsdk
|
|
49
|
+
+# Pinned (not :latest): an unpinned emsdk silently drifts to whatever Emscripten ships that day,
|
|
50
|
+
+# which has broken this build before (removed -s EXTRA_EXPORTED_RUNTIME_METHODS, changed emcc's
|
|
51
|
+
+# default C/C++ linkage - see CMakeLists.txt). Bump deliberately, and re-run the full build to
|
|
52
|
+
+# confirm CMakeLists.txt's EMCC_ARGS/em++ usage still matches whatever version you bump to.
|
|
53
|
+
+FROM emscripten/emsdk:6.0.8
|
|
54
|
+
ENV PYTHONUNBUFFERED 1
|
|
55
|
+
RUN apt-get update \
|
|
56
|
+
&& apt-get install -y --no-install-recommends \
|
|
1
57
|
diff --git a/ammo.idl b/ammo.idl
|
|
2
58
|
index 1f6b880..9c2e5cf 100644
|
|
3
59
|
--- a/ammo.idl
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
|
2
|
+
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
|
3
|
+
|
|
4
|
+
FIND_PACKAGE(Python3)
|
|
5
|
+
set(PYTHON ${Python3_EXECUTABLE} CACHE STRING "Python path")
|
|
6
|
+
set(EMSCRIPTEN_ROOT $ENV{EMSDK}/upstream/emscripten CACHE STRING "Emscripten path")
|
|
7
|
+
set(CMAKE_TOOLCHAIN_FILE ${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake)
|
|
8
|
+
set(WEBIDL_BINDER_SCRIPT ${EMSCRIPTEN_ROOT}/tools/webidl_binder.py)
|
|
9
|
+
set(AMMO_FRONT_MATTER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/front-matter.js)
|
|
10
|
+
set(AMMO_HEADER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/ammo.h)
|
|
11
|
+
set(AMMO_IDL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/ammo.idl)
|
|
12
|
+
set(AMMO_ONLOAD_FILE ${CMAKE_CURRENT_SOURCE_DIR}/onload.js)
|
|
13
|
+
set(BULLET_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bullet/src/)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
set(BULLET_TARGETS BulletCollision BulletDynamics BulletSoftBody LinearMath)
|
|
17
|
+
foreach(_TARGET ${BULLET_TARGETS})
|
|
18
|
+
list(APPEND BULLET_LIBS $<TARGET_FILE:${_TARGET}>)
|
|
19
|
+
endforeach()
|
|
20
|
+
|
|
21
|
+
# Disable bullet graphical benchmarks
|
|
22
|
+
set(USE_GRAPHICAL_BENCHMARK OFF)
|
|
23
|
+
|
|
24
|
+
# Disable bullet GLUT
|
|
25
|
+
set(USE_GLUT OFF)
|
|
26
|
+
|
|
27
|
+
# Build Release by default
|
|
28
|
+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build Type")
|
|
29
|
+
|
|
30
|
+
# Default is 64*1024*1024 = 64MB
|
|
31
|
+
set(TOTAL_MEMORY 67108864 CACHE STRING "Total Memory")
|
|
32
|
+
|
|
33
|
+
# Enable for resizable heap, with some amount of slowness
|
|
34
|
+
set(ALLOW_MEMORY_GROWTH 0 CACHE STRING "Allow Memory Growth")
|
|
35
|
+
|
|
36
|
+
set(EMCC_ARGS
|
|
37
|
+
--extern-pre-js ${AMMO_FRONT_MATTER_FILE}
|
|
38
|
+
--post-js glue.js
|
|
39
|
+
--post-js ${AMMO_ONLOAD_FILE}
|
|
40
|
+
-O3
|
|
41
|
+
-s ALLOW_MEMORY_GROWTH=${ALLOW_MEMORY_GROWTH}
|
|
42
|
+
-s ALLOW_TABLE_GROWTH=1
|
|
43
|
+
-s EXPORTED_FUNCTIONS=["_malloc","_free"]
|
|
44
|
+
-s EXPORTED_RUNTIME_METHODS=["UTF8ToString","addFunction"]
|
|
45
|
+
-s EXPORT_NAME="Ammo"
|
|
46
|
+
-s MODULARIZE=1
|
|
47
|
+
-s NO_EXIT_RUNTIME=1
|
|
48
|
+
-s NO_FILESYSTEM=1
|
|
49
|
+
-s TOTAL_MEMORY=${TOTAL_MEMORY})
|
|
50
|
+
|
|
51
|
+
if(${CLOSURE})
|
|
52
|
+
# Ignore closure errors about the bullet Node class
|
|
53
|
+
# (Node is a DOM thing too)
|
|
54
|
+
LIST(APPEND EMCC_ARGS
|
|
55
|
+
--closure 1
|
|
56
|
+
-s IGNORE_CLOSURE_COMPILER_ERRORS=1)
|
|
57
|
+
else()
|
|
58
|
+
LIST(APPEND EMCC_ARGS
|
|
59
|
+
-s NO_DYNAMIC_EXECUTION=1)
|
|
60
|
+
endif()
|
|
61
|
+
|
|
62
|
+
set(EMCC_JS_ARGS ${EMCC_ARGS}
|
|
63
|
+
-s AGGRESSIVE_VARIABLE_ELIMINATION=1
|
|
64
|
+
-s ELIMINATE_DUPLICATE_FUNCTIONS=1
|
|
65
|
+
-s LEGACY_VM_SUPPORT=1
|
|
66
|
+
-s SINGLE_FILE=1
|
|
67
|
+
-s WASM=0)
|
|
68
|
+
|
|
69
|
+
set(EMCC_WASM_ARGS ${EMCC_ARGS}
|
|
70
|
+
-s BINARYEN_IGNORE_IMPLICIT_TRAPS=1
|
|
71
|
+
-s WASM=1)
|
|
72
|
+
|
|
73
|
+
set(EMCC_GLUE_ARGS
|
|
74
|
+
-c
|
|
75
|
+
-I${BULLET_SRC_DIR}
|
|
76
|
+
-include${AMMO_HEADER_FILE})
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
#######################################
|
|
80
|
+
project("ammo")
|
|
81
|
+
add_subdirectory(bullet EXCLUDE_FROM_ALL)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
#######################################
|
|
85
|
+
add_custom_command(
|
|
86
|
+
OUTPUT glue.cpp glue.js
|
|
87
|
+
BYPRODUCTS parser.out WebIDLGrammar.pkl
|
|
88
|
+
COMMAND ${PYTHON} ${WEBIDL_BINDER_SCRIPT} ${AMMO_IDL_FILE} glue
|
|
89
|
+
DEPENDS ${AMMO_IDL_FILE}
|
|
90
|
+
COMMENT "Generating ammo bindings"
|
|
91
|
+
VERBATIM)
|
|
92
|
+
add_custom_command(
|
|
93
|
+
OUTPUT glue.o
|
|
94
|
+
COMMAND emcc glue.cpp ${EMCC_GLUE_ARGS} -o glue.o
|
|
95
|
+
DEPENDS glue.cpp ${AMMO_HEADER_FILE}
|
|
96
|
+
COMMENT "Building ammo bindings"
|
|
97
|
+
VERBATIM)
|
|
98
|
+
add_custom_target(ammo-bindings ALL DEPENDS glue.js glue.o)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
#######################################
|
|
102
|
+
add_custom_command(
|
|
103
|
+
OUTPUT ammo.js
|
|
104
|
+
# em++ (not emcc): the final link pulls in libBulletCollision/Dynamics/etc, which are C++ and
|
|
105
|
+
# need operator new/delete resolved from libc++ - modern emscripten's emcc no longer defaults
|
|
106
|
+
# to C++ linkage the way it used to, and fails with "undefined symbol: operator new" otherwise.
|
|
107
|
+
COMMAND em++ glue.o ${BULLET_LIBS} ${EMCC_JS_ARGS} -o ammo.js
|
|
108
|
+
DEPENDS ammo-bindings ${AMMO_FRONT_MATTER_FILE} ${AMMO_ONLOAD_FILE} ${BULLET_TARGETS}
|
|
109
|
+
COMMENT "Building ammo javascript"
|
|
110
|
+
VERBATIM)
|
|
111
|
+
add_custom_target(ammo-javascript ALL DEPENDS ammo.js)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
#######################################
|
|
115
|
+
add_custom_command(
|
|
116
|
+
OUTPUT ammo.wasm.js ammo.wasm.wasm
|
|
117
|
+
COMMAND em++ glue.o ${BULLET_LIBS} ${EMCC_WASM_ARGS} -o ammo.wasm.js
|
|
118
|
+
DEPENDS ammo-bindings ${AMMO_FRONT_MATTER_FILE} ${AMMO_ONLOAD_FILE} ${BULLET_TARGETS}
|
|
119
|
+
COMMENT "Building ammo webassembly"
|
|
120
|
+
VERBATIM)
|
|
121
|
+
add_custom_target(ammo-wasm ALL DEPENDS ammo.wasm.js ammo.wasm.wasm)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Pinned (not :latest): an unpinned emsdk silently drifts to whatever Emscripten ships that day,
|
|
2
|
+
# which has broken this build before (removed -s EXTRA_EXPORTED_RUNTIME_METHODS, changed emcc's
|
|
3
|
+
# default C/C++ linkage - see CMakeLists.txt). Bump deliberately, and re-run the full build to
|
|
4
|
+
# confirm CMakeLists.txt's EMCC_ARGS/em++ usage still matches whatever version you bump to.
|
|
5
|
+
FROM emscripten/emsdk:6.0.8
|
|
6
|
+
ENV PYTHONUNBUFFERED 1
|
|
7
|
+
RUN apt-get update \
|
|
8
|
+
&& apt-get install -y --no-install-recommends \
|
|
9
|
+
libgeos-dev ed \
|
|
10
|
+
automake autoconf libtool \
|
|
11
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
12
|
+
RUN mkdir code
|
|
13
|
+
WORKDIR /code
|