parent
385c608d96
commit
dda4ec2fe5
18 changed files with 54782 additions and 89 deletions
@ -0,0 +1,27 @@ |
||||
#pragma once |
||||
|
||||
#include <cstdint> |
||||
|
||||
struct Edge { |
||||
uint32_t a; |
||||
uint32_t b; |
||||
float length; |
||||
}; |
||||
|
||||
struct Face { |
||||
uint32_t a; |
||||
uint32_t b; |
||||
uint32_t c; |
||||
}; |
||||
|
||||
struct Triangle : Face { |
||||
float area; |
||||
}; |
||||
|
||||
struct Tetrahedron { |
||||
uint32_t a; |
||||
uint32_t b; |
||||
uint32_t c; |
||||
uint32_t d; |
||||
float volume; |
||||
}; |
@ -0,0 +1,14 @@ |
||||
#pragma once |
||||
|
||||
#include <string> |
||||
#include "vulkan/vertex.hpp" |
||||
#include <vector> |
||||
|
||||
struct Face; |
||||
|
||||
class Mesh { |
||||
public: |
||||
explicit Mesh(const std::string &fileName); |
||||
std::vector<Vertex> vertices; |
||||
std::vector<Face> faces; |
||||
}; |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,16 @@ |
||||
#version 450 |
||||
|
||||
layout (local_size_x = 1) in; |
||||
layout (local_size_x = 32) in; |
||||
|
||||
struct Vertex { |
||||
vec3 position; |
||||
vec3 color; |
||||
}; |
||||
|
||||
layout (std140, binding = 0) buffer VertexBuffer { |
||||
layout (std140, set = 0, binding = 0) buffer VertexBuffer { |
||||
Vertex vertices[]; |
||||
}; |
||||
|
||||
void main() { |
||||
vertices[0].position.z += 0.001; |
||||
// vertices[0].position.z += 0.001; |
||||
} |
@ -0,0 +1 @@ |
||||
#include "constraints.hpp" |
@ -0,0 +1,25 @@ |
||||
#include "mesh.hpp" |
||||
#include <assimp/Importer.hpp> |
||||
#include <assimp/scene.h> |
||||
#include <assimp/postprocess.h> |
||||
#include "constraints.hpp" |
||||
|
||||
|
||||
Mesh::Mesh(const std::string &fileName) { |
||||
Assimp::Importer importer; |
||||
auto scene = importer.ReadFile(fileName, aiProcess_Triangulate); |
||||
|
||||
auto mesh = scene->mMeshes[0]; |
||||
|
||||
for (size_t i = 0; i < mesh->mNumVertices; i++){ |
||||
vertices.push_back({ |
||||
*reinterpret_cast<glm::vec3*>(&mesh->mVertices[i]), |
||||
glm::vec3(1, 0, 0) |
||||
}); |
||||
} |
||||
|
||||
for (size_t i = 0; i < mesh->mNumFaces; i++){ |
||||
faces.push_back(*reinterpret_cast<Face*>(mesh->mFaces[i].mIndices)); |
||||
} |
||||
|
||||
} |
@ -1,5 +1,73 @@ |
||||
#include "soft_body.hpp" |
||||
#include "mesh.hpp" |
||||
#include "constraints.hpp" |
||||
#include "tetgen.h" |
||||
|
||||
SoftBody::SoftBody(const std::string &fileName) { |
||||
SoftBody::SoftBody(Mesh* mesh, float compliance) : compliance(compliance) { |
||||
edges.push_back(Edge(0, 1, 10)); |
||||
triangles.push_back(Triangle(Face(0, 1, 2), 40)); |
||||
tetrahedra.push_back(Tetrahedron(0, 1, 2, 3, 50)); |
||||
|
||||
|
||||
tetgenbehavior behavior; |
||||
behavior.parse_commandline(std::string("pYa0.01Qfez").data()); |
||||
|
||||
tetgenio in; |
||||
in.numberofpoints = static_cast<int>(mesh->vertices.size()); |
||||
in.pointlist = new REAL[mesh->vertices.size() * 3]; |
||||
in.numberoffacets = static_cast<int>(mesh->faces.size()); |
||||
in.facetlist = new tetgenio::facet[mesh->faces.size()]; |
||||
in.numberofpointattributes = 3; |
||||
in.pointattributelist = new REAL[mesh->vertices.size() * 3]; |
||||
|
||||
for (size_t i = 0; i < mesh->vertices.size(); i++){ |
||||
in.pointlist[i * 3 + 0] = mesh->vertices[i].pos.x; |
||||
in.pointlist[i * 3 + 1] = mesh->vertices[i].pos.y; |
||||
in.pointlist[i * 3 + 2] = mesh->vertices[i].pos.z; |
||||
in.pointattributelist[i * 3 + 0] = (mesh->vertices[i].pos.x + 1) / 2; |
||||
in.pointattributelist[i * 3 + 1] = (mesh->vertices[i].pos.y + 1) / 2; |
||||
in.pointattributelist[i * 3 + 2] = (mesh->vertices[i].pos.z + 1) / 2; |
||||
} |
||||
|
||||
for (size_t i = 0; i < mesh->faces.size(); i++){ |
||||
tetgenio::facet &f = in.facetlist[i]; |
||||
tetgenio::polygon p; |
||||
|
||||
p.numberofvertices = 3; |
||||
p.vertexlist = new int[3]; |
||||
p.vertexlist[0] = static_cast<int>(mesh->faces[i].a); |
||||
p.vertexlist[1] = static_cast<int>(mesh->faces[i].b); |
||||
p.vertexlist[2] = static_cast<int>(mesh->faces[i].c); |
||||
|
||||
f.numberofholes = 0; |
||||
f.holelist = nullptr; |
||||
f.numberofpolygons = 1; |
||||
f.polygonlist = new tetgenio::polygon[1]; |
||||
f.polygonlist[0] = p; |
||||
} |
||||
|
||||
tetgenio out; |
||||
tetrahedralize(&behavior, &in, &out); |
||||
|
||||
vertices.reserve(out.numberofpoints / 3); |
||||
for (size_t i = 0; i < out.numberofpoints; i++){ |
||||
float x = static_cast<float>(out.pointlist[i * 3 + 0]); |
||||
float y = static_cast<float>(out.pointlist[i * 3 + 1]); |
||||
float z = static_cast<float>(out.pointlist[i * 3 + 2]); |
||||
float r = static_cast<float>(out.pointattributelist[i * 3 + 0]); |
||||
float g = static_cast<float>(out.pointattributelist[i * 3 + 1]); |
||||
float b = static_cast<float>(out.pointattributelist[i * 3 + 2]); |
||||
vertices.emplace_back(Vertex({x, y, z}, {r, g, b})); |
||||
} |
||||
|
||||
faces.reserve(out.numberoftrifaces); |
||||
for (size_t i = 0; i < out.numberoftrifaces; i++){ |
||||
uint32_t a = out.trifacelist[i * 3 + 0]; |
||||
uint32_t b = out.trifacelist[i * 3 + 1]; |
||||
uint32_t c = out.trifacelist[i * 3 + 2]; |
||||
if (out.trifacemarkerlist[i] != 0) |
||||
faces.emplace_back(Face(a, b, c)); |
||||
} |
||||
faces.shrink_to_fit(); |
||||
|
||||
} |
||||
|
Loading…
Reference in new issue