Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing IDL definitions to btRigidBody #338

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ set(USE_GLUT OFF)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build Type")

# Default is 64*1024*1024 = 64MB
set(TOTAL_MEMORY 67108864 CACHE STRING "Total Memory")
#set(TOTAL_MEMORY 67108864 CACHE STRING "Total Memory")
set(TOTAL_MEMORY 134217728 CACHE STRING "Total Memory")

# Enable for resizable heap, with some amount of slowness
set(ALLOW_MEMORY_GROWTH 0 CACHE STRING "Allow Memory Growth")
Expand All @@ -41,10 +42,11 @@ set(EMCC_ARGS
-O3
-s ALLOW_MEMORY_GROWTH=${ALLOW_MEMORY_GROWTH}
-s ALLOW_TABLE_GROWTH=1
-s EXPORTED_FUNCTIONS=["_malloc"]
-s EXPORTED_FUNCTIONS=["_malloc","_free"]
-s EXPORTED_RUNTIME_METHODS=["UTF8ToString"]
-s EXTRA_EXPORTED_RUNTIME_METHODS=["addFunction"]
-s EXPORT_NAME="Ammo"
-s EXPORT_ES6=1
-s MODULARIZE=1
-s NO_EXIT_RUNTIME=1
-s NO_FILESYSTEM=1
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM trzeci/emscripten
FROM emscripten/emsdk
ENV PYTHONUNBUFFERED 1
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
Expand Down
2 changes: 2 additions & 0 deletions ammo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "BulletSoftBody/btSoftBodyHelpers.h"
#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
#include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h"
#include "BulletCollision/Gimpact/btGImpactShape.h"

//Web IDL doesn't seem to support C++ templates so this is the best we can do
//https://stackoverflow.com/questions/42517010/is-there-a-way-to-create-webidl-bindings-for-c-templated-types#comment82966925_42517010
Expand Down
175 changes: 175 additions & 0 deletions ammo.idl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ interface btMotionState {
void setWorldTransform([Ref] btTransform worldTrans);
};

[JSImplementation="btMotionState"]
interface MotionState {
void MotionState();
[Const] void getWorldTransform([Ref] btTransform worldTrans);
void setWorldTransform([Const, Ref] btTransform worldTrans);
};

interface btDefaultMotionState {
void btDefaultMotionState([Ref] optional btTransform startTrans, [Ref] optional btTransform centerOfMassOffset);
[Value] attribute btTransform m_graphicsWorldTrans;
Expand Down Expand Up @@ -140,7 +147,9 @@ interface btCollisionObject {
void setWorldTransform([Const,Ref] btTransform worldTrans);
void setCollisionShape(btCollisionShape collisionShape);
void setCcdMotionThreshold (float ccdMotionThreshold);
[Const] float getCcdMotionThreshold();
void setCcdSweptSphereRadius (float radius);
[Const] float getCcdSweptSphereRadius();
long getUserIndex();
void setUserIndex(long index);
VoidPtr getUserPointer();
Expand All @@ -163,6 +172,7 @@ interface RayResultCallback {
attribute short m_collisionFilterMask;
attribute float m_closestHitFraction;
[Const] attribute btCollisionObject m_collisionObject;
attribute unsigned long m_flags;
};

[Prefix="btCollisionWorld::"]
Expand Down Expand Up @@ -475,6 +485,152 @@ interface btHeightfieldTerrainShape {
};
btHeightfieldTerrainShape implements btConcaveShape;

// GImpact

interface btAABB {
void btAABB([ Const, Ref ] btVector3 V1, [ Const, Ref ] btVector3 V2, [ Const, Ref ] btVector3 V3, float margin);
void invalidate();
void increment_margin(float margin);
void copy_with_margin([ Const, Ref ] btAABB other, float margin);
};

interface btPrimitiveTriangle {
void btPrimitiveTriangle();
};

interface btTriangleShapeEx {
void btTriangleShapeEx([ Const, Ref ] btVector3 p1, [ Const, Ref ] btVector3 p2, [ Const, Ref ] btVector3 p3);
void getAabb([ Const, Ref ] btTransform t, [ Ref ] btVector3 aabbMin, [ Ref ] btVector3 aabbMax);
void applyTransform([ Const, Ref ] btTransform t);
void buildTriPlane([ Ref ] btVector4 plane);
};

interface btPrimitiveManagerBase {
boolean is_trimesh();
long get_primitive_count();
void get_primitive_box(long prim_index , [Ref] btAABB primbox);
void get_primitive_triangle(long prim_index, [Ref] btPrimitiveTriangle triangle);
};

enum eGIMPACT_SHAPE_TYPE {
"CONST_GIMPACT_COMPOUND_SHAPE",
"CONST_GIMPACT_TRIMESH_SHAPE_PART",
"CONST_GIMPACT_TRIMESH_SHAPE"
};

interface btTetrahedronShapeEx {
void btTetrahedronShapeEx();
void setVertices([ Const, Ref ] btVector3 v0, [ Const, Ref ] btVector3 v1, [ Const, Ref ] btVector3 v2, [ Const, Ref ] btVector3 v3);
};

interface btGImpactShapeInterface {
void updateBound();
void postUpdate();
long getShapeType();
[Const] DOMString getName();
eGIMPACT_SHAPE_TYPE getGImpactShapeType();
[Const] btPrimitiveManagerBase getPrimitiveManager();
long getNumChildShapes();
boolean childrenHasTransform();
boolean needsRetrieveTriangles();
boolean needsRetrieveTetrahedrons();
void getBulletTriangle(long prim_index, [Ref] btTriangleShapeEx triangle);
void getBulletTetrahedron(long prim_index, [Ref] btTetrahedronShapeEx tetrahedron);
[Const] btCollisionShape getChildShape(long index);
[Value] btTransform getChildTransform(long index);
void setChildTransform(long index, [Const, Ref] btTransform transform);
};
btGImpactShapeInterface implements btConcaveShape;

[Prefix="btGImpactCompoundShape::"]
interface CompoundPrimitiveManager {
attribute btGImpactCompoundShape m_compoundShape;
long get_primitive_count();
void get_primitive_box(long prim_index, [Ref] btAABB primbox);
void get_primitive_triangle(long prim_index, [Ref] btPrimitiveTriangle triangle);
};
CompoundPrimitiveManager implements btPrimitiveManagerBase;

interface btGImpactCompoundShape {
void btGImpactCompoundShape(optional boolean children_has_transform = true);
boolean childrenHasTransform();
[Const] btPrimitiveManagerBase getPrimitiveManager();
CompoundPrimitiveManager getCompoundPrimitiveManager();
long getNumChildShapes();
void addChildShape([ Const, Ref ] btTransform localTransform, btCollisionShape shape);
btCollisionShape getChildShape(long index);
void getChildAabb(long child_index, [ Const, Ref ] btTransform t, [Ref] btVector3 aabbMin, [Ref] btVector3 aabbMax);
[Value] btTransform getChildTransform(long index);
void setChildTransform(long index, [ Const, Ref ] btTransform transform);
void calculateLocalInertia(float mass, [Ref] btVector3 inertia);
[Const] DOMString getName();
eGIMPACT_SHAPE_TYPE getGImpactShapeType();
};
btGImpactCompoundShape implements btGImpactShapeInterface;

[Prefix = "btGImpactMeshShapePart::"]
interface TrimeshPrimitiveManager {
attribute float m_margin;
attribute btStridingMeshInterface m_meshInterface;
attribute long m_part;
attribute long m_lock_count;
attribute long numverts;
attribute PHY_ScalarType type;
attribute long stride;
attribute long indexstride;
attribute long numfaces;
attribute PHY_ScalarType indicestype;
void TrimeshPrimitiveManager([Const, Ref] optional TrimeshPrimitiveManager manager);
void lock();
void unlock();
boolean is_trimesh();
long get_vertex_count();
void get_indices(long face_index, unsigned long i0, unsigned long i1, unsigned long i2);
void get_vertex(unsigned long vertex_index, [Ref] btVector3 vertex);
void get_bullet_triangle(long prim_index, [Ref] btTriangleShapeEx triangle);
};
TrimeshPrimitiveManager implements btPrimitiveManagerBase;

interface btGImpactMeshShapePart {
void btGImpactMeshShapePart(btStridingMeshInterface meshInterface, long part);
TrimeshPrimitiveManager getTrimeshPrimitiveManager();
long getVertexCount();
void getVertex(long vertex_index, [Ref] btVector3 vertex);
long getPart();
};
btGImpactMeshShapePart implements btGImpactShapeInterface;

interface btGImpactMeshShape {
void btGImpactMeshShape(btStridingMeshInterface meshInterface);
[Const] btStridingMeshInterface getMeshInterface();
long getMeshPartCount();
[Const] btGImpactMeshShapePart getMeshPart(long index);
long calculateSerializeBufferSize();
};
btGImpactMeshShape implements btGImpactShapeInterface;

interface btCollisionAlgorithmConstructionInfo {
void btCollisionAlgorithmConstructionInfo();
void btCollisionAlgorithmConstructionInfo(btDispatcher dispatcher, long temp);
attribute btDispatcher m_dispatcher1;
attribute btPersistentManifold m_manifold;
};

interface btCollisionAlgorithm {
};

interface btActivatingCollisionAlgorithm {
};
btActivatingCollisionAlgorithm implements btCollisionAlgorithm;

interface btGImpactCollisionAlgorithm {
void btGImpactCollisionAlgorithm([Const, Ref] btCollisionAlgorithmConstructionInfo ci, [Const] btCollisionObjectWrapper body0Wrap, [Const] btCollisionObjectWrapper body1Wrap);
static void registerAlgorithm(btCollisionDispatcher dispatcher);
};
btGImpactCollisionAlgorithm implements btActivatingCollisionAlgorithm;

//

interface btDefaultCollisionConstructionInfo {
void btDefaultCollisionConstructionInfo();
};
Expand Down Expand Up @@ -585,6 +741,11 @@ interface btRigidBody {
void setGravity([Const, Ref] btVector3 acceleration);
[Const] btBroadphaseProxy getBroadphaseProxy();
void clearForces();
void setFlags(long flags);
[Const] long getFlags();
[Const, Ref] btVector3 getTotalForce();
[Const, Ref] btVector3 getTotalTorque();
[Const] float getInvMass();
};
btRigidBody implements btCollisionObject;

Expand Down Expand Up @@ -670,6 +831,8 @@ interface btHingeConstraint {
void btHingeConstraint ([Ref] btRigidBody rbA, [Ref] btRigidBody rbB, [Ref] btTransform rbAFrame, [Ref] btTransform rbBFrame, optional boolean useReferenceFrameA);
void btHingeConstraint ([Ref] btRigidBody rbA, [Ref] btTransform rbAFrame, optional boolean useReferenceFrameA);

float getHingeAngle();

void setLimit(float low, float high, float softness, float biasFactor, optional float relaxationFactor);
void enableAngularMotor(boolean enableMotor, float targetVelocity, float maxMotorImpulse);
void setAngularOnly(boolean angularOnly);
Expand All @@ -684,10 +847,18 @@ btHingeConstraint implements btTypedConstraint;
interface btSliderConstraint {
void btSliderConstraint([Ref] btRigidBody rbA, [Ref] btRigidBody rbB, [Const,Ref] btTransform frameInA, [Const,Ref] btTransform frameInB, boolean useLinearReferenceFrameA);
void btSliderConstraint([Ref] btRigidBody rbB, [Const,Ref] btTransform frameInB, boolean useLinearReferenceFrameA);

[Const] float getLinearPos();
[Const] float getAngularPos();

void setLowerLinLimit(float lowerLimit);
void setUpperLinLimit(float upperLimit);
void setLowerAngLimit(float lowerAngLimit);
void setUpperAngLimit(float upperAngLimit);

void setPoweredLinMotor(boolean onOff);
void setMaxLinMotorForce(float maxLinMotorForce);
void setTargetLinMotorVelocity(float targetLinMotorVelocity);
};
btSliderConstraint implements btTypedConstraint;

Expand Down Expand Up @@ -1068,6 +1239,10 @@ interface btSoftBody {
long generateClusters(long k, optional long maxiterations);
long generateBendingConstraints(long distance, Material mat);
btSoftBody upcast(btCollisionObject colObj);
float getRestLengthScale();
void setRestLengthScale(float restLength);
void setWindVelocity([Const, Ref] btVector3 velocity);
[Const, Ref] btVector3 getWindVelocity();
};
btSoftBody implements btCollisionObject;

Expand Down
4 changes: 4 additions & 0 deletions build_v3d.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
rm -rf builds/*
cmake -B builds -DALLOW_MEMORY_GROWTH=1 -DCLOSURE=1 -DENVIRONMENT='web,webview'
cmake --build builds -j12
Loading