forked from hitsz-ldjam/MixEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
133 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "MxColliderUtils.h" | ||
#include "MxPhysicsUtils.hpp" | ||
#include "../Resource/MxResourceLoader.h" | ||
#include "../Resource/Model/MxModel.h" | ||
|
||
namespace Mix::Physics { | ||
CompoundCollider createColliderFromFile(const std::string& _path, | ||
std::vector<ConvexHullCollider>& _children) { | ||
auto model = ResourceLoader::Get()->load<Model>(_path); | ||
if(!model) | ||
return nullptr; | ||
|
||
auto& meshes = model->getMeshes(); | ||
|
||
CompoundCollider collider(new btCompoundShape(true, meshes.size())); | ||
|
||
_children.clear(); | ||
_children.reserve(meshes.size()); | ||
|
||
btTransform identityTrans(btTransform::getIdentity()); | ||
|
||
for(const auto& mesh : meshes) { | ||
const auto& vertices = mesh->getPositions(); | ||
|
||
ConvexHullCollider childShape(new btConvexHullShape); | ||
for(const auto& v : vertices) | ||
childShape->addPoint(Physics::mx_bt_cast(v), false); | ||
childShape->recalcLocalAabb(); | ||
_children.emplace_back(childShape); | ||
|
||
collider->addChildShape(identityTrans, childShape.get()); | ||
} | ||
|
||
return collider; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#ifndef MX_COLLIDER_UTILS_H_ | ||
#define MX_COLLIDER_UTILS_H_ | ||
|
||
#include <bullet3/btBulletCollisionCommon.h> | ||
#include <vector> | ||
|
||
namespace Mix::Physics { | ||
using Collider = std::shared_ptr<btCollisionShape>; | ||
|
||
using BoxCollider = std::shared_ptr<btBoxShape>; | ||
using CapsuleColliderX = std::shared_ptr<btCapsuleShapeX>; | ||
using CapsuleColliderY = std::shared_ptr<btCapsuleShape>; | ||
using CapsuleColliderZ = std::shared_ptr<btCapsuleShapeZ>; | ||
using CompoundCollider = std::shared_ptr<btCompoundShape>; | ||
using ConvexHullCollider = std::shared_ptr<btConvexHullShape>; | ||
using SphereCollider = std::shared_ptr<btSphereShape>; | ||
|
||
/** | ||
* @brief Create a collider according to a model file. | ||
* @param[in] _path Path to the file. | ||
* @param[out] _children Children shapes of the compound shape. | ||
* @return The collider built from the file. @code nullptr @endcode if file not found. | ||
* @attention CompoundCollider does NOT manage the lifetime of its children shapes internally. | ||
*/ | ||
CompoundCollider createColliderFromFile(const std::string& _path, | ||
std::vector<ConvexHullCollider>& _children); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.