Compare commits
No commits in common. "33242794e60b68ad6981902a3ab61d4c4a57f136" and "6cf66df7f1e56ae7f039f1cbb601279986a36fb5" have entirely different histories.
33242794e6
...
6cf66df7f1
7 changed files with 68 additions and 159 deletions
|
@ -6,7 +6,6 @@
|
|||
#include "objects/joint/rotatev.h"
|
||||
#include "objects/joint/weld.h"
|
||||
#include "objects/message.h"
|
||||
#include "objects/part/wedgepart.h"
|
||||
#include "objects/service/jointsservice.h"
|
||||
#include "objects/model.h"
|
||||
#include "objects/part/part.h"
|
||||
|
@ -24,7 +23,6 @@ std::map<std::string, const InstanceType*> INSTANCE_MAP = {
|
|||
|
||||
{ "BasePart", &BasePart::TYPE },
|
||||
{ "Part", &Part::TYPE },
|
||||
{ "WedgePart", &WedgePart::TYPE },
|
||||
{ "Snap", &Snap::TYPE },
|
||||
{ "Weld", &Weld::TYPE },
|
||||
{ "Rotate", &Rotate::TYPE },
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
BasePart::BasePart(const InstanceType* type): BasePart(type, PartConstructParams { .size = glm::vec3(4, 1.2, 2), .color = Color3(0.639216f, 0.635294f, 0.647059f) }) {
|
||||
BasePart::BasePart(const InstanceType* type): BasePart(type, PartConstructParams { .size = glm::vec3(2, 1.2, 4), .color = Color3(0.639216f, 0.635294f, 0.647059f) }) {
|
||||
}
|
||||
|
||||
BasePart::BasePart(const InstanceType* type, PartConstructParams params): PVInstance(type), cframe(CFrame::FromEulerAnglesXYZ((Vector3)params.rotation) + params.position),
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
#include "wedgepart.h"
|
||||
#include "physics/util.h"
|
||||
#include <reactphysics3d/collision/ConvexMesh.h>
|
||||
#include <reactphysics3d/collision/shapes/ConvexMeshShape.h>
|
||||
|
||||
rp::ConvexMesh* wedgePhysMesh;
|
||||
|
||||
WedgePart::WedgePart(): BasePart(&TYPE) {
|
||||
}
|
||||
|
||||
WedgePart::WedgePart(PartConstructParams params): BasePart(&TYPE, params) {
|
||||
|
||||
}
|
||||
|
||||
void WedgePart::updateCollider(rp::PhysicsCommon* common) {
|
||||
rp::ConvexMeshShape* shape = common->createConvexMeshShape(wedgePhysMesh, glmToRp(size * glm::vec3(0.5f)));
|
||||
|
||||
// Recreate the rigidbody if the shape changes
|
||||
if (rigidBody->getNbColliders() > 0
|
||||
&& dynamic_cast<rp::ConvexMeshShape*>(rigidBody->getCollider(0)->getCollisionShape())->getScale() != shape->getScale()) {
|
||||
// TODO: This causes Touched to get called twice. Fix this.
|
||||
rigidBody->removeCollider(rigidBody->getCollider(0));
|
||||
rigidBody->addCollider(shape, rp::Transform());
|
||||
}
|
||||
|
||||
if (rigidBody->getNbColliders() == 0)
|
||||
rigidBody->addCollider(shape, rp::Transform());
|
||||
}
|
||||
|
||||
void WedgePart::createWedgeShape(rp::PhysicsCommon* common) {
|
||||
// https://www.reactphysics3d.com/documentation/index.html#creatingbody
|
||||
float vertices[] = {
|
||||
// X Y Z
|
||||
/*0*/ -1, 1, 1, // 0
|
||||
/*1*/ -1, -1, 1, // |
|
||||
/*2*/ -1, -1, -1, // 1---2
|
||||
|
||||
/*3*/ 1, 1, 1,
|
||||
/*4*/ 1, -1, 1,
|
||||
/*5*/ 1, -1, -1,
|
||||
};
|
||||
|
||||
// -x +x
|
||||
// +z 1----------4
|
||||
// | bottom |
|
||||
// -z 2----------5
|
||||
|
||||
// -x +x
|
||||
// +y 0----------3
|
||||
// | front |
|
||||
// -y 1----------4
|
||||
|
||||
// -x +x
|
||||
// +yz 0----------3
|
||||
// | slope |
|
||||
// -yz 2----------5
|
||||
|
||||
int indices[] = {
|
||||
// Base
|
||||
1, 2, 5, 4,
|
||||
|
||||
// Back-face
|
||||
0, 1, 4, 3,
|
||||
// 4, 1, 0, 3,
|
||||
|
||||
// Slope
|
||||
0, 2, 5, 3,
|
||||
// 3, 5, 2, 0,
|
||||
|
||||
// Sides
|
||||
0, 1, 2,
|
||||
3, 4, 5,
|
||||
};
|
||||
|
||||
// Description of the six faces of the convex mesh
|
||||
rp::PolygonVertexArray::PolygonFace* polygonFaces = new rp::PolygonVertexArray::PolygonFace[5];
|
||||
polygonFaces[0] = { 4, 0 }; // Bottom
|
||||
polygonFaces[1] = { 4, 4 }; // Front
|
||||
polygonFaces[2] = { 4, 8 }; // Slope
|
||||
polygonFaces[3] = { 3, 12 }; // Side
|
||||
polygonFaces[4] = { 3, 15 }; // Side
|
||||
|
||||
// Create the polygon vertex array
|
||||
rp::PolygonVertexArray polygonVertexArray(6, vertices, 3 * sizeof(float), indices, sizeof(int), 5, polygonFaces,
|
||||
rp::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE,
|
||||
rp::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
|
||||
|
||||
// Create the convex mesh
|
||||
std::vector<rp3d::Message> messages;
|
||||
wedgePhysMesh = common->createConvexMesh(polygonVertexArray, messages);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "basepart.h"
|
||||
#include "objects/annotation.h"
|
||||
|
||||
class DEF_INST WedgePart : public BasePart {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
protected:
|
||||
void updateCollider(rp::PhysicsCommon* common) override;
|
||||
static void createWedgeShape(rp::PhysicsCommon* common);
|
||||
|
||||
friend Workspace;
|
||||
public:
|
||||
WedgePart();
|
||||
WedgePart(PartConstructParams params);
|
||||
|
||||
static inline std::shared_ptr<WedgePart> New() { return std::make_shared<WedgePart>(); };
|
||||
static inline std::shared_ptr<WedgePart> New(PartConstructParams params) { return std::make_shared<WedgePart>(params); };
|
||||
static inline std::shared_ptr<Instance> Create() { return std::make_shared<WedgePart>(); };
|
||||
};
|
|
@ -5,7 +5,6 @@
|
|||
#include "logger.h"
|
||||
#include "objects/base/instance.h"
|
||||
#include "objects/part/part.h"
|
||||
#include "objects/part/wedgepart.h"
|
||||
#include "objects/service/jointsservice.h"
|
||||
#include "objects/joint/jointinstance.h"
|
||||
#include "objects/datamodel.h"
|
||||
|
@ -83,9 +82,6 @@ void Workspace::InitService() {
|
|||
|
||||
physicsWorld->setEventListener(&physicsEventListener);
|
||||
|
||||
// Create meshes
|
||||
WedgePart::createWedgeShape(physicsCommon);
|
||||
|
||||
// Sync all parts
|
||||
for (auto it = this->GetDescendantsStart(); it != this->GetDescendantsEnd(); it++) {
|
||||
std::shared_ptr<Instance> obj = *it;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "mesh.h"
|
||||
|
||||
extern Mesh* CUBE_MESH;
|
||||
extern Mesh* WEDGE_MESH;
|
||||
extern Mesh* SPHERE_MESH;
|
||||
extern Mesh* ARROW_MESH;
|
||||
extern Mesh* OUTLINE_MESH;
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "math_helper.h"
|
||||
#include "objects/hint.h"
|
||||
#include "objects/message.h"
|
||||
#include "objects/part/wedgepart.h"
|
||||
#include "objects/service/selection.h"
|
||||
#include "partassembly.h"
|
||||
#include "rendering/font.h"
|
||||
|
@ -122,54 +121,30 @@ void renderInit(int width, int height) {
|
|||
sansSerif = loadFont("LiberationSans-Regular.ttf");
|
||||
}
|
||||
|
||||
static void renderPart(std::shared_ptr<BasePart> part) {
|
||||
glm::mat4 model = part->cframe;
|
||||
// if (part->name == "camera") model = camera.getLookAt();
|
||||
model = glm::scale(model, (glm::vec3)part->size);
|
||||
shader->set("model", model);
|
||||
shader->set("material", Material {
|
||||
.diffuse = part->color,
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 16.0f,
|
||||
});
|
||||
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
|
||||
shader->set("normalMatrix", normalMatrix);
|
||||
shader->set("texScale", part->size);
|
||||
shader->set("transparency", part->transparency);
|
||||
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", (int)part->rightSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", (int)part->topSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", (int)part->backSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", (int)part->leftSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", (int)part->bottomSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", (int)part->frontSurface);
|
||||
|
||||
if (part->IsA<WedgePart>()) {
|
||||
glFrontFace(GL_CCW);
|
||||
WEDGE_MESH->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, WEDGE_MESH->vertexCount);
|
||||
} else {
|
||||
glFrontFace(GL_CW);
|
||||
CUBE_MESH->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
|
||||
}
|
||||
}
|
||||
|
||||
void renderParts() {
|
||||
glDepthMask(GL_TRUE);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glFrontFace(GL_CW);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Use shader
|
||||
shader->use();
|
||||
// shader->set("objectColor", glm::vec3(1.0f, 0.5f, 0.31f));
|
||||
// shader->set("lightColor", glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
|
||||
// view/projection transformations
|
||||
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)viewportWidth / (float)viewportHeight, 0.1f, 1000.0f);
|
||||
glm::mat4 view = camera.getLookAt();
|
||||
shader->set("projection", projection);
|
||||
shader->set("view", view);
|
||||
// shader->set("material", Material {
|
||||
// // .ambient = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||
// .diffuse = glm::vec3(0.639216f, 0.635294f, 0.647059f),
|
||||
// .specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
// .shininess = 16.0f,
|
||||
// });
|
||||
shader->set("sunLight", DirLight {
|
||||
.direction = glm::vec3(-0.2f, -1.0f, -0.3f),
|
||||
.ambient = glm::vec3(0.2f, 0.2f, 0.2f),
|
||||
|
@ -177,6 +152,15 @@ void renderParts() {
|
|||
.specular = glm::vec3(1.0f, 1.0f, 1.0f),
|
||||
});
|
||||
shader->set("numPointLights", 0);
|
||||
// shader->set("pointLights[0]", PointLight {
|
||||
// .position = lightPos,
|
||||
// .ambient = glm::vec3(0.4f, 0.4f, 0.4f),
|
||||
// .diffuse = glm::vec3(1.0f, 1.0f, 1.0f),
|
||||
// .specular = glm::vec3(1.0f, 1.0f, 1.0f),
|
||||
// .constant = 1.0,
|
||||
// .linear = 0.9,
|
||||
// .quadratic = 0.32,
|
||||
// });
|
||||
studsTexture->activate(0);
|
||||
shader->set("studs", 0);
|
||||
|
||||
|
@ -188,14 +172,36 @@ void renderParts() {
|
|||
// Sort by nearest
|
||||
std::map<float, std::shared_ptr<BasePart>> sorted;
|
||||
for (auto it = gWorkspace()->GetDescendantsStart(); it != gWorkspace()->GetDescendantsEnd(); it++) {
|
||||
if (!it->IsA<BasePart>()) continue;
|
||||
std::shared_ptr<BasePart> part = std::dynamic_pointer_cast<BasePart>(*it);
|
||||
|
||||
std::shared_ptr<Instance> inst = *it;
|
||||
if (inst->GetClass()->className != "Part") continue;
|
||||
std::shared_ptr<BasePart> part = std::dynamic_pointer_cast<BasePart>(inst);
|
||||
if (part->transparency > 0.00001) {
|
||||
float distance = glm::length(glm::vec3(Vector3(camera.cameraPos) - part->position()));
|
||||
sorted[distance] = part;
|
||||
} else {
|
||||
renderPart(part);
|
||||
glm::mat4 model = part->cframe;
|
||||
// if (part->name == "camera") model = camera.getLookAt();
|
||||
model = glm::scale(model, (glm::vec3)part->size);
|
||||
shader->set("model", model);
|
||||
shader->set("material", Material {
|
||||
.diffuse = part->color,
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 16.0f,
|
||||
});
|
||||
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
|
||||
shader->set("normalMatrix", normalMatrix);
|
||||
shader->set("texScale", part->size);
|
||||
shader->set("transparency", part->transparency);
|
||||
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", (int)part->rightSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", (int)part->topSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", (int)part->backSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", (int)part->leftSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", (int)part->bottomSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", (int)part->frontSurface);
|
||||
|
||||
CUBE_MESH->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,7 +209,29 @@ void renderParts() {
|
|||
// According to LearnOpenGL, std::map automatically sorts its contents.
|
||||
for (std::map<float, std::shared_ptr<BasePart>>::reverse_iterator it = sorted.rbegin(); it != sorted.rend(); it++) {
|
||||
std::shared_ptr<BasePart> part = it->second;
|
||||
renderPart(part);
|
||||
glm::mat4 model = part->cframe;
|
||||
// if (part->name == "camera") model = camera.getLookAt();
|
||||
model = glm::scale(model, (glm::vec3)part->size);
|
||||
shader->set("model", model);
|
||||
shader->set("material", Material {
|
||||
.diffuse = part->color,
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 16.0f,
|
||||
});
|
||||
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
|
||||
shader->set("normalMatrix", normalMatrix);
|
||||
shader->set("texScale", part->size);
|
||||
shader->set("transparency", part->transparency);
|
||||
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", (int)part->rightSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", (int)part->topSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", (int)part->backSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", (int)part->leftSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", (int)part->bottomSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", (int)part->frontSurface);
|
||||
|
||||
CUBE_MESH->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue