aboutsummaryrefslogtreecommitdiff
path: root/demo/scenes/rigidpile.h
blob: dcd12820a5818eaf7c85af2968e404ebb8b438a9 (plain) (blame)
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
class RigidPile : public Scene
{
public:

	RigidPile(const char* name, int brickHeight) : Scene(name), mHeight(brickHeight)
	{
	}
	
	virtual void Initialize()
	{
		int sx = 2;
		int sy = mHeight;
		int sz = 2;

		Vec3 lower(0.0f, 1.5f + g_params.radius*0.25f, 0.0f);

		int dimx = 10;
		int dimy = 10;
		int dimz = 10;

		float radius = g_params.radius;

		if (1)
		{
			Mesh* mesh = ImportMesh(GetFilePathByPlatform("../../data/box.ply").c_str());

			// create a basic grid
			for (int y=0; y < dimy; ++y)
				for (int z=0; z < dimz; ++z)
					for (int x=0; x < dimx; ++x)
						CreateParticleShape(
						mesh,
						(g_params.radius*0.905f)*Vec3(float(x*sx), float(y*sy), float(z*sz)) + (g_params.radius*0.1f)*Vec3(float(x),float(y),float(z)) + lower,
						g_params.radius*0.9f*Vec3(float(sx), float(sy), float(sz)), 0.0f, g_params.radius*0.9f, Vec3(0.0f), 1.0f, true, 1.0f, NvFlexMakePhase(g_buffers->rigidOffsets.size()+1, 0), true, 0.002f);// 0.002f);
		

			delete mesh;

			AddPlinth();
		}
		else
		{
			// brick work
			int wdimx = 10;
			int wdimy = 10;

			int bdimx = 4;
			int bdimy = 2;
			int bdimz = 2;

			for (int y=0; y < wdimy; ++y)
			{
				for (int x=0; x < wdimx; ++x)
				{
					Vec3 lower = Vec3(x*bdimx*radius + 0.5f*radius, 0.93f*bdimy*y*radius, 0.0f);

					if (y&1)
						lower += Vec3(bdimx*0.25f*radius + 0.5f*radius, 0.0f, 0.0f);

					//CreateParticleGrid(lower, bdimx, bdimy, bdimz, radius, Vec3(0.0f), 1.0f, true, g_buffers->rigidOffsets.size()+1, 0.0f);
					CreateParticleShape(GetFilePathByPlatform("../../data/box.ply").c_str(), lower + RandomUnitVector()*Vec3(0.0f, 0.0f, 0.0f), Vec3(bdimx*radius, bdimy*radius, bdimz*radius), 0.0f, radius, Vec3(0.0f), 1.0f, true, 1.0f, NvFlexMakePhase(g_buffers->rigidOffsets.size()+1, 0), true, 0.0f, Vec3(0.0f, 0.0f, y*0.0001f));
				}
			}
			
			if (0)
			{
				// create a basic grid
				for (int y=0; y < dimy; ++y)
					for (int z=0; z < 1; ++z)
						for (int x=0; x < 1; ++x)
							CreateParticleShape(
							GetFilePathByPlatform("../../data/box.ply").c_str(), 
							0.99f*(g_params.radius)*Vec3(float(x*sx), float(y*sy), float(z*sz)),
							g_params.radius*Vec3(float(sx), float(sy), float(sz)), 0.0f, g_params.radius, Vec3(0.0f), 1.0f, true, 1.0f, NvFlexMakePhase(g_buffers->rigidOffsets.size()+1, 0), true, 0.0f);

				// create a basic grid
				for (int y=0; y < dimy; ++y)
					for (int z=0; z < 1; ++z)
						for (int x=0; x < 1; ++x)
							CreateParticleShape(
							GetFilePathByPlatform("../../data/box.ply").c_str(), 
							0.99f*(g_params.radius)*Vec3(float(sx*2 + x*sx), float(y*sy), float(z*sz)),
							g_params.radius*Vec3(float(sx), float(sy), float(sz)), 0.0f, g_params.radius, Vec3(0.0f), 1.0f, true, 1.0f, NvFlexMakePhase(g_buffers->rigidOffsets.size()+1, 0), true, 0.0f);
			}

		}
		

		if (0)
		{
			float stretchStiffness = 1.0f;
			float bendStiffness = 0.5f;
			float shearStiffness = 0.7f;

			int dimx = 40;
			int dimy = 40;

			CreateSpringGrid(Vec3(-1.0f, 1.0f + g_params.radius*0.5f, -1.0f), dimx, dimy, 1, g_params.radius*0.9f, NvFlexMakePhase(0, eNvFlexPhaseSelfCollide), stretchStiffness, bendStiffness, shearStiffness, Vec3(0.0f), 1.0f);
		}


		//g_numExtraParticles = 32*1024;		
		g_numSubsteps = 2;
		g_params.numIterations = 8;

		g_params.radius *= 1.0f;
		g_params.dynamicFriction = 0.4f;
		g_params.dissipation = 0.01f;
		g_params.particleCollisionMargin = g_params.radius*0.05f;
		g_params.sleepThreshold = g_params.radius*0.25f;
		g_params.shockPropagation = 3.f;
		
		g_windStrength = 0.0f;

		// draw options
		g_drawPoints = false;

		g_emitters[0].mEnabled = true;
		g_emitters[0].mSpeed = (g_params.radius*2.0f/g_dt);
	}

	virtual void Update()
	{
			
	}

	int mHeight;
};