1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "Scene.h"
#include "Cloth.h"
#include "Obstacles.h"
#include "Shape.h"
#include "Preprocessor.h"
#include "Collisions.h"
#include "Constraints.h"
#include "GeneralizedSolver.h"
#include "matlabOutputs.h"

#include "external\ArcSim\dynamicremesh.hpp"

#ifdef EOLC_ONLINE
#include "online\MatrixStack.h"
#include "online\Program.h"
#endif // EOLC_ONLINE


using namespace std;
using namespace Eigen;

Scene::Scene() : 
	h(0.005),
	grav(Vector3d(0.0,0.0,-9.8)),
	part(0)
{
	cloth = make_shared<Cloth>();
	obs = make_shared<Obstacles>();
	GS = make_shared<GeneralizedSolver>();
}

void Scene::load(const string &RESOURCE_DIR)
{
	obs->load(RESOURCE_DIR);
}

void Scene::init(const bool online, const bool exportObjs)
{
#ifdef EOLC_ONLINE
	if (online) {
		cloth->init();
		obs->init();
	}
#endif

	cloth->consts->init(obs);

	if (exportObjs) {

	}
}

void printstate(Mesh& mesh)
{
	for (int n = 0; n < mesh.nodes.size(); n++) {
		if (mesh.nodes[n]->EoL) {
			cout << mesh.nodes[n]->EoL_state << endl;
		}
	}
}

void Scene::step()
{
	if (part != 0) {
		cout << "Please finish the partial step before making a full step" << endl;
		return;
	}
	cloth->updatePreviousMesh();
	dynamic_remesh(cloth->mesh);
	set_indices(cloth->mesh);
	CD(cloth->mesh, obs, cls);
	//dynamic_remesh(cloth->mesh);
	preprocess(cloth->mesh, cls);
	//reindex_nodes(cloth->mesh.nodes);
	set_indices(cloth->mesh);
	cout << "pre" << endl;
	dynamic_remesh(cloth->mesh);
	set_indices(cloth->mesh);
	//preprocessClean(cloth->mesh);
	//set_indices(cloth->mesh);
	//cloth->consts->fill(cloth->mesh, obs, h);
	//printstate(cloth->mesh);
	//cloth->velocityTransfer();
	//cloth->updateBuffers();
	cloth->step(GS, obs, grav, h);
	obs->step(h);
	cls.clear();
	mesh2m(cloth->mesh, "mesh.m", true);
	cout << "step" << endl;
}

void Scene::partialStep()
{
	if (part == 0) {
		dynamic_remesh(cloth->mesh);
		set_indices(cloth->mesh);
		CD(cloth->mesh, obs, cls);
		cout << "CD" << endl;
	}
	else if (part >= 1 && part < 8) {
		preprocessPart(cloth->mesh, cls, part);
		set_indices(cloth->mesh);
		cloth->updateBuffers();
		mesh2m(cloth->mesh, "mesh.m", true);
	}
	else if (part == 8) {
		dynamic_remesh(cloth->mesh);
		set_indices(cloth->mesh);
		cloth->updateBuffers();
	}
	else if (part == 9) {
		cloth->updateBuffers();
		cout << "Finished step" << endl;
		cls.clear();
		part = -1;
	}
	part++;
}

#ifdef EOLC_ONLINE
void Scene::draw(std::shared_ptr<MatrixStack> MV, const std::shared_ptr<Program> p) const
{
	obs->draw(MV,p);

	glUniform3fv(p->getUniform("kdFront"), 1, Vector3f(1.0, 0.5, 0.5).data());
	glUniform3fv(p->getUniform("kdBack"), 1, Vector3f(1.0, 0.5, 0.5).data());
	cloth->draw(MV, p);
}

void Scene::drawSimple(std::shared_ptr<MatrixStack> MV, const std::shared_ptr<Program> p) const
{
	obs->drawSimple(MV, p);
	cloth->consts->drawSimple(MV, p);
	cloth->drawSimple(MV, p);
}
#endif // EOLC_ONLINE