Implement triangle geoms.
PiperOrigin-RevId: 837079122 Change-Id: If7aa0904c6f3e7c62477b75b17d67259fe2bdabb
This commit is contained in:
committed by
Copybara-Service
parent
ed69fe85f1
commit
aa25075ea4
@@ -145,6 +145,42 @@ class PlaneBuilder {
|
|||||||
float4 orientation_;
|
float4 orientation_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TriangleBuilder {
|
||||||
|
public:
|
||||||
|
using VertexType = VertexNoUv;
|
||||||
|
using IndexType = uint16_t;
|
||||||
|
static constexpr filament::RenderableManager::PrimitiveType kPrimitiveType =
|
||||||
|
filament::RenderableManager::PrimitiveType::TRIANGLES;
|
||||||
|
|
||||||
|
TriangleBuilder()
|
||||||
|
: orientation_(CalculateOrientation({0, 0, 1})) {}
|
||||||
|
|
||||||
|
std::size_t NumVertices() const {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t NumIndices() const {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenerateVertices(VertexType* ptr, size_t num) const {
|
||||||
|
ptr[0] = VertexType({0, 0, 0}, orientation_);
|
||||||
|
ptr[1] = VertexType({1, 0, 0}, orientation_);
|
||||||
|
ptr[2] = VertexType({0, 1, 0}, orientation_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenerateIndices(IndexType* ptr, size_t num) const {
|
||||||
|
ptr[0] = 0;
|
||||||
|
ptr[1] = 1;
|
||||||
|
ptr[2] = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
filament::Box GetBounds() const { return {{-1, -1, -0.001}, {1, 1, 0.001}}; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
float4 orientation_;
|
||||||
|
};
|
||||||
|
|
||||||
class LineBoxBuilder {
|
class LineBoxBuilder {
|
||||||
public:
|
public:
|
||||||
using VertexType = VertexNoUv;
|
using VertexType = VertexNoUv;
|
||||||
@@ -745,6 +781,10 @@ FilamentBuffers CreatePlane(filament::Engine* engine, const mjModel* model) {
|
|||||||
return CreateFromBuilder(engine, PlaneBuilder(num_quads));
|
return CreateFromBuilder(engine, PlaneBuilder(num_quads));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilamentBuffers CreateTriangle(filament::Engine* engine, const mjModel* model) {
|
||||||
|
return CreateFromBuilder(engine, TriangleBuilder());
|
||||||
|
}
|
||||||
|
|
||||||
FilamentBuffers CreateBox(filament::Engine* engine, const mjModel* model) {
|
FilamentBuffers CreateBox(filament::Engine* engine, const mjModel* model) {
|
||||||
const int num_quads = model->vis.quality.numquads;
|
const int num_quads = model->vis.quality.numquads;
|
||||||
return CreateFromBuilder(engine, BoxBuilder(num_quads));
|
return CreateFromBuilder(engine, BoxBuilder(num_quads));
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace mujoco {
|
|||||||
FilamentBuffers CreateLine(filament::Engine* engine, const mjModel* model);
|
FilamentBuffers CreateLine(filament::Engine* engine, const mjModel* model);
|
||||||
FilamentBuffers CreateBox(filament::Engine* engine, const mjModel* model);
|
FilamentBuffers CreateBox(filament::Engine* engine, const mjModel* model);
|
||||||
FilamentBuffers CreateLineBox(filament::Engine* engine, const mjModel* model);
|
FilamentBuffers CreateLineBox(filament::Engine* engine, const mjModel* model);
|
||||||
|
FilamentBuffers CreateTriangle(filament::Engine* engine, const mjModel* model);
|
||||||
FilamentBuffers CreatePlane(filament::Engine* engine, const mjModel* model);
|
FilamentBuffers CreatePlane(filament::Engine* engine, const mjModel* model);
|
||||||
FilamentBuffers CreateSphere(filament::Engine* engine, const mjModel* model);
|
FilamentBuffers CreateSphere(filament::Engine* engine, const mjModel* model);
|
||||||
FilamentBuffers CreateTube(filament::Engine* engine, const mjModel* model);
|
FilamentBuffers CreateTube(filament::Engine* engine, const mjModel* model);
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ Drawable::Drawable(ObjectManager* object_mgr, const mjvGeom& geom)
|
|||||||
AddShape(ObjectManager::kLine);
|
AddShape(ObjectManager::kLine);
|
||||||
} else if (geom.type == mjGEOM_LINEBOX) {
|
} else if (geom.type == mjGEOM_LINEBOX) {
|
||||||
AddShape(ObjectManager::kLineBox);
|
AddShape(ObjectManager::kLineBox);
|
||||||
|
} else if (geom.type == mjGEOM_TRIANGLE) {
|
||||||
|
AddShape(ObjectManager::kTriangle);
|
||||||
} else if (geom.type == mjGEOM_FLEX || geom.type == mjGEOM_SKIN) {
|
} else if (geom.type == mjGEOM_FLEX || geom.type == mjGEOM_SKIN) {
|
||||||
// Flex and skin geometries are dynamically updated every frame.
|
// Flex and skin geometries are dynamically updated every frame.
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ ObjectManager::ObjectManager(const mjModel* model, filament::Engine* engine,
|
|||||||
shapes_[kTube] = CreateTube(engine_, model_);
|
shapes_[kTube] = CreateTube(engine_, model_);
|
||||||
shapes_[kPlane] = CreatePlane(engine_, model_);
|
shapes_[kPlane] = CreatePlane(engine_, model_);
|
||||||
shapes_[kSphere] = CreateSphere(engine_, model_);
|
shapes_[kSphere] = CreateSphere(engine_, model_);
|
||||||
|
shapes_[kTriangle] = CreateTriangle(engine_, model_);
|
||||||
|
|
||||||
auto LoadMaterial = [this](const char* filename) {
|
auto LoadMaterial = [this](const char* filename) {
|
||||||
Asset asset(filename, config_);
|
Asset asset(filename, config_);
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class ObjectManager {
|
|||||||
kLine,
|
kLine,
|
||||||
kLineBox,
|
kLineBox,
|
||||||
kPlane,
|
kPlane,
|
||||||
|
kTriangle,
|
||||||
kBox,
|
kBox,
|
||||||
kSphere,
|
kSphere,
|
||||||
kCone,
|
kCone,
|
||||||
|
|||||||
Reference in New Issue
Block a user