Skip to content

Commit

Permalink
Merge pull request #5 from frostsim/develop
Browse files Browse the repository at this point in the history
master <- develop
  • Loading branch information
jklae authored Aug 4, 2021
2 parents 36f1066 + 1460bb2 commit b9b866d
Show file tree
Hide file tree
Showing 163 changed files with 423 additions and 12,372 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudio,c++,cmake
### Custon ###
*.ply

### C++ ###
# Prerequisites
Expand Down
11 changes: 3 additions & 8 deletions .gitmessage
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@

# Issue Tracker Number or URL

# --- COMMIT END ---
# Type can be
# --- COMMIT TYPE ---
# feat : adding, removing, changing features
# fix : bug fix
# refactor: refactoring production code
# style : formatting, missing semi colons, etc; no code change
# docs : changes to documentation
# file : changes to files
# test : adding or refactoring tests
# no production code change
# chore : updating grunt tasks etc
# no production code change
# chore : updating grunt tasks etc; no code change
# ------------------
# Remember
# 1. Capitalize the subject line
# 1. Capitalize the subject line (except TYPE)
# 2. Use the imperative mood in the subject line
# 3. Do not end the subject line with a period
# 4. Separate subject from body with a blank line
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ext/DXViewer"]
path = ext/DXViewer
url = https://github.com/jklee95/DXViewer.git
23 changes: 19 additions & 4 deletions CmakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.19.0)
SET( PROJECT_NAME FlipEngine )
PROJECT(${PROJECT_NAME})

# Set configuration types
Set(CMAKE_CONFIGURATION_TYPES Debug Release)

# Set the include/lib directory
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ext/DXViewer/DXViewer-1.0.0/include)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/ext/DXViewer/DXViewer-1.0.0/lib)

# Copy DLLs
FILE(GLOB DLL ${CMAKE_SOURCE_DIR}/ext/DXViewer/DXViewer-1.0.0/bin/*.dll)
FILE(COPY ${DLL} DESTINATION ${CMAKE_BINARY_DIR})

# Collect source files
FILE( GLOB SRC src/*.cpp )
FILE( GLOB HDR src/*.h )
FILE( GLOB SRC ${CMAKE_SOURCE_DIR}/src/engine/*.cpp ${CMAKE_SOURCE_DIR}/src/*.cpp)
FILE( GLOB HDR ${CMAKE_SOURCE_DIR}/src/engine/*.h ${CMAKE_SOURCE_DIR}/src/*.h)

# Link Source files ('WIN32' keyword is used for win32 project)
ADD_EXECUTABLE( ${PROJECT_NAME} WIN32 ${SRC} ${HDR} )

# Link Source files
ADD_EXECUTABLE( ${PROJECT_NAME} ${SRC} ${HDR} )
# Set 'Additional Dependencies'
SET(LIB $<$<CONFIG:DEBUG>:DXViewer.lib> $<$<CONFIG:RELEASE>:DXViewerRel.lib>)
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${LIB})
1 change: 1 addition & 0 deletions ext/DXViewer
Submodule DXViewer added at dc9957
Binary file added ply/fluid_0.ply
Binary file not shown.
227 changes: 227 additions & 0 deletions src/SubFluidSimulation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
#include "SubFluidSimulation.h"

using namespace std;
using namespace vmath;
using namespace DirectX;

SubFluidSimulation::SubFluidSimulation(int isize, int jsize, int ksize, double dx)
:FluidSimulation(isize, jsize, ksize, dx)
{
}

SubFluidSimulation::~SubFluidSimulation()
{
}

void SubFluidSimulation::_outputSurfaceMeshThread(std::vector<vmath::vec3>* particles,
MeshLevelSet* solidSDF)
{
if (!_isSurfaceMeshReconstructionEnabled) { return; }

_logfile.logString(_logfile.getTime() + " BEGIN Generate Surface Mesh");

StopWatch t;
t.start();

_applyMeshingVolumeToSDF(solidSDF);
_filterParticlesOutsideMeshingVolume(particles);

TriangleMesh isomesh, previewmesh;
_polygonizeOutputSurface(isomesh, previewmesh, particles, solidSDF);
delete particles;
delete solidSDF;

isomesh.removeMinimumTriangleCountPolyhedra(_minimumSurfacePolyhedronTriangleCount);

_removeMeshNearDomain(isomesh);
_smoothSurfaceMesh(isomesh);
_smoothSurfaceMesh(previewmesh);
_invertContactNormals(isomesh);

if (_isSurfaceMotionBlurEnabled) {
TriangleMesh blurData;
blurData.vertices.reserve(isomesh.vertices.size());
double dt = _currentFrameDeltaTime;
for (size_t i = 0; i < isomesh.vertices.size(); i++) {
vmath::vec3 p = isomesh.vertices[i];
vmath::vec3 t = _MACVelocity.evaluateVelocityAtPositionLinear(p) * _domainScale * dt;
blurData.vertices.push_back(t);
}

_getTriangleMeshFileData(blurData, _outputData.surfaceBlurData);
_outputData.frameData.surfaceblur.enabled = 1;
_outputData.frameData.surfaceblur.vertices = (int)blurData.vertices.size();
_outputData.frameData.surfaceblur.triangles = (int)blurData.triangles.size();
_outputData.frameData.surfaceblur.bytes = (unsigned int)_outputData.surfaceBlurData.size();
}

vmath::vec3 scale(_domainScale, _domainScale, _domainScale);
isomesh.scale(scale);
isomesh.translate(_domainOffset);
previewmesh.scale(scale);
previewmesh.translate(_domainOffset);

_getTriangleMeshFileData(isomesh, _outputData.surfaceData);

_outputData.frameData.surface.enabled = 1;
_outputData.frameData.surface.vertices = (int)isomesh.vertices.size();
_outputData.frameData.surface.triangles = (int)isomesh.triangles.size();
_outputData.frameData.surface.bytes = (unsigned int)_outputData.surfaceData.size();

if (_isPreviewSurfaceMeshEnabled) {
_getTriangleMeshFileData(previewmesh, _outputData.surfacePreviewData);
_outputData.frameData.preview.enabled = 1;
_outputData.frameData.preview.vertices = (int)previewmesh.vertices.size();
_outputData.frameData.preview.triangles = (int)previewmesh.triangles.size();
_outputData.frameData.preview.bytes = (unsigned int)_outputData.surfacePreviewData.size();
}

t.stop();
_timingData.outputMeshSimulationData += t.getTime();

_logfile.logString(_logfile.getTime() + " COMPLETE Generate Surface Mesh");

isomesh2 = isomesh;

}


void SubFluidSimulation::writeSurfaceMesh(int frameno) {
std::ostringstream ss;
ss << frameno;
std::string frameString = ss.str();
//frameString.insert(frameString.begin(), 6 - frameString.size(), '0');
std::string filepath = "ply/fluid_" + frameString + ".ply";

std::vector<char>* data = getSurfaceData();
std::ofstream ply(filepath.c_str(), std::ios::out | std::ios::binary);
ply.write(data->data(), data->size());
ply.close();
}

TriangleMesh SubFluidSimulation::getTriangleMeshFromAABB(AABB bbox) {
vmath::vec3 p = bbox.position;
std::vector<vmath::vec3> verts{
vmath::vec3(p.x, p.y, p.z),
vmath::vec3(p.x + bbox.width, p.y, p.z),
vmath::vec3(p.x + bbox.width, p.y, p.z + bbox.depth),
vmath::vec3(p.x, p.y, p.z + bbox.depth),
vmath::vec3(p.x, p.y + bbox.height, p.z),
vmath::vec3(p.x + bbox.width, p.y + bbox.height, p.z),
vmath::vec3(p.x + bbox.width, p.y + bbox.height, p.z + bbox.depth),
vmath::vec3(p.x, p.y + bbox.height, p.z + bbox.depth)
};

std::vector<Triangle> tris{
Triangle(0, 1, 2), Triangle(0, 2, 3), Triangle(4, 7, 6), Triangle(4, 6, 5),
Triangle(0, 3, 7), Triangle(0, 7, 4), Triangle(1, 5, 6), Triangle(1, 6, 2),
Triangle(0, 4, 5), Triangle(0, 5, 1), Triangle(3, 2, 6), Triangle(3, 6, 7)
};

TriangleMesh m;
m.vertices = verts;
m.triangles = tris;

return m;
}


void SubFluidSimulation::initialize()
{
setSurfaceSubdivisionLevel(2);

double x, y, z;
getSimulationDimensions(&x, &y, &z);

double boxWidth = (1.0 / 3.0) * x;
double boxHeight = (1.0 / 3.0) * y;
double boxDepth = (1.0 / 3.0) * z;
vmath::vec3 boxPosition(0.5 * (x - boxWidth), 0.5 * (y - boxHeight), 0.5 * (z - boxDepth));
AABB box(boxPosition, boxWidth, boxHeight, boxDepth);
TriangleMesh boxMesh = getTriangleMeshFromAABB(box);
MeshObject boxFluidObject(_isize, _jsize, _ksize, _dx);
boxFluidObject.updateMeshStatic(boxMesh);
addMeshFluid(boxFluidObject);

addBodyForce(0.0, -25.0, 0.0);
FluidSimulation::initialize();

}




void SubFluidSimulation::IUpdate(double timestep)
{
int frameno = getCurrentFrame();
FluidSimulation::update(timestep);
writeSurfaceMesh(frameno);
}

vector<Vertex> SubFluidSimulation::IGetVertice()
{
vector<Vertex> vertice;
vector<vec3> normal;

for (int i = 0; i < isomesh2.vertices.size(); i++)
{
Vertex v;
v.pos.x = isomesh2.vertices[i].x;
v.pos.y = isomesh2.vertices[i].y;
v.pos.z = isomesh2.vertices[i].z;

normal.push_back(vec3(0.0f, 0.0f, 0.0f));

vertice.push_back(v);
}


for (int i = 0; i < isomesh2.triangles.size(); i++)
{
int i0 = isomesh2.triangles[i].tri[0];
int i1 = isomesh2.triangles[i].tri[1];
int i2 = isomesh2.triangles[i].tri[2];


vec3 v0 = isomesh2.vertices[i0];
vec3 v1 = isomesh2.vertices[i1];
vec3 v2 = isomesh2.vertices[i2];

vec3 e0 = v1 - v0;
vec3 e1 = v2 - v0;
vec3 faceN = cross(e0, e1);

normal[i0] += faceN;
normal[i1] += faceN;
normal[i2] += faceN;
}


for (int i = 0; i < isomesh2.vertices.size(); i++)
{
vec3 nor = normalize(normal[i]);
vertice[i].nor.x = nor.x;
vertice[i].nor.y = nor.y;
vertice[i].nor.z = nor.z;
}

return vertice;
}

vector<unsigned int> SubFluidSimulation::IGetIndice()
{
vector<unsigned int> indice;
indice.clear();

for (int i = 0; i < isomesh2.triangles.size(); i++)
{
for (int j = 0; j < 3; j++)
{
unsigned int a = static_cast<unsigned int>(isomesh2.triangles[i].tri[j]);
indice.push_back(a);
}
//std::cout << "\n";
}

return indice;
}
29 changes: 29 additions & 0 deletions src/SubFluidSimulation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include <fstream>
#include "engine/fluidsimulation.h"
#include "engine/stopwatch.h"
#include "Win32App.h" // This includes ISimulation.h

class SubFluidSimulation : public FluidSimulation, public ISimulation
{
private:
TriangleMesh isomesh2;
void _outputSurfaceMeshThread(std::vector<vmath::vec3>* particles, MeshLevelSet* solidSDF) override;

// The ones originally in main.cpp
void writeSurfaceMesh(int frameno);
TriangleMesh getTriangleMeshFromAABB(AABB bbox);


public:
SubFluidSimulation(int isize, int jsize, int ksize, double dx);
~SubFluidSimulation();

void initialize() override;

// Functions for virtual class
void IUpdate(double timestep) override;
std::vector<Vertex> IGetVertice() override;
std::vector<unsigned int> IGetIndice() override;
};

37 changes: 0 additions & 37 deletions src/c_bindings/aabb_c.h

This file was deleted.

Loading

0 comments on commit b9b866d

Please sign in to comment.