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
Bullet Physics Integration #1 #91
Changes from 77 commits
e4e6ad4
3d647e3
0f6c81b
c6f3709
786081a
617f25c
06fe5a1
ec445a1
b97ad69
236ea39
6f9d891
cc1a6b2
1d6a215
831f7cd
7406de7
40c5fb3
04258e7
df3b311
7e64cd8
dcb7697
e9a44d5
74ee87a
54e2b2b
6254ce8
dca1880
b74de0c
87c1ce5
f38d352
f2f28bb
f584d9e
a71b048
d292e23
84945ca
d2e2221
d28b0d7
939dc35
89cc0b8
a55f458
9f59c4f
d0c541b
3c3c2e1
6e67b42
06527a0
754ab11
f77bf4a
6870423
7d7c19e
b37c361
7f9533a
6fafa67
0c9c562
4abefac
0c04bbb
84cc664
aa6f863
864451a
4edbaa9
eba6af7
fb96e0c
71ff5d0
82a3b47
9561717
5d38cef
2d4ad65
c37eafa
b6f967b
5f7af52
e53867a
4f69ee6
34295ef
4a314b3
c6d5b5d
dffe6a7
78d92c5
b48c7eb
f78cb7b
6278e3b
5a7f575
bcdf7a7
acdd01c
4fc44c7
06d95d4
913b98f
75febd5
3968ca6
2cbba91
ba8b915
61e84e9
0c7b8e7
3dc693e
dcda359
3245e7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"physics simulator": "bullet", | ||
"timestep": 0.01, | ||
"gravity": [0,-9.8,0], | ||
"friction coefficient": 0.4, | ||
"restitution coefficient": 0.1, | ||
"rigid object paths":[ | ||
"objects/cheezit", | ||
"objects/chefcan", | ||
"objects/banana" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ include(cmake/dependencies.cmake) | |
# include source dirs | ||
include_directories(${PROJECT_SOURCE_DIR}) | ||
|
||
# Physics | ||
add_definitions(-DBT_ENABLE_PROFILE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed globally, or just for the things that link to bullet? If the latter, you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this make everything really slow? (That's what profiling usually does, in my experience.) Shouldn't that be configurable via an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shouldn't make things very slow. In addition, you can call an API that makes it almost for free. See Bullet/src/LinearMath/btQuickprof.h |
||
# compiler define for enabling ptex support | ||
if(BUILD_PTEX_SUPPORT) | ||
message("Building with ptex support") | ||
|
@@ -59,6 +61,7 @@ add_subdirectory(esp/gfx/) | |
add_subdirectory(esp/assets) | ||
add_subdirectory(esp/io) | ||
add_subdirectory(esp/scene) | ||
add_subdirectory(esp/physics) | ||
add_subdirectory(esp/nav) | ||
add_subdirectory(esp/agent) | ||
add_subdirectory(esp/sensor) | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,259 @@ | ||||||
// Copyright (c) Facebook, Inc. and its affiliates. | ||||||
// This source code is licensed under the MIT license found in the | ||||||
// LICENSE file in the root directory of this source tree. | ||||||
|
||||||
#include "Attributes.h" | ||||||
#include <algorithm> | ||||||
|
||||||
namespace esp { | ||||||
namespace assets { | ||||||
|
||||||
Attributes::Attributes() { | ||||||
doubleMap_ = std::map<std::string, double>(); | ||||||
intMap_ = std::map<std::string, int>(); | ||||||
stringMap_ = std::map<std::string, std::string>(); | ||||||
magnumVec3Map_ = std::map<std::string, Magnum::Vector3>(); | ||||||
vecStringsMap_ = std::map<std::string, std::vector<std::string> >(); | ||||||
} | ||||||
|
||||||
// return true if any container has the key | ||||||
bool Attributes::exists(std::string key) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if (doubleMap_.count(key) > 0) | ||||||
hzyjerry marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return true; | ||||||
if (intMap_.count(key) > 0) | ||||||
return true; | ||||||
if (stringMap_.count(key) > 0) | ||||||
return true; | ||||||
if (magnumVec3Map_.count(key) > 0) | ||||||
return true; | ||||||
if (vecStringsMap_.count(key) > 0) | ||||||
return true; | ||||||
|
||||||
return false; | ||||||
} | ||||||
|
||||||
// check if an attribute of a specific type exists | ||||||
bool Attributes::existsAs(DataType t, std::string key) { | ||||||
if (t == DOUBLE) | ||||||
if (doubleMap_.count(key) > 0) | ||||||
return true; | ||||||
if (t == INT) | ||||||
if (intMap_.count(key) > 0) | ||||||
return true; | ||||||
if (t == STRING) | ||||||
if (stringMap_.count(key) > 0) | ||||||
return true; | ||||||
if (t == MAGNUMVEC3) | ||||||
if (magnumVec3Map_.count(key) > 0) | ||||||
return true; | ||||||
if (t == VEC_STRINGS) | ||||||
if (vecStringsMap_.count(key) > 0) | ||||||
return true; | ||||||
return false; | ||||||
} | ||||||
|
||||||
// count the number of containers with the key | ||||||
int Attributes::count(std::string key) { | ||||||
int numAttributes = 0; | ||||||
if (doubleMap_.count(key) > 0) | ||||||
numAttributes++; | ||||||
if (intMap_.count(key) > 0) | ||||||
numAttributes++; | ||||||
if (stringMap_.count(key) > 0) | ||||||
numAttributes++; | ||||||
if (magnumVec3Map_.count(key) > 0) | ||||||
numAttributes++; | ||||||
if (vecStringsMap_.count(key) > 0) | ||||||
numAttributes++; | ||||||
return numAttributes; | ||||||
} | ||||||
|
||||||
// erase the key from all maps | ||||||
void Attributes::eraseAll(std::string key) { | ||||||
if (doubleMap_.count(key) > 0) | ||||||
doubleMap_.erase(key); | ||||||
if (intMap_.count(key) > 0) | ||||||
intMap_.erase(key); | ||||||
if (stringMap_.count(key) > 0) | ||||||
stringMap_.erase(key); | ||||||
if (magnumVec3Map_.count(key) > 0) | ||||||
magnumVec3Map_.erase(key); | ||||||
if (vecStringsMap_.count(key) > 0) | ||||||
vecStringsMap_.erase(key); | ||||||
} | ||||||
|
||||||
// erase the key from a particular map | ||||||
void Attributes::eraseAs(DataType t, std::string key) { | ||||||
if (t == DOUBLE) { | ||||||
if (doubleMap_.count(key) > 0) | ||||||
doubleMap_.erase(key); | ||||||
} else if (t == INT) { | ||||||
if (intMap_.count(key) > 0) | ||||||
intMap_.erase(key); | ||||||
} else if (t == STRING) { | ||||||
if (stringMap_.count(key) > 0) | ||||||
stringMap_.erase(key); | ||||||
} else if (t == MAGNUMVEC3) { | ||||||
if (magnumVec3Map_.count(key) > 0) | ||||||
magnumVec3Map_.erase(key); | ||||||
} else if (t == VEC_STRINGS) { | ||||||
if (vecStringsMap_.count(key) > 0) | ||||||
vecStringsMap_.erase(key); | ||||||
} | ||||||
} | ||||||
|
||||||
// clear all maps | ||||||
void Attributes::clear() { | ||||||
doubleMap_.clear(); | ||||||
intMap_.clear(); | ||||||
stringMap_.clear(); | ||||||
magnumVec3Map_.clear(); | ||||||
vecStringsMap_.clear(); | ||||||
} | ||||||
|
||||||
// clear only a particular map | ||||||
void Attributes::clearAs(DataType t) { | ||||||
if (t == DOUBLE) { | ||||||
doubleMap_.clear(); | ||||||
} else if (t == INT) { | ||||||
intMap_.clear(); | ||||||
} else if (t == STRING) { | ||||||
stringMap_.clear(); | ||||||
} else if (t == MAGNUMVEC3) { | ||||||
magnumVec3Map_.clear(); | ||||||
} else if (t == VEC_STRINGS) { | ||||||
vecStringsMap_.clear(); | ||||||
} | ||||||
} | ||||||
|
||||||
//----------------------------------------// | ||||||
// Type specific getters/setters | ||||||
//----------------------------------------// | ||||||
// return the queried entry in the double map | ||||||
// will throw an exception if the key does not exist in the double map | ||||||
double Attributes::getDouble(std::string key) { | ||||||
return doubleMap_.at(key); | ||||||
} | ||||||
|
||||||
// set a double attribute key->val | ||||||
void Attributes::setDouble(std::string key, double val) { | ||||||
doubleMap_[key] = val; | ||||||
} | ||||||
|
||||||
int Attributes::getInt(std::string key) { | ||||||
return intMap_.at(key); | ||||||
} | ||||||
|
||||||
void Attributes::setInt(std::string key, int val) { | ||||||
intMap_[key] = val; | ||||||
} | ||||||
|
||||||
std::string Attributes::getString(std::string key) { | ||||||
return stringMap_.at(key); | ||||||
} | ||||||
|
||||||
void Attributes::setString(std::string key, std::string val) { | ||||||
stringMap_[key] = val; | ||||||
} | ||||||
|
||||||
Magnum::Vector3 Attributes::getMagnumVec3(std::string key) { | ||||||
return magnumVec3Map_.at(key); | ||||||
} | ||||||
|
||||||
void Attributes::setMagnumVec3(std::string key, Magnum::Vector3 val) { | ||||||
magnumVec3Map_[key] = val; | ||||||
} | ||||||
std::vector<std::string> Attributes::getVecStrings(std::string key) { | ||||||
return vecStringsMap_.at(key); | ||||||
} | ||||||
|
||||||
void Attributes::setVecStrings(std::string key, std::vector<std::string> val) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Particularly important for |
||||||
vecStringsMap_[key] = val; | ||||||
} | ||||||
|
||||||
// add a string to a string vector (to avoid get/set copying) | ||||||
void Attributes::appendVecStrings(std::string key, std::string val) { | ||||||
vecStringsMap_[key].push_back(val); | ||||||
} | ||||||
|
||||||
void Attributes::removeFromVecString(std::string key, std::string val) { | ||||||
std::vector<std::string>& stringVec = vecStringsMap_[key]; | ||||||
std::vector<std::string>::iterator position = | ||||||
std::find(stringVec.begin(), stringVec.end(), val); | ||||||
if (position != stringVec.end()) // == .end() means the element was not found | ||||||
stringVec.erase(position); | ||||||
} | ||||||
|
||||||
// return a formated string exposing the current contents of the attributes maps | ||||||
std::string Attributes::listAttributes() { | ||||||
std::string attributes = | ||||||
"List of attributes: \n----------------------------------------\n"; | ||||||
|
||||||
attributes += "\nDoubles: \n"; | ||||||
for (auto it = doubleMap_.begin(); it != doubleMap_.end(); ++it) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You do not have to change. Just FYI: A simpler way is to: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yay for auto and range-based for loops tho :) |
||||||
attributes += it->first + " : " + std::to_string(it->second) + "\n"; | ||||||
} | ||||||
|
||||||
attributes += "\nInts: \n"; | ||||||
for (auto it = intMap_.begin(); it != intMap_.end(); ++it) { | ||||||
attributes += it->first + " : " + std::to_string(it->second) + "\n"; | ||||||
} | ||||||
|
||||||
attributes += "\nStrings: \n"; | ||||||
for (auto it = stringMap_.begin(); it != stringMap_.end(); ++it) { | ||||||
attributes += it->first + " : " + it->second + "\n"; | ||||||
} | ||||||
|
||||||
attributes += "\nMagnum Vector3s: \n"; | ||||||
for (auto it = magnumVec3Map_.begin(); it != magnumVec3Map_.end(); ++it) { | ||||||
attributes += it->first + " : [" + std::to_string(it->second[0]) + ", " + | ||||||
std::to_string(it->second[1]) + ", " + | ||||||
std::to_string(it->second[2]) + "]\n"; | ||||||
} | ||||||
|
||||||
attributes += "\nVectors of Strings: \n"; | ||||||
for (auto it = vecStringsMap_.begin(); it != vecStringsMap_.end(); ++it) { | ||||||
attributes += it->first + " : ["; | ||||||
for (auto vs_it = it->second.begin(); vs_it != it->second.end(); ++vs_it) { | ||||||
if (vs_it != it->second.begin()) | ||||||
attributes += ", "; | ||||||
attributes += *vs_it; | ||||||
} | ||||||
attributes += "]\n"; | ||||||
} | ||||||
|
||||||
attributes += "\n----------------------------------------\n\n"; | ||||||
return attributes; | ||||||
} | ||||||
|
||||||
PhysicsObjectAttributes::PhysicsObjectAttributes() { | ||||||
// fill necessary attribute defaults | ||||||
setDouble("mass", 1.0); | ||||||
setDouble("margin", 0.01); | ||||||
setDouble("scale", 1.0); | ||||||
setMagnumVec3("COM", Magnum::Vector3(0)); | ||||||
setMagnumVec3("inertia", Magnum::Vector3(0., 0., 0.)); | ||||||
setDouble("frictionCoefficient", 0.5); | ||||||
setDouble("restitutionCoefficient", 0.6); | ||||||
setDouble("linDamping", 0.2); | ||||||
setDouble("angDamping", 0.2); | ||||||
setString("originHandle", ""); | ||||||
setString("renderMeshHandle", ""); | ||||||
setString("collisionMeshHandle", ""); | ||||||
} | ||||||
|
||||||
PhysicsSceneAttributes::PhysicsSceneAttributes() { | ||||||
setMagnumVec3("gravity", Magnum::Vector3(0, -9.8, 0)); | ||||||
setDouble("frictionCoefficient", 0.4); | ||||||
setDouble("restitutionCoefficient", 0.05); | ||||||
setString("renderMeshHandle", ""); | ||||||
setString("collisionMeshHandle", ""); | ||||||
} | ||||||
|
||||||
PhysicsManagerAttributes::PhysicsManagerAttributes() { | ||||||
setString("simulator", "none"); | ||||||
setDouble("timestep", 0.01); | ||||||
setInt("maxSubsteps", 10); | ||||||
} | ||||||
} // namespace assets | ||||||
} // namespace esp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it makes more sense to not have spaces in names.
_
or-
makes more sense as that's more inline with what people expect.