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 bullet3/2.89 recipe #440

Merged
merged 1 commit into from
Jan 31, 2020
Merged
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
7 changes: 7 additions & 0 deletions recipes/bullet3/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.11)
project(cmake_wrapper)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/bullet3/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.89":
url: "https://github.com/bulletphysics/bullet3/archive/2.89.tar.gz"
sha256: "621b36e91c0371933f3c2156db22c083383164881d2a6b84636759dc4cbb0bb8"
111 changes: 111 additions & 0 deletions recipes/bullet3/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import os


class Bullet3Conan(ConanFile):
name = "bullet3"
description = "Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc."
homepage = "https://github.com/bulletphysics/bullet3"
topics = "conan", "bullet", "physics", "simulation", "robotics", "kinematics", "engine",
license = "ZLIB"
url = "https://github.com/conan-io/conan-center-index"
exports_sources = "CMakeLists.txt"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"bullet3": [True, False],
"graphical_benchmark": [True, False],
"double_precision": [True, False],
"bt2_thread_locks": [True, False],
"soft_body_multi_body_dynamics_world": [True, False],
"network_support": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"bullet3": False,
"graphical_benchmark": False,
"double_precision": False,
"bt2_thread_locks": False,
"soft_body_multi_body_dynamics_world": False,
"network_support": False,
}

_source_subfolder = "source_subfolder"
_cmake = None

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.settings.compiler == "Visual Studio" and self.options.shared:
raise ConanInvalidConfiguration("Shared libraries on Visual Studio not supported")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("bullet3-{}".format(self.version), self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_BULLET3"] = self.options.bullet3
self._cmake.definitions["INSTALL_LIBS"] = True
self._cmake.definitions["USE_GRAPHICAL_BENCHMARK"] = self.options.graphical_benchmark
self._cmake.definitions["USE_DOUBLE_PRECISION"] = self.options.double_precision
self._cmake.definitions["BULLET2_USE_THREAD_LOCKS"] = self.options.bt2_thread_locks
self._cmake.definitions["USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD"] = self.options.soft_body_multi_body_dynamics_world
self._cmake.definitions["BUILD_ENET"] = self.options.network_support
self._cmake.definitions["BUILD_CLSOCKET"] = self.options.network_support
self._cmake.definitions["BUILD_CPU_DEMOS"] = False
self._cmake.definitions["BUILD_OPENGL3_DEMOS"] = False
self._cmake.definitions["BUILD_BULLET2_DEMOS"] = False
self._cmake.definitions["BUILD_EXTRAS"] = False
self._cmake.definitions["BUILD_UNIT_TESTS"] = False
if self.settings.compiler == "Visual Studio":
self._cmake.definitions["USE_MSVC_RUNTIME_LIBRARY_DLL"] = "MD" in self.settings.compiler.runtime
self._cmake.configure()
return self._cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake.install()
self.copy("LICENSE.txt", src=os.path.join(self.source_folder, self._source_subfolder), dst="licenses")
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
libs = []
if self.options.bullet3:
libs += [
"Bullet2FileLoader",
"Bullet3Collision",
"Bullet3Dynamics",
"Bullet3Geometry",
"Bullet3OpenCL_clew",
]
libs += [
"BulletDynamics",
"BulletCollision",
"LinearMath",
"BulletSoftBody",
"Bullet3Common",
"BulletInverseDynamics",
]
if self.settings.os == "Windows" and self.settings.build_type in ("Debug", "MinSizeRel", "RelWithDebInfo"):
libs = [lib + "_{}".format(self.settings.build_type) for lib in libs]

self.cpp_info.names["cmake_find_package"] = "Bullet"
self.cpp_info.names["cmake_find_package_multi"] = "Bullet"
self.cpp_info.libs = libs
self.cpp_info.includedirs = ["include", os.path.join("include", "bullet")]
11 changes: 11 additions & 0 deletions recipes/bullet3/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
project(test_package)
cmake_minimum_required(VERSION 2.8.11)

set(CMAKE_VERBOSE_MAKEFILE TRUE)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})

16 changes: 16 additions & 0 deletions recipes/bullet3/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conans import ConanFile, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
self.run(os.path.join("bin", "test_package"), run_environment=True)

178 changes: 178 additions & 0 deletions recipes/bullet3/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

///-----includes_start-----
#include <btBulletDynamicsCommon.h>
#include <stdio.h>

/// This is a Hello World program for running a basic Bullet physics simulation

int main(int argc, char** argv)
{
///-----includes_end-----

int i;
///-----initialization_start-----

///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();

///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);

///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();

///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;

btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);

dynamicsWorld->setGravity(btVector3(0, -10, 0));

///-----initialization_end-----

//keep track of the shapes, we release memory at exit.
//make sure to re-use collision shapes among rigid bodies whenever possible!
btAlignedObjectArray<btCollisionShape*> collisionShapes;

///create a few basic rigid bodies

//the ground is a cube of side 100 at position y = -56.
//the sphere will hit it at y = -6, with center at -5
{
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.), btScalar(50.), btScalar(50.)));

collisionShapes.push_back(groundShape);

btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0, -56, 0));

btScalar mass(0.);

//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);

btVector3 localInertia(0, 0, 0);
if (isDynamic)
groundShape->calculateLocalInertia(mass, localInertia);

//using motionstate is optional, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

//add the body to the dynamics world
dynamicsWorld->addRigidBody(body);
}

{
//create a dynamic rigidbody

//btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
btCollisionShape* colShape = new btSphereShape(btScalar(1.));
collisionShapes.push_back(colShape);

/// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();

btScalar mass(1.f);

//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);

btVector3 localInertia(0, 0, 0);
if (isDynamic)
colShape->calculateLocalInertia(mass, localInertia);

startTransform.setOrigin(btVector3(2, 10, 0));

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, colShape, localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

dynamicsWorld->addRigidBody(body);
}

/// Do some simulation

///-----stepsimulation_start-----
for (i = 0; i < 150; i++)
{
dynamicsWorld->stepSimulation(1.f / 60.f, 10);

//print positions of all objects
for (int j = dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--)
{
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[j];
btRigidBody* body = btRigidBody::upcast(obj);
btTransform trans;
if (body && body->getMotionState())
{
body->getMotionState()->getWorldTransform(trans);
}
else
{
trans = obj->getWorldTransform();
}
printf("world pos object %d = %f,%f,%f\n", j, float(trans.getOrigin().getX()), float(trans.getOrigin().getY()), float(trans.getOrigin().getZ()));
}
}

///-----stepsimulation_end-----

//cleanup in the reverse order of creation/initialization

///-----cleanup_start-----

//remove the rigidbodies from the dynamics world and delete them
for (i = dynamicsWorld->getNumCollisionObjects() - 1; i >= 0; i--)
{
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
delete body->getMotionState();
}
dynamicsWorld->removeCollisionObject(obj);
delete obj;
}

//delete collision shapes
for (int j = 0; j < collisionShapes.size(); j++)
{
btCollisionShape* shape = collisionShapes[j];
collisionShapes[j] = 0;
delete shape;
}

//delete dynamics world
delete dynamicsWorld;

//delete solver
delete solver;

//delete broadphase
delete overlappingPairCache;

//delete dispatcher
delete dispatcher;

delete collisionConfiguration;

//next line is optional: it will be cleared by the destructor when the array goes out of scope
collisionShapes.clear();
}
3 changes: 3 additions & 0 deletions recipes/bullet3/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.89":
folder: all