2015-05-02 04:34:27 +00:00
|
|
|
#include "ConcaveScene.h"
|
|
|
|
#include "GpuRigidBodyDemo.h"
|
|
|
|
#include "OpenGLWindow/ShapeData.h"
|
|
|
|
|
|
|
|
#include "OpenGLWindow/GLInstancingRenderer.h"
|
|
|
|
#include "Bullet3Common/b3Quaternion.h"
|
|
|
|
#include "OpenGLWindow/b3gWindowInterface.h"
|
|
|
|
#include "Bullet3OpenCL/BroadphaseCollision/b3GpuSapBroadphase.h"
|
|
|
|
#include "../GpuDemoInternalData.h"
|
|
|
|
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
|
|
|
|
#include "OpenGLWindow/OpenGLInclude.h"
|
|
|
|
#include "OpenGLWindow/GLInstanceRendererInternalData.h"
|
|
|
|
#include "Bullet3OpenCL/ParallelPrimitives/b3LauncherCL.h"
|
|
|
|
#include "Bullet3OpenCL/RigidBody/b3GpuRigidBodyPipeline.h"
|
|
|
|
#include "Bullet3OpenCL/RigidBody/b3GpuNarrowPhase.h"
|
|
|
|
#include "Bullet3Collision/NarrowPhaseCollision/b3Config.h"
|
|
|
|
#include "GpuRigidBodyDemoInternalData.h"
|
2018-09-23 21:17:31 +00:00
|
|
|
#include "../../Wavefront/tiny_obj_loader.h"
|
2015-05-02 04:34:27 +00:00
|
|
|
#include "Bullet3Common/b3Transform.h"
|
|
|
|
#include "Bullet3Collision/NarrowPhaseCollision/b3ConvexUtility.h"
|
|
|
|
|
|
|
|
#include "Bullet3AppSupport/gwenUserInterface.h"
|
|
|
|
#include "OpenGLWindow/GLInstanceGraphicsShape.h"
|
|
|
|
#define CONCAVE_GAPX 14
|
|
|
|
#define CONCAVE_GAPY 5
|
|
|
|
#define CONCAVE_GAPZ 14
|
|
|
|
|
|
|
|
GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(std::vector<tinyobj::shape_t>& shapes)
|
|
|
|
{
|
|
|
|
b3AlignedObjectArray<GLInstanceVertex>* vertices = new b3AlignedObjectArray<GLInstanceVertex>;
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// int numVertices = obj->vertexCount;
|
|
|
|
// int numIndices = 0;
|
2015-05-02 04:34:27 +00:00
|
|
|
b3AlignedObjectArray<int>* indicesPtr = new b3AlignedObjectArray<int>;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int s = 0; s < shapes.size(); s++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
tinyobj::shape_t& shape = shapes[s];
|
|
|
|
int faceCount = shape.mesh.indices.size();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int f = 0; f < faceCount; f += 3)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
//b3Vector3 normal(face.m_plane[0],face.m_plane[1],face.m_plane[2]);
|
|
|
|
if (1)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 normal = b3MakeVector3(0, 1, 0);
|
2015-05-02 04:34:27 +00:00
|
|
|
int vtxBaseIndex = vertices->size();
|
|
|
|
|
|
|
|
indicesPtr->push_back(vtxBaseIndex);
|
2018-09-23 21:17:31 +00:00
|
|
|
indicesPtr->push_back(vtxBaseIndex + 1);
|
|
|
|
indicesPtr->push_back(vtxBaseIndex + 2);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
GLInstanceVertex vtx0;
|
2018-09-23 21:17:31 +00:00
|
|
|
vtx0.xyzw[0] = shape.mesh.positions[shape.mesh.indices[f] * 3 + 0];
|
|
|
|
vtx0.xyzw[1] = shape.mesh.positions[shape.mesh.indices[f] * 3 + 1];
|
|
|
|
vtx0.xyzw[2] = shape.mesh.positions[shape.mesh.indices[f] * 3 + 2];
|
2015-05-02 04:34:27 +00:00
|
|
|
vtx0.xyzw[3] = 0.f;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
vtx0.uv[0] = 0.5f; //shape.mesh.positions[shape.mesh.indices[f]*3+2];?
|
2015-05-02 04:34:27 +00:00
|
|
|
vtx0.uv[1] = 0.5f;
|
|
|
|
|
|
|
|
GLInstanceVertex vtx1;
|
2018-09-23 21:17:31 +00:00
|
|
|
vtx1.xyzw[0] = shape.mesh.positions[shape.mesh.indices[f + 1] * 3 + 0];
|
|
|
|
vtx1.xyzw[1] = shape.mesh.positions[shape.mesh.indices[f + 1] * 3 + 1];
|
|
|
|
vtx1.xyzw[2] = shape.mesh.positions[shape.mesh.indices[f + 1] * 3 + 2];
|
|
|
|
vtx1.xyzw[3] = 0.f;
|
|
|
|
vtx1.uv[0] = 0.5f; //obj->textureList[face->vertex_index[1]]->e[0];
|
|
|
|
vtx1.uv[1] = 0.5f; //obj->textureList[face->vertex_index[1]]->e[1];
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
GLInstanceVertex vtx2;
|
2018-09-23 21:17:31 +00:00
|
|
|
vtx2.xyzw[0] = shape.mesh.positions[shape.mesh.indices[f + 2] * 3 + 0];
|
|
|
|
vtx2.xyzw[1] = shape.mesh.positions[shape.mesh.indices[f + 2] * 3 + 1];
|
|
|
|
vtx2.xyzw[2] = shape.mesh.positions[shape.mesh.indices[f + 2] * 3 + 2];
|
2015-05-02 04:34:27 +00:00
|
|
|
vtx2.xyzw[3] = 0.f;
|
|
|
|
vtx2.uv[0] = 0.5f;
|
|
|
|
vtx2.uv[1] = 0.5f;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 v0 = b3MakeVector3(vtx0.xyzw[0], vtx0.xyzw[1], vtx0.xyzw[2]);
|
|
|
|
b3Vector3 v1 = b3MakeVector3(vtx1.xyzw[0], vtx1.xyzw[1], vtx1.xyzw[2]);
|
|
|
|
b3Vector3 v2 = b3MakeVector3(vtx2.xyzw[0], vtx2.xyzw[1], vtx2.xyzw[2]);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
normal = (v1 - v0).cross(v2 - v0);
|
2015-05-02 04:34:27 +00:00
|
|
|
normal.normalize();
|
|
|
|
vtx0.normal[0] = normal[0];
|
|
|
|
vtx0.normal[1] = normal[1];
|
|
|
|
vtx0.normal[2] = normal[2];
|
|
|
|
vtx1.normal[0] = normal[0];
|
|
|
|
vtx1.normal[1] = normal[1];
|
|
|
|
vtx1.normal[2] = normal[2];
|
|
|
|
vtx2.normal[0] = normal[0];
|
|
|
|
vtx2.normal[1] = normal[1];
|
|
|
|
vtx2.normal[2] = normal[2];
|
|
|
|
vertices->push_back(vtx0);
|
|
|
|
vertices->push_back(vtx1);
|
|
|
|
vertices->push_back(vtx2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GLInstanceGraphicsShape* gfxShape = new GLInstanceGraphicsShape;
|
|
|
|
gfxShape->m_vertices = vertices;
|
|
|
|
gfxShape->m_numvertices = vertices->size();
|
|
|
|
gfxShape->m_indices = indicesPtr;
|
|
|
|
gfxShape->m_numIndices = indicesPtr->size();
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
gfxShape->m_scaling[i] = 1; //bake the scaling into the vertices
|
2015-05-02 04:34:27 +00:00
|
|
|
return gfxShape;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci, const char* fileName, const b3Vector3& shift, const b3Vector3& scaling)
|
|
|
|
{
|
|
|
|
char relativeFileName[1024];
|
2018-09-23 21:17:31 +00:00
|
|
|
const char* prefix[] = {"./data/", "../data/", "../../data/", "../../../data/", "../../../../data/"};
|
|
|
|
int prefixIndex = -1;
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int numPrefixes = sizeof(prefix) / sizeof(char*);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numPrefixes; i++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
FILE* f = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
sprintf(relativeFileName, "%s%s", prefix[i], fileName);
|
|
|
|
f = fopen(relativeFileName, "r");
|
2015-05-02 04:34:27 +00:00
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
prefixIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (prefixIndex < 0)
|
2015-05-02 04:34:27 +00:00
|
|
|
return;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int index = 10;
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
std::vector<tinyobj::shape_t> shapes;
|
|
|
|
std::string err = tinyobj::LoadObj(shapes, relativeFileName, prefix[prefixIndex]);
|
|
|
|
|
|
|
|
GLInstanceGraphicsShape* shape = createGraphicsShapeFromWavefrontObj(shapes);
|
|
|
|
|
|
|
|
b3AlignedObjectArray<b3Vector3> verts;
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < shape->m_numvertices; i++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < 3; j++)
|
2015-05-02 04:34:27 +00:00
|
|
|
shape->m_vertices->at(i).xyzw[j] += shift[j];
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 vtx = b3MakeVector3(shape->m_vertices->at(i).xyzw[0],
|
|
|
|
shape->m_vertices->at(i).xyzw[1],
|
|
|
|
shape->m_vertices->at(i).xyzw[2]);
|
|
|
|
verts.push_back(vtx * scaling);
|
2015-05-02 04:34:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int colIndex = m_data->m_np->registerConcaveMesh(&verts, shape->m_indices, b3MakeVector3(1, 1, 1));
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int strideInBytes = 9 * sizeof(float);
|
|
|
|
int numVertices = sizeof(cube_vertices) / strideInBytes;
|
|
|
|
int numIndices = sizeof(cube_indices) / sizeof(int);
|
2015-05-02 04:34:27 +00:00
|
|
|
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
|
|
|
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
|
|
|
|
|
|
|
int shapeId = ci.m_instancingRenderer->registerShape(&shape->m_vertices->at(0).xyzw[0], shape->m_numvertices, &shape->m_indices->at(0), shape->m_numIndices);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Quaternion orn(0, 0, 0, 1);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector4 color = b3MakeVector4(0.3, 0.3, 1, 1.f); //0.5);//1.f
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
float mass = 0.f;
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 position = b3MakeVector3(0, 0, 0);
|
|
|
|
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId, position, orn, color, scaling);
|
|
|
|
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass, position, orn, colIndex, index, false);
|
2015-05-02 04:34:27 +00:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete shape->m_indices;
|
|
|
|
delete shape->m_vertices;
|
|
|
|
delete shape;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConcaveScene::setupScene(const ConstructionInfo& ci)
|
|
|
|
{
|
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
//char* fileName = "slopedPlane100.obj";
|
2018-09-23 21:17:31 +00:00
|
|
|
//char* fileName = "plane100.obj";
|
|
|
|
// char* fileName = "plane100.obj";
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
//char* fileName = "teddy.obj";//"plane.obj";
|
|
|
|
// char* fileName = "sponza_closed.obj";//"plane.obj";
|
|
|
|
//char* fileName = "leoTest1.obj";
|
|
|
|
const char* fileName = "samurai_monastry.obj";
|
|
|
|
// char* fileName = "teddy2_VHACD_CHs.obj";
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 shift1 = b3MakeVector3(0, 0, 0); //0,230,80);//150,-100,-120);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector4 scaling = b3MakeVector4(10, 10, 10, 1);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// createConcaveMesh(ci,"plane100.obj",shift1,scaling);
|
2015-05-02 04:34:27 +00:00
|
|
|
//createConcaveMesh(ci,"plane100.obj",shift,scaling);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// b3Vector3 shift2(0,0,0);//0,230,80);//150,-100,-120);
|
|
|
|
// createConcaveMesh(ci,"teddy.obj",shift2,scaling);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// b3Vector3 shift3(130,-150,-75);//0,230,80);//150,-100,-120);
|
|
|
|
// createConcaveMesh(ci,"leoTest1.obj",shift3,scaling);
|
|
|
|
createConcaveMesh(ci, fileName, shift1, scaling);
|
|
|
|
}
|
|
|
|
else
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int strideInBytes = 9 * sizeof(float);
|
|
|
|
int numVertices = sizeof(cube_vertices) / strideInBytes;
|
|
|
|
int numIndices = sizeof(cube_indices) / sizeof(int);
|
|
|
|
int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0], numVertices, cube_indices, numIndices);
|
|
|
|
int group = 1;
|
|
|
|
int mask = 1;
|
|
|
|
int index = 0;
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector4 scaling = b3MakeVector4(400, 1., 400, 1);
|
|
|
|
int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0], strideInBytes, numVertices, scaling);
|
|
|
|
b3Vector3 position = b3MakeVector3(0, -2, 0);
|
|
|
|
b3Quaternion orn(0, 0, 0, 1);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector4 color = b3MakeVector4(0, 0, 1, 1);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId, position, orn, color, scaling);
|
|
|
|
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f, position, orn, colIndex, index, false);
|
2015-05-02 04:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createDynamicObjects(ci);
|
|
|
|
|
|
|
|
m_data->m_rigidBodyPipeline->writeAllInstancesToGpu();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
float camPos[4] = {0, 0, 0, 0}; //65.5,4.5,65.5,0};
|
2015-05-02 04:34:27 +00:00
|
|
|
//float camPos[4]={1,12.5,1.5,0};
|
|
|
|
m_instancingRenderer->setCameraPitch(45);
|
|
|
|
m_instancingRenderer->setCameraTargetPosition(camPos);
|
|
|
|
m_instancingRenderer->setCameraDistance(355);
|
|
|
|
char msg[1024];
|
|
|
|
int numInstances = m_data->m_rigidBodyPipeline->getNumBodies();
|
2018-09-23 21:17:31 +00:00
|
|
|
sprintf(msg, "Num objects = %d", numInstances);
|
2015-05-02 04:34:27 +00:00
|
|
|
if (ci.m_gui)
|
2018-09-23 21:17:31 +00:00
|
|
|
ci.m_gui->setStatusBarMessage(msg, true);
|
2015-05-02 04:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConcaveScene::createDynamicObjects(const ConstructionInfo& ci)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int strideInBytes = 9 * sizeof(float);
|
|
|
|
int numVertices = sizeof(cube_vertices) / strideInBytes;
|
|
|
|
int numIndices = sizeof(cube_indices) / sizeof(int);
|
2015-05-02 04:34:27 +00:00
|
|
|
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
2018-09-23 21:17:31 +00:00
|
|
|
int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0], numVertices, cube_indices, numIndices);
|
|
|
|
int group = 1;
|
|
|
|
int mask = 1;
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int index = 0;
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
int curColor = 0;
|
|
|
|
b3Vector4 colors[4] =
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
b3MakeVector4(1, 1, 1, 1),
|
|
|
|
b3MakeVector4(1, 1, 0.3, 1),
|
|
|
|
b3MakeVector4(0.3, 1, 1, 1),
|
|
|
|
b3MakeVector4(0.3, 0.3, 1, 1),
|
|
|
|
};
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3ConvexUtility* utilPtr = new b3ConvexUtility();
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector4 scaling = b3MakeVector4(1, 1, 1, 1);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
b3AlignedObjectArray<b3Vector3> verts;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
unsigned char* vts = (unsigned char*)cube_vertices;
|
|
|
|
for (int i = 0; i < numVertices; i++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float* vertex = (float*)&vts[i * strideInBytes];
|
|
|
|
verts.push_back(b3MakeVector3(vertex[0] * scaling[0], vertex[1] * scaling[1], vertex[2] * scaling[2]));
|
2015-05-02 04:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool merge = true;
|
|
|
|
if (numVertices)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
utilPtr->initializePolyhedralFeatures(&verts[0], verts.size(), merge);
|
2015-05-02 04:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int colIndex = -1;
|
2015-05-02 04:34:27 +00:00
|
|
|
if (ci.m_useInstancedCollisionShapes)
|
|
|
|
colIndex = m_data->m_np->registerConvexHullShape(utilPtr);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < ci.arraySizeX; i++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < ci.arraySizeY; j++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int k = 0; k < ci.arraySizeZ; k++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
if (!ci.m_useInstancedCollisionShapes)
|
|
|
|
colIndex = m_data->m_np->registerConvexHullShape(utilPtr);
|
|
|
|
|
|
|
|
float mass = 1;
|
|
|
|
|
|
|
|
//b3Vector3 position(-2*ci.gapX+i*ci.gapX,25+j*ci.gapY,-2*ci.gapZ+k*ci.gapZ);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 position = b3MakeVector3(-(ci.arraySizeX / 2) * CONCAVE_GAPX + i * CONCAVE_GAPX,
|
|
|
|
23 + j * CONCAVE_GAPY,
|
|
|
|
-(ci.arraySizeZ / 2) * CONCAVE_GAPZ + k * CONCAVE_GAPZ);
|
|
|
|
b3Quaternion orn(0, 0, 0, 1);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3Vector4 color = colors[curColor];
|
|
|
|
curColor++;
|
2018-09-23 21:17:31 +00:00
|
|
|
curColor &= 3;
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId, position, orn, color, scaling);
|
|
|
|
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass, position, orn, colIndex, index, false);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConcaveCompoundScene::setupScene(const ConstructionInfo& ci)
|
|
|
|
{
|
|
|
|
ConcaveScene::setupScene(ci);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
float camPos[4] = {0, 50, 0, 0}; //65.5,4.5,65.5,0};
|
2015-05-02 04:34:27 +00:00
|
|
|
//float camPos[4]={1,12.5,1.5,0};
|
|
|
|
m_instancingRenderer->setCameraPitch(45);
|
|
|
|
m_instancingRenderer->setCameraTargetPosition(camPos);
|
|
|
|
m_instancingRenderer->setCameraDistance(40);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
|
|
|
|
{
|
|
|
|
const char* fileName = "teddy2_VHACD_CHs.obj";
|
|
|
|
//char* fileName = "cube_offset.obj";
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 shift = b3MakeVector3(0, 0, 0); //0,230,80);//150,-100,-120);
|
|
|
|
b3Vector4 scaling = b3MakeVector4(1, 1, 1, 1);
|
|
|
|
const char* prefix[] = {"./data/", "../data/", "../../data/", "../../../data/", "../../../../data/"};
|
|
|
|
int prefixIndex = -1;
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
char relativeFileName[1024];
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int numPrefixes = sizeof(prefix) / sizeof(char*);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numPrefixes; i++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
sprintf(relativeFileName, "%s%s", prefix[i], fileName);
|
2015-05-02 04:34:27 +00:00
|
|
|
FILE* f = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
f = fopen(relativeFileName, "r");
|
2015-05-02 04:34:27 +00:00
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
prefixIndex = i;
|
|
|
|
fclose(f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (prefixIndex < 0)
|
2015-05-02 04:34:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<tinyobj::shape_t> shapes;
|
|
|
|
std::string err = tinyobj::LoadObj(shapes, relativeFileName, prefix[prefixIndex]);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (shapes.size() > 0)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int strideInBytes = 9 * sizeof(float);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3AlignedObjectArray<GLInstanceVertex> vertexArray;
|
|
|
|
b3AlignedObjectArray<int> indexArray;
|
|
|
|
|
|
|
|
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
2018-09-23 21:17:31 +00:00
|
|
|
int group = 1;
|
|
|
|
int mask = 1;
|
|
|
|
int index = 0;
|
2015-05-02 04:34:27 +00:00
|
|
|
int colIndex = 0;
|
|
|
|
|
|
|
|
b3AlignedObjectArray<GLInstanceVertex> vertices;
|
|
|
|
int stride2 = sizeof(GLInstanceVertex);
|
|
|
|
b3Assert(stride2 == strideInBytes);
|
|
|
|
|
|
|
|
{
|
|
|
|
b3AlignedObjectArray<b3GpuChildShape> childShapes;
|
|
|
|
|
|
|
|
int numChildShapes = shapes.size();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numChildShapes; i++)
|
|
|
|
// int i=4;
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
tinyobj::shape_t& shape = shapes[i];
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int numVertices = shape.mesh.positions.size() / 3;
|
|
|
|
int numFaces = shape.mesh.indices.size() / 3;
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
//for now, only support polyhedral child shapes
|
|
|
|
b3GpuChildShape child;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 pos = b3MakeVector3(0, 0, 0);
|
|
|
|
b3Quaternion orn(0, 0, 0, 1);
|
|
|
|
for (int v = 0; v < 4; v++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
child.m_childPosition[v] = pos[v];
|
|
|
|
child.m_childOrientation[v] = orn[v];
|
|
|
|
}
|
|
|
|
|
|
|
|
b3Transform tr;
|
|
|
|
tr.setIdentity();
|
|
|
|
tr.setOrigin(pos);
|
|
|
|
tr.setRotation(orn);
|
|
|
|
|
|
|
|
int baseIndex = vertexArray.size();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int f = 0; f < numFaces; f++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 3; i++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
indexArray.push_back(baseIndex + shape.mesh.indices[f * 3 + i]);
|
2015-05-02 04:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 center = b3MakeVector3(0, 0, 0);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3AlignedObjectArray<GLInstanceVertex> tmpVertices;
|
|
|
|
//add transformed graphics vertices and indices
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 myScaling = b3MakeVector3(50, 50, 50); //300,300,300);
|
|
|
|
for (int v = 0; v < numVertices; v++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
GLInstanceVertex vert;
|
|
|
|
|
|
|
|
vert.uv[0] = 0.5f;
|
|
|
|
vert.uv[1] = 0.5f;
|
2018-09-23 21:17:31 +00:00
|
|
|
vert.normal[0] = 0.f;
|
|
|
|
vert.normal[1] = 1.f;
|
|
|
|
vert.normal[2] = 0.f;
|
2015-05-02 04:34:27 +00:00
|
|
|
b3Vector3 vertPos;
|
2018-09-23 21:17:31 +00:00
|
|
|
vertPos[0] = shape.mesh.positions[v * 3 + 0] * myScaling[0];
|
|
|
|
vertPos[1] = shape.mesh.positions[v * 3 + 1] * myScaling[1];
|
|
|
|
vertPos[2] = shape.mesh.positions[v * 3 + 2] * myScaling[2];
|
|
|
|
vertPos[3] = 0.f;
|
|
|
|
center += vertPos;
|
2015-05-02 04:34:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
center /= numVertices;
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int v = 0; v < numVertices; v++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
GLInstanceVertex vert;
|
|
|
|
vert.uv[0] = 0.5f;
|
|
|
|
vert.uv[1] = 0.5f;
|
2018-09-23 21:17:31 +00:00
|
|
|
vert.normal[0] = 0.f;
|
|
|
|
vert.normal[1] = 1.f;
|
|
|
|
vert.normal[2] = 0.f;
|
2015-05-02 04:34:27 +00:00
|
|
|
b3Vector3 vertPos;
|
2018-09-23 21:17:31 +00:00
|
|
|
vertPos[0] = shape.mesh.positions[v * 3 + 0] * myScaling[0];
|
|
|
|
vertPos[1] = shape.mesh.positions[v * 3 + 1] * myScaling[1];
|
|
|
|
vertPos[2] = shape.mesh.positions[v * 3 + 2] * myScaling[2];
|
|
|
|
vertPos[3] = 0.f;
|
|
|
|
// vertPos-=center;
|
2015-05-02 04:34:27 +00:00
|
|
|
vert.xyzw[0] = vertPos[0];
|
|
|
|
vert.xyzw[1] = vertPos[1];
|
|
|
|
vert.xyzw[2] = vertPos[2];
|
|
|
|
|
|
|
|
tmpVertices.push_back(vert);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 newPos = tr * vertPos;
|
2015-05-02 04:34:27 +00:00
|
|
|
vert.xyzw[0] = newPos[0];
|
|
|
|
vert.xyzw[1] = newPos[1];
|
|
|
|
vert.xyzw[2] = newPos[2];
|
|
|
|
vert.xyzw[3] = 0.f;
|
|
|
|
vertexArray.push_back(vert);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int childColIndex = m_data->m_np->registerConvexHullShape(&tmpVertices[0].xyzw[0], strideInBytes, numVertices, scaling);
|
2015-05-02 04:34:27 +00:00
|
|
|
child.m_shapeIndex = childColIndex;
|
|
|
|
childShapes.push_back(child);
|
|
|
|
colIndex = childColIndex;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
colIndex = m_data->m_np->registerCompoundShape(&childShapes);
|
2015-05-02 04:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
2018-09-23 21:17:31 +00:00
|
|
|
int shapeId = ci.m_instancingRenderer->registerShape(&vertexArray[0].xyzw[0], vertexArray.size(), &indexArray[0], indexArray.size());
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3Vector4 colors[4] =
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
b3MakeVector4(1, 0, 0, 1),
|
|
|
|
b3MakeVector4(0, 1, 0, 1),
|
|
|
|
b3MakeVector4(0, 0, 1, 1),
|
|
|
|
b3MakeVector4(0, 1, 1, 1),
|
|
|
|
};
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
int curColor = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 1; i++) //ci.arraySizeX;i++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < 4; j++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// for (int k=0;k<ci.arraySizeZ;k++)
|
|
|
|
int k = 0;
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float mass = 1; //j==0? 0.f : 1.f;
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
//b3Vector3 position(i*10*ci.gapX,j*ci.gapY,k*10*ci.gapZ);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 position = b3MakeVector3(i * 10 * ci.gapX, 10 + j * 10 * ci.gapY, k * 10 * ci.gapZ);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// b3Quaternion orn(0,0,0,1);
|
|
|
|
b3Quaternion orn(b3MakeVector3(0, 0, 1), 1.8);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3Vector4 color = colors[curColor];
|
|
|
|
curColor++;
|
2018-09-23 21:17:31 +00:00
|
|
|
curColor &= 3;
|
|
|
|
b3Vector4 scaling = b3MakeVector4(1, 1, 1, 1);
|
|
|
|
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId, position, orn, color, scaling);
|
|
|
|
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass, position, orn, colIndex, index, false);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConcaveCompoundScene::createDynamicObjects(const ConstructionInfo& ci)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int strideInBytes = 9 * sizeof(float);
|
|
|
|
int numVertices = sizeof(cube_vertices) / strideInBytes;
|
|
|
|
int numIndices = sizeof(cube_indices) / sizeof(int);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3AlignedObjectArray<GLInstanceVertex> vertexArray;
|
|
|
|
b3AlignedObjectArray<int> indexArray;
|
|
|
|
|
|
|
|
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
2018-09-23 21:17:31 +00:00
|
|
|
int group = 1;
|
|
|
|
int mask = 1;
|
|
|
|
int index = 0;
|
|
|
|
float scaling[4] = {1, 1, 1, 1};
|
2015-05-02 04:34:27 +00:00
|
|
|
int colIndex = 0;
|
|
|
|
|
|
|
|
GLInstanceVertex* cubeVerts = (GLInstanceVertex*)&cube_vertices[0];
|
|
|
|
int stride2 = sizeof(GLInstanceVertex);
|
|
|
|
b3Assert(stride2 == strideInBytes);
|
|
|
|
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int childColIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0], strideInBytes, numVertices, scaling);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 childPositions[3] = {
|
|
|
|
b3MakeVector3(0, -2, 0),
|
|
|
|
b3MakeVector3(0, 0, 0),
|
|
|
|
b3MakeVector3(0, 0, 2)};
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3AlignedObjectArray<b3GpuChildShape> childShapes;
|
|
|
|
int numChildShapes = 3;
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numChildShapes; i++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
//for now, only support polyhedral child shapes
|
|
|
|
b3GpuChildShape child;
|
|
|
|
child.m_shapeIndex = childColIndex;
|
|
|
|
b3Vector3 pos = childPositions[i];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Quaternion orn(0, 0, 0, 1);
|
|
|
|
for (int v = 0; v < 4; v++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
child.m_childPosition[v] = pos[v];
|
|
|
|
child.m_childOrientation[v] = orn[v];
|
|
|
|
}
|
|
|
|
childShapes.push_back(child);
|
|
|
|
b3Transform tr;
|
|
|
|
tr.setIdentity();
|
|
|
|
tr.setOrigin(pos);
|
|
|
|
tr.setRotation(orn);
|
|
|
|
|
|
|
|
int baseIndex = vertexArray.size();
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < numIndices; j++)
|
|
|
|
indexArray.push_back(cube_indices[j] + baseIndex);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
//add transformed graphics vertices and indices
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int v = 0; v < numVertices; v++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
GLInstanceVertex vert = cubeVerts[v];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 vertPos = b3MakeVector3(vert.xyzw[0], vert.xyzw[1], vert.xyzw[2]);
|
|
|
|
b3Vector3 newPos = tr * vertPos;
|
2015-05-02 04:34:27 +00:00
|
|
|
vert.xyzw[0] = newPos[0];
|
|
|
|
vert.xyzw[1] = newPos[1];
|
|
|
|
vert.xyzw[2] = newPos[2];
|
|
|
|
vert.xyzw[3] = 0.f;
|
|
|
|
vertexArray.push_back(vert);
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
colIndex = m_data->m_np->registerCompoundShape(&childShapes);
|
2015-05-02 04:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
2018-09-23 21:17:31 +00:00
|
|
|
int shapeId = ci.m_instancingRenderer->registerShape(&vertexArray[0].xyzw[0], vertexArray.size(), &indexArray[0], indexArray.size());
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3Vector4 colors[4] =
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
b3MakeVector4(1, 0, 0, 1),
|
|
|
|
b3MakeVector4(0, 1, 0, 1),
|
|
|
|
b3MakeVector4(0, 0, 1, 1),
|
|
|
|
b3MakeVector4(0, 1, 1, 1),
|
|
|
|
};
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
int curColor = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < ci.arraySizeX; i++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < ci.arraySizeY; j++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int k = 0; k < ci.arraySizeZ; k++)
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float mass = 1; //j==0? 0.f : 1.f;
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 position = b3MakeVector3((-ci.arraySizeX / 2 + i) * ci.gapX, 50 + j * ci.gapY, (-ci.arraySizeZ / 2 + k) * ci.gapZ);
|
2015-05-02 04:34:27 +00:00
|
|
|
//b3Quaternion orn(0,0,0,1);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Quaternion orn(b3MakeVector3(1, 0, 0), 0.7);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3Vector4 color = colors[curColor];
|
|
|
|
curColor++;
|
2018-09-23 21:17:31 +00:00
|
|
|
curColor &= 3;
|
|
|
|
b3Vector4 scaling = b3MakeVector4(1, 1, 1, 1);
|
|
|
|
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId, position, orn, color, scaling);
|
|
|
|
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass, position, orn, colIndex, index, false);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConcaveSphereScene::setupScene(const ConstructionInfo& ci)
|
|
|
|
{
|
|
|
|
ConcaveScene::setupScene(ci);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
float camPos[4] = {0, 50, 0, 0}; //65.5,4.5,65.5,0};
|
2015-05-02 04:34:27 +00:00
|
|
|
//float camPos[4]={1,12.5,1.5,0};
|
|
|
|
m_instancingRenderer->setCameraPitch(45);
|
|
|
|
m_instancingRenderer->setCameraTargetPosition(camPos);
|
|
|
|
m_instancingRenderer->setCameraDistance(40);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConcaveSphereScene::createDynamicObjects(const ConstructionInfo& ci)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector4 colors[4] =
|
|
|
|
{
|
|
|
|
b3MakeVector4(1, 0, 0, 1),
|
|
|
|
b3MakeVector4(0, 1, 0, 1),
|
|
|
|
b3MakeVector4(0, 1, 1, 1),
|
|
|
|
b3MakeVector4(1, 1, 0, 1),
|
|
|
|
};
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int index = 0;
|
2015-05-02 04:34:27 +00:00
|
|
|
int curColor = 0;
|
|
|
|
float radius = 1;
|
|
|
|
//int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
2018-09-23 21:17:31 +00:00
|
|
|
int colIndex = m_data->m_np->registerSphereShape(radius); //>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
|
|
|
int prevGraphicsShapeIndex = registerGraphicsSphereShape(ci, radius, false);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < ci.arraySizeX; i++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < ci.arraySizeY; j++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int k = 0; k < ci.arraySizeZ; k++)
|
2015-05-02 04:34:27 +00:00
|
|
|
{
|
|
|
|
float mass = 1.f;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 position = b3MakeVector3(-(ci.arraySizeX / 2) * 8 + i * 8, 50 + j * 8, -(ci.arraySizeZ / 2) * 8 + k * 8);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
//b3Vector3 position(0,-41,0);//0,0,0);//i*radius*3,-41+j*radius*3,k*radius*3);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Quaternion orn(0, 0, 0, 1);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
b3Vector4 color = colors[curColor];
|
|
|
|
curColor++;
|
2018-09-23 21:17:31 +00:00
|
|
|
curColor &= 3;
|
|
|
|
b3Vector4 scaling = b3MakeVector4(radius, radius, radius, 1);
|
|
|
|
int id = ci.m_instancingRenderer->registerGraphicsInstance(prevGraphicsShapeIndex, position, orn, color, scaling);
|
|
|
|
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass, position, orn, colIndex, index, false);
|
2015-05-02 04:34:27 +00:00
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|