Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
@@ -23,13 +23,13 @@ subject to the following restrictions:
|
||||
struct ColladaGraphicsInstance
|
||||
{
|
||||
ColladaGraphicsInstance()
|
||||
:m_shapeIndex(-1)
|
||||
: m_shapeIndex(-1)
|
||||
{
|
||||
m_worldTransform.setIdentity();
|
||||
}
|
||||
btMatrix4x4 m_worldTransform;
|
||||
int m_shapeIndex;//could be index into array of GLInstanceGraphicsShape
|
||||
btMatrix4x4 m_worldTransform;
|
||||
int m_shapeIndex; //could be index into array of GLInstanceGraphicsShape
|
||||
float m_color[4];
|
||||
};
|
||||
|
||||
#endif //COLLADA_GRAPHICS_INSTANCE_H
|
||||
#endif //COLLADA_GRAPHICS_INSTANCE_H
|
||||
|
||||
@@ -15,7 +15,6 @@ subject to the following restrictions:
|
||||
//original author: Erwin Coumans
|
||||
*/
|
||||
|
||||
|
||||
#include "ImportColladaSetup.h"
|
||||
#include <vector>
|
||||
#include "../OpenGLWindow/GLInstancingRenderer.h"
|
||||
@@ -28,49 +27,42 @@ subject to the following restrictions:
|
||||
|
||||
#include "../CommonInterfaces/CommonRigidBodyBase.h"
|
||||
|
||||
|
||||
|
||||
class ImportColladaSetup : public CommonRigidBodyBase
|
||||
{
|
||||
|
||||
public:
|
||||
ImportColladaSetup(struct GUIHelperInterface* helper);
|
||||
virtual ~ImportColladaSetup();
|
||||
|
||||
ImportColladaSetup(struct GUIHelperInterface* helper);
|
||||
virtual ~ImportColladaSetup();
|
||||
|
||||
virtual void initPhysics();
|
||||
virtual void resetCamera()
|
||||
{
|
||||
float dist = 16;
|
||||
float pitch = -28;
|
||||
float yaw = -140;
|
||||
float targetPos[3]={-4,-3,-3};
|
||||
m_guiHelper->resetCamera(dist,yaw,pitch,targetPos[0],targetPos[1],targetPos[2]);
|
||||
float targetPos[3] = {-4, -3, -3};
|
||||
m_guiHelper->resetCamera(dist, yaw, pitch, targetPos[0], targetPos[1], targetPos[2]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
ImportColladaSetup::ImportColladaSetup(struct GUIHelperInterface* helper)
|
||||
:CommonRigidBodyBase(helper)
|
||||
: CommonRigidBodyBase(helper)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ImportColladaSetup::~ImportColladaSetup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static int ColladaGraphicsInstanceSortfnc(const ColladaGraphicsInstance& a,const ColladaGraphicsInstance& b)
|
||||
static int ColladaGraphicsInstanceSortfnc(const ColladaGraphicsInstance& a, const ColladaGraphicsInstance& b)
|
||||
{
|
||||
if (a.m_shapeIndex<b.m_shapeIndex) return +1;
|
||||
if (a.m_shapeIndex>b.m_shapeIndex) return -1;
|
||||
if (a.m_shapeIndex < b.m_shapeIndex) return +1;
|
||||
if (a.m_shapeIndex > b.m_shapeIndex) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void ImportColladaSetup::initPhysics()
|
||||
{
|
||||
int upAxis=1;
|
||||
int upAxis = 1;
|
||||
m_guiHelper->setUpAxis(upAxis);
|
||||
this->createEmptyDynamicsWorld();
|
||||
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
||||
@@ -81,28 +73,20 @@ void ImportColladaSetup::initPhysics()
|
||||
const char* fileNames[] = {
|
||||
"duck.dae",
|
||||
"seymourplane_triangulate.dae",
|
||||
};
|
||||
};
|
||||
const char* fileName = fileNames[fileIndex];
|
||||
int numFiles = sizeof(fileNames)/sizeof(const char*);
|
||||
|
||||
char relativeFileName[1024];
|
||||
int numFiles = sizeof(fileNames) / sizeof(const char*);
|
||||
|
||||
if (!b3ResourcePath::findResourcePath(fileName,relativeFileName,1024))
|
||||
return;
|
||||
char relativeFileName[1024];
|
||||
|
||||
if (!b3ResourcePath::findResourcePath(fileName, relativeFileName, 1024))
|
||||
return;
|
||||
|
||||
btVector3 shift(0,0,0);
|
||||
btVector3 scaling(1,1,1);
|
||||
// int index=10;
|
||||
|
||||
|
||||
|
||||
|
||||
btVector3 shift(0, 0, 0);
|
||||
btVector3 scaling(1, 1, 1);
|
||||
// int index=10;
|
||||
|
||||
|
||||
|
||||
{
|
||||
|
||||
btAlignedObjectArray<GLInstanceGraphicsShape> visualShapes;
|
||||
btAlignedObjectArray<ColladaGraphicsInstance> visualShapeInstances;
|
||||
|
||||
@@ -110,69 +94,64 @@ void ImportColladaSetup::initPhysics()
|
||||
btTransform upAxisTrans;
|
||||
upAxisTrans.setIdentity();
|
||||
|
||||
btVector3 color(0,0,1);
|
||||
btVector3 color(0, 0, 1);
|
||||
|
||||
#ifdef COMPARE_WITH_ASSIMP
|
||||
static int useAssimp = 0;
|
||||
if (useAssimp)
|
||||
{
|
||||
|
||||
LoadMeshFromColladaAssimp(relativeFileName, visualShapes, visualShapeInstances,upAxisTrans,unitMeterScaling);
|
||||
LoadMeshFromColladaAssimp(relativeFileName, visualShapes, visualShapeInstances, upAxisTrans, unitMeterScaling);
|
||||
fileIndex++;
|
||||
if (fileIndex>=numFiles)
|
||||
if (fileIndex >= numFiles)
|
||||
{
|
||||
fileIndex = 0;
|
||||
}
|
||||
color.setValue(1,0,0);
|
||||
color.setValue(1, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadMeshFromCollada(relativeFileName, visualShapes, visualShapeInstances,upAxisTrans,unitMeterScaling);
|
||||
|
||||
LoadMeshFromCollada(relativeFileName, visualShapes, visualShapeInstances, upAxisTrans, unitMeterScaling);
|
||||
}
|
||||
useAssimp=1-useAssimp;
|
||||
useAssimp = 1 - useAssimp;
|
||||
#else
|
||||
fileIndex++;
|
||||
if (fileIndex>=numFiles)
|
||||
if (fileIndex >= numFiles)
|
||||
{
|
||||
fileIndex = 0;
|
||||
}
|
||||
LoadMeshFromCollada(relativeFileName, visualShapes, visualShapeInstances,upAxisTrans,unitMeterScaling, upAxis);
|
||||
#endif// COMPARE_WITH_ASSIMP
|
||||
|
||||
|
||||
LoadMeshFromCollada(relativeFileName, visualShapes, visualShapeInstances, upAxisTrans, unitMeterScaling, upAxis);
|
||||
#endif // COMPARE_WITH_ASSIMP
|
||||
|
||||
//at the moment our graphics engine requires instances that share the same visual shape to be added right after registering the shape
|
||||
//so perform a sort, just to be sure
|
||||
visualShapeInstances.quickSort(ColladaGraphicsInstanceSortfnc);
|
||||
|
||||
for (int i=0;i<visualShapeInstances.size();i++)
|
||||
for (int i = 0; i < visualShapeInstances.size(); i++)
|
||||
{
|
||||
ColladaGraphicsInstance* instance = &visualShapeInstances[i];
|
||||
GLInstanceGraphicsShape* gfxShape = &visualShapes[instance->m_shapeIndex];
|
||||
btVector3 position(0,0,0);// = scaling*btVector3(instance->m_pos[0],instance->m_pos[1],instance->m_pos[2]);
|
||||
btQuaternion orn(0,0,0,1);//instance->m_orn[0],instance->m_orn[1],instance->m_orn[2],instance->m_orn[3]);
|
||||
btVector3 position(0, 0, 0); // = scaling*btVector3(instance->m_pos[0],instance->m_pos[1],instance->m_pos[2]);
|
||||
btQuaternion orn(0, 0, 0, 1); //instance->m_orn[0],instance->m_orn[1],instance->m_orn[2],instance->m_orn[3]);
|
||||
|
||||
//sort the visualShapeInstances, then iterate etc
|
||||
//void LoadMeshFromCollada(const char* relativeFileName,
|
||||
//btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes,
|
||||
//btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes,
|
||||
//btAlignedObjectArray<GLInstanceGraphicsInstance> visualShapeInstances);
|
||||
|
||||
|
||||
if (gfxShape)
|
||||
{
|
||||
//btTransform trans;
|
||||
//trans.setIdentity();
|
||||
//trans.setRotation(btQuaternion(btVector3(1,0,0),SIMD_HALF_PI));
|
||||
|
||||
|
||||
|
||||
|
||||
b3AlignedObjectArray<GLInstanceVertex> verts;
|
||||
verts.resize(gfxShape->m_vertices->size());
|
||||
|
||||
for (int i=0;i<gfxShape->m_vertices->size();i++)
|
||||
|
||||
for (int i = 0; i < gfxShape->m_vertices->size(); i++)
|
||||
{
|
||||
verts[i].normal[0] = gfxShape->m_vertices->at(i).normal[0];
|
||||
verts[i].normal[1] = gfxShape->m_vertices->at(i).normal[1];
|
||||
verts[i].normal[2] = gfxShape->m_vertices->at(i).normal[2];
|
||||
verts[i].normal[0] = gfxShape->m_vertices->at(i).normal[0];
|
||||
verts[i].normal[1] = gfxShape->m_vertices->at(i).normal[1];
|
||||
verts[i].normal[2] = gfxShape->m_vertices->at(i).normal[2];
|
||||
verts[i].uv[0] = gfxShape->m_vertices->at(i).uv[0];
|
||||
verts[i].uv[1] = gfxShape->m_vertices->at(i).uv[1];
|
||||
verts[i].xyzw[0] = gfxShape->m_vertices->at(i).xyzw[0];
|
||||
@@ -180,34 +159,33 @@ void ImportColladaSetup::initPhysics()
|
||||
verts[i].xyzw[2] = gfxShape->m_vertices->at(i).xyzw[2];
|
||||
verts[i].xyzw[3] = gfxShape->m_vertices->at(i).xyzw[3];
|
||||
}
|
||||
|
||||
|
||||
//compensate upAxisTrans and unitMeterScaling here
|
||||
btMatrix4x4 upAxisMat;
|
||||
upAxisMat.setPureRotation(upAxisTrans.getRotation());
|
||||
btMatrix4x4 unitMeterScalingMat;
|
||||
unitMeterScalingMat.setPureScaling(btVector3(unitMeterScaling,unitMeterScaling,unitMeterScaling));
|
||||
btMatrix4x4 worldMat = unitMeterScalingMat*upAxisMat*instance->m_worldTransform;
|
||||
unitMeterScalingMat.setPureScaling(btVector3(unitMeterScaling, unitMeterScaling, unitMeterScaling));
|
||||
btMatrix4x4 worldMat = unitMeterScalingMat * upAxisMat * instance->m_worldTransform;
|
||||
//btMatrix4x4 worldMat = instance->m_worldTransform;
|
||||
for(int v=0;v<verts.size();v++)
|
||||
for (int v = 0; v < verts.size(); v++)
|
||||
{
|
||||
btVector3 pos(verts[v].xyzw[0],verts[v].xyzw[1],verts[v].xyzw[2]);
|
||||
pos = worldMat*pos;
|
||||
btVector3 pos(verts[v].xyzw[0], verts[v].xyzw[1], verts[v].xyzw[2]);
|
||||
pos = worldMat * pos;
|
||||
verts[v].xyzw[0] = float(pos[0]);
|
||||
verts[v].xyzw[1] = float(pos[1]);
|
||||
verts[v].xyzw[2] = float(pos[2]);
|
||||
}
|
||||
|
||||
|
||||
int shapeId = m_guiHelper->getRenderInterface()->registerShape(&verts[0].xyzw[0], gfxShape->m_numvertices, &gfxShape->m_indices->at(0), gfxShape->m_numIndices);
|
||||
|
||||
|
||||
//btVector3 instanceScaling(instance->m_scaling[0],instance->m_scaling[1],instance->m_scaling[2]);
|
||||
m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId, position, orn, color, scaling);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CommonExampleInterface* ImportColladaCreateFunc(struct CommonExampleOptions& options)
|
||||
class CommonExampleInterface* ImportColladaCreateFunc(struct CommonExampleOptions& options)
|
||||
{
|
||||
return new ImportColladaSetup(options.m_guiHelper);
|
||||
}
|
||||
|
||||
@@ -15,11 +15,9 @@ subject to the following restrictions:
|
||||
//original author: Erwin Coumans
|
||||
*/
|
||||
|
||||
|
||||
#ifndef IMPORT_COLLADA_SETUP_H
|
||||
#define IMPORT_COLLADA_SETUP_H
|
||||
|
||||
class CommonExampleInterface* ImportColladaCreateFunc(struct CommonExampleOptions& options);
|
||||
class CommonExampleInterface* ImportColladaCreateFunc(struct CommonExampleOptions& options);
|
||||
|
||||
|
||||
#endif //IMPORT_COLLADA_SETUP_H
|
||||
#endif //IMPORT_COLLADA_SETUP_H
|
||||
|
||||
@@ -15,9 +15,8 @@ subject to the following restrictions:
|
||||
//original author: Erwin Coumans
|
||||
*/
|
||||
|
||||
|
||||
#include "LoadMeshFromCollada.h"
|
||||
#include <stdio.h> //fopen
|
||||
#include <stdio.h> //fopen
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include <string>
|
||||
#include "../../ThirdPartyLibs/tinyxml2/tinyxml2.h"
|
||||
@@ -28,10 +27,8 @@ using namespace tinyxml2;
|
||||
#include <assert.h>
|
||||
#include "btMatrix4x4.h"
|
||||
|
||||
|
||||
#define MAX_VISUAL_SHAPES 512
|
||||
|
||||
|
||||
struct VertexSource
|
||||
{
|
||||
std::string m_positionArrayId;
|
||||
@@ -42,7 +39,8 @@ struct TokenFloatArray
|
||||
{
|
||||
btAlignedObjectArray<float>& m_values;
|
||||
TokenFloatArray(btAlignedObjectArray<float>& floatArray)
|
||||
:m_values(floatArray) {
|
||||
: m_values(floatArray)
|
||||
{
|
||||
}
|
||||
inline void add(const char* token)
|
||||
{
|
||||
@@ -54,7 +52,8 @@ struct TokenIntArray
|
||||
{
|
||||
btAlignedObjectArray<int>& m_values;
|
||||
TokenIntArray(btAlignedObjectArray<int>& intArray)
|
||||
:m_values(intArray) {
|
||||
: m_values(intArray)
|
||||
{
|
||||
}
|
||||
inline void add(const char* token)
|
||||
{
|
||||
@@ -66,127 +65,125 @@ struct TokenIntArray
|
||||
template <typename AddToken>
|
||||
void tokenize(const std::string& str, AddToken& tokenAdder, const std::string& delimiters = " ")
|
||||
{
|
||||
std::string::size_type pos, lastPos = 0;
|
||||
while(true)
|
||||
{
|
||||
pos = str.find_first_of(delimiters, lastPos);
|
||||
if(pos == std::string::npos)
|
||||
{
|
||||
pos = str.length();
|
||||
if(pos != lastPos)
|
||||
{
|
||||
tokenAdder.add(str.data()+lastPos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pos != lastPos)
|
||||
{
|
||||
tokenAdder.add(str.data()+lastPos);
|
||||
}
|
||||
}
|
||||
lastPos = pos + 1;
|
||||
}
|
||||
std::string::size_type pos, lastPos = 0;
|
||||
while (true)
|
||||
{
|
||||
pos = str.find_first_of(delimiters, lastPos);
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
pos = str.length();
|
||||
if (pos != lastPos)
|
||||
{
|
||||
tokenAdder.add(str.data() + lastPos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pos != lastPos)
|
||||
{
|
||||
tokenAdder.add(str.data() + lastPos);
|
||||
}
|
||||
}
|
||||
lastPos = pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void readFloatArray(XMLElement* source, btAlignedObjectArray<float>& floatArray, int& componentStride)
|
||||
void readFloatArray(XMLElement* source, btAlignedObjectArray<float>& floatArray, int& componentStride)
|
||||
{
|
||||
int numVals, stride;
|
||||
XMLElement* array = source->FirstChildElement("float_array");
|
||||
if(array)
|
||||
if (array)
|
||||
{
|
||||
componentStride = 1;
|
||||
if (source->FirstChildElement("technique_common")->FirstChildElement("accessor")->QueryIntAttribute("stride", &stride)!= XML_NO_ATTRIBUTE)
|
||||
if (source->FirstChildElement("technique_common")->FirstChildElement("accessor")->QueryIntAttribute("stride", &stride) != XML_NO_ATTRIBUTE)
|
||||
{
|
||||
componentStride = stride;
|
||||
}
|
||||
array->QueryIntAttribute("count", &numVals);
|
||||
TokenFloatArray adder(floatArray);
|
||||
floatArray.reserve(numVals);
|
||||
tokenize(array->GetText(),adder);
|
||||
tokenize(array->GetText(), adder);
|
||||
assert(floatArray.size() == numVals);
|
||||
}
|
||||
}
|
||||
|
||||
btVector3 getVector3FromXmlText(const char* text)
|
||||
{
|
||||
btVector3 vec(0,0,0);
|
||||
btVector3 vec(0, 0, 0);
|
||||
btAlignedObjectArray<float> floatArray;
|
||||
TokenFloatArray adder(floatArray);
|
||||
floatArray.reserve(3);
|
||||
tokenize(text,adder);
|
||||
tokenize(text, adder);
|
||||
assert(floatArray.size() == 3);
|
||||
if (floatArray.size()==3)
|
||||
if (floatArray.size() == 3)
|
||||
{
|
||||
vec.setValue(floatArray[0],floatArray[1],floatArray[2]);
|
||||
vec.setValue(floatArray[0], floatArray[1], floatArray[2]);
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
btVector4 getVector4FromXmlText(const char* text)
|
||||
{
|
||||
btVector4 vec(0,0,0,0);
|
||||
btVector4 vec(0, 0, 0, 0);
|
||||
btAlignedObjectArray<float> floatArray;
|
||||
TokenFloatArray adder(floatArray);
|
||||
floatArray.reserve(4);
|
||||
tokenize(text,adder);
|
||||
tokenize(text, adder);
|
||||
assert(floatArray.size() == 4);
|
||||
if (floatArray.size()==4)
|
||||
if (floatArray.size() == 4)
|
||||
{
|
||||
vec.setValue(floatArray[0],floatArray[1],floatArray[2],floatArray[3]);
|
||||
vec.setValue(floatArray[0], floatArray[1], floatArray[2], floatArray[3]);
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
|
||||
void readLibraryGeometries(XMLDocument& doc, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btHashMap<btHashString,int>& name2Shape, float extraScaling)
|
||||
void readLibraryGeometries(XMLDocument& doc, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btHashMap<btHashString, int>& name2Shape, float extraScaling)
|
||||
{
|
||||
btHashMap<btHashString,XMLElement* > allSources;
|
||||
btHashMap<btHashString,VertexSource> vertexSources;
|
||||
for(XMLElement* geometry = doc.RootElement()->FirstChildElement("library_geometries")->FirstChildElement("geometry");
|
||||
geometry != NULL; geometry = geometry->NextSiblingElement("geometry"))
|
||||
btHashMap<btHashString, XMLElement*> allSources;
|
||||
btHashMap<btHashString, VertexSource> vertexSources;
|
||||
for (XMLElement* geometry = doc.RootElement()->FirstChildElement("library_geometries")->FirstChildElement("geometry");
|
||||
geometry != NULL; geometry = geometry->NextSiblingElement("geometry"))
|
||||
{
|
||||
btAlignedObjectArray<btVector3> vertexPositions;
|
||||
btAlignedObjectArray<btVector3> vertexNormals;
|
||||
btAlignedObjectArray<int> indices;
|
||||
|
||||
const char* geometryName = geometry->Attribute("id");
|
||||
for (XMLElement* mesh = geometry->FirstChildElement("mesh");(mesh != NULL); mesh = mesh->NextSiblingElement("mesh"))
|
||||
for (XMLElement* mesh = geometry->FirstChildElement("mesh"); (mesh != NULL); mesh = mesh->NextSiblingElement("mesh"))
|
||||
{
|
||||
XMLElement* vertices2 = mesh->FirstChildElement("vertices");
|
||||
|
||||
for (XMLElement* source = mesh->FirstChildElement("source");source != NULL;source = source->NextSiblingElement("source"))
|
||||
|
||||
for (XMLElement* source = mesh->FirstChildElement("source"); source != NULL; source = source->NextSiblingElement("source"))
|
||||
{
|
||||
const char* srcId= source->Attribute("id");
|
||||
// printf("source id=%s\n",srcId);
|
||||
allSources.insert(srcId,source);
|
||||
const char* srcId = source->Attribute("id");
|
||||
// printf("source id=%s\n",srcId);
|
||||
allSources.insert(srcId, source);
|
||||
}
|
||||
const char* vertexId = vertices2->Attribute("id");
|
||||
//printf("vertices id=%s\n",vertexId);
|
||||
VertexSource vs;
|
||||
for(XMLElement* input = vertices2->FirstChildElement("input");input != NULL;input = input->NextSiblingElement("input"))
|
||||
for (XMLElement* input = vertices2->FirstChildElement("input"); input != NULL; input = input->NextSiblingElement("input"))
|
||||
{
|
||||
const char* sem = input->Attribute("semantic");
|
||||
std::string semName(sem);
|
||||
// printf("sem=%s\n",sem);
|
||||
// const char* src = input->Attribute("source");
|
||||
// printf("src=%s\n",src);
|
||||
// printf("sem=%s\n",sem);
|
||||
// const char* src = input->Attribute("source");
|
||||
// printf("src=%s\n",src);
|
||||
const char* srcIdRef = input->Attribute("source");
|
||||
std::string source_name;
|
||||
source_name = std::string(srcIdRef);
|
||||
source_name = source_name.erase(0, 1);
|
||||
if (semName=="POSITION")
|
||||
if (semName == "POSITION")
|
||||
{
|
||||
vs.m_positionArrayId = source_name;
|
||||
}
|
||||
if (semName=="NORMAL")
|
||||
if (semName == "NORMAL")
|
||||
{
|
||||
vs.m_normalArrayId = source_name;
|
||||
}
|
||||
}
|
||||
vertexSources.insert(vertexId,vs);
|
||||
vertexSources.insert(vertexId, vs);
|
||||
|
||||
btAlignedObjectArray<XMLElement*> trianglesAndPolylists;
|
||||
|
||||
@@ -199,36 +196,35 @@ void readLibraryGeometries(XMLDocument& doc, btAlignedObjectArray<GLInstanceGrap
|
||||
trianglesAndPolylists.push_back(primitive);
|
||||
}
|
||||
|
||||
for (int i=0;i<trianglesAndPolylists.size();i++)
|
||||
for (int i = 0; i < trianglesAndPolylists.size(); i++)
|
||||
{
|
||||
XMLElement* primitive = trianglesAndPolylists[i];
|
||||
std::string positionSourceName;
|
||||
std::string normalSourceName;
|
||||
int primitiveCount;
|
||||
primitive->QueryIntAttribute("count", &primitiveCount);
|
||||
int indexStride=1;
|
||||
int indexStride = 1;
|
||||
int posOffset = 0;
|
||||
int normalOffset = 0;
|
||||
int numIndices = 0;
|
||||
{
|
||||
|
||||
for (XMLElement* input = primitive->FirstChildElement("input");input != NULL;input = input->NextSiblingElement("input"))
|
||||
for (XMLElement* input = primitive->FirstChildElement("input"); input != NULL; input = input->NextSiblingElement("input"))
|
||||
{
|
||||
const char* sem = input->Attribute("semantic");
|
||||
std::string semName(sem);
|
||||
int offset = atoi(input->Attribute("offset"));
|
||||
if ((offset+1)>indexStride)
|
||||
indexStride=offset+1;
|
||||
if ((offset + 1) > indexStride)
|
||||
indexStride = offset + 1;
|
||||
//printf("sem=%s\n",sem);
|
||||
// const char* src = input->Attribute("source");
|
||||
// const char* src = input->Attribute("source");
|
||||
|
||||
//printf("src=%s\n",src);
|
||||
const char* srcIdRef = input->Attribute("source");
|
||||
std::string source_name;
|
||||
source_name = std::string(srcIdRef);
|
||||
source_name = source_name.erase(0, 1);
|
||||
|
||||
if (semName=="VERTEX")
|
||||
|
||||
if (semName == "VERTEX")
|
||||
{
|
||||
//now we have POSITION and possibly NORMAL too, using same index array (<p>)
|
||||
VertexSource* vs = vertexSources[source_name.c_str()];
|
||||
@@ -240,138 +236,138 @@ void readLibraryGeometries(XMLDocument& doc, btAlignedObjectArray<GLInstanceGrap
|
||||
if (vs->m_normalArrayId.length())
|
||||
{
|
||||
normalSourceName = vs->m_normalArrayId;
|
||||
normalOffset = offset;
|
||||
normalOffset = offset;
|
||||
}
|
||||
}
|
||||
if (semName=="NORMAL")
|
||||
if (semName == "NORMAL")
|
||||
{
|
||||
btAssert(normalSourceName.length()==0);
|
||||
btAssert(normalSourceName.length() == 0);
|
||||
normalSourceName = source_name;
|
||||
normalOffset = offset;
|
||||
normalOffset = offset;
|
||||
}
|
||||
}
|
||||
numIndices = primitiveCount * 3;
|
||||
numIndices = primitiveCount * 3;
|
||||
}
|
||||
btAlignedObjectArray<float> positionFloatArray;
|
||||
int posStride=1;
|
||||
int posStride = 1;
|
||||
XMLElement** sourcePtr = allSources[positionSourceName.c_str()];
|
||||
if (sourcePtr)
|
||||
{
|
||||
readFloatArray(*sourcePtr,positionFloatArray, posStride);
|
||||
readFloatArray(*sourcePtr, positionFloatArray, posStride);
|
||||
}
|
||||
btAlignedObjectArray<float> normalFloatArray;
|
||||
int normalStride=1;
|
||||
int normalStride = 1;
|
||||
sourcePtr = allSources[normalSourceName.c_str()];
|
||||
if (sourcePtr)
|
||||
{
|
||||
readFloatArray(*sourcePtr,normalFloatArray,normalStride);
|
||||
readFloatArray(*sourcePtr, normalFloatArray, normalStride);
|
||||
}
|
||||
btAlignedObjectArray<int> curIndices;
|
||||
curIndices.reserve(numIndices*indexStride);
|
||||
curIndices.reserve(numIndices * indexStride);
|
||||
TokenIntArray adder(curIndices);
|
||||
tokenize(primitive->FirstChildElement("p")->GetText(),adder);
|
||||
assert(curIndices.size() == numIndices*indexStride);
|
||||
tokenize(primitive->FirstChildElement("p")->GetText(), adder);
|
||||
assert(curIndices.size() == numIndices * indexStride);
|
||||
int indexOffset = vertexPositions.size();
|
||||
|
||||
for(int index=0; index<numIndices; index++)
|
||||
for (int index = 0; index < numIndices; index++)
|
||||
{
|
||||
int posIndex = curIndices[index*indexStride+posOffset];
|
||||
int normalIndex = curIndices[index*indexStride+normalOffset];
|
||||
vertexPositions.push_back(btVector3(extraScaling*positionFloatArray[posIndex*3+0],
|
||||
extraScaling*positionFloatArray[posIndex*3+1],
|
||||
extraScaling*positionFloatArray[posIndex*3+2]));
|
||||
|
||||
if (normalFloatArray.size() && (normalFloatArray.size()>normalIndex))
|
||||
int posIndex = curIndices[index * indexStride + posOffset];
|
||||
int normalIndex = curIndices[index * indexStride + normalOffset];
|
||||
vertexPositions.push_back(btVector3(extraScaling * positionFloatArray[posIndex * 3 + 0],
|
||||
extraScaling * positionFloatArray[posIndex * 3 + 1],
|
||||
extraScaling * positionFloatArray[posIndex * 3 + 2]));
|
||||
|
||||
if (normalFloatArray.size() && (normalFloatArray.size() > normalIndex))
|
||||
{
|
||||
vertexNormals.push_back(btVector3(normalFloatArray[normalIndex*3+0],
|
||||
normalFloatArray[normalIndex*3+1],
|
||||
normalFloatArray[normalIndex*3+2]));
|
||||
} else
|
||||
vertexNormals.push_back(btVector3(normalFloatArray[normalIndex * 3 + 0],
|
||||
normalFloatArray[normalIndex * 3 + 1],
|
||||
normalFloatArray[normalIndex * 3 + 2]));
|
||||
}
|
||||
else
|
||||
{
|
||||
//add a dummy normal of length zero, so it is easy to detect that it is an invalid normal
|
||||
vertexNormals.push_back(btVector3(0,0,0));
|
||||
vertexNormals.push_back(btVector3(0, 0, 0));
|
||||
}
|
||||
}
|
||||
int curNumIndices = indices.size();
|
||||
indices.resize(curNumIndices+numIndices);
|
||||
for(int index=0; index<numIndices; index++)
|
||||
indices.resize(curNumIndices + numIndices);
|
||||
for (int index = 0; index < numIndices; index++)
|
||||
{
|
||||
indices[curNumIndices+index] = index+indexOffset;
|
||||
indices[curNumIndices + index] = index + indexOffset;
|
||||
}
|
||||
}//if(primitive != NULL)
|
||||
}//for each mesh
|
||||
|
||||
} //if(primitive != NULL)
|
||||
} //for each mesh
|
||||
|
||||
int shapeIndex = visualShapes.size();
|
||||
if (shapeIndex<MAX_VISUAL_SHAPES)
|
||||
{
|
||||
GLInstanceGraphicsShape& visualShape = visualShapes.expand();
|
||||
{
|
||||
visualShape.m_vertices = new b3AlignedObjectArray<GLInstanceVertex>;
|
||||
visualShape.m_indices = new b3AlignedObjectArray<int>;
|
||||
int indexBase = 0;
|
||||
if (shapeIndex < MAX_VISUAL_SHAPES)
|
||||
{
|
||||
GLInstanceGraphicsShape& visualShape = visualShapes.expand();
|
||||
{
|
||||
visualShape.m_vertices = new b3AlignedObjectArray<GLInstanceVertex>;
|
||||
visualShape.m_indices = new b3AlignedObjectArray<int>;
|
||||
int indexBase = 0;
|
||||
|
||||
btAssert(vertexNormals.size()==vertexPositions.size());
|
||||
for (int v=0;v<vertexPositions.size();v++)
|
||||
{
|
||||
GLInstanceVertex vtx;
|
||||
vtx.xyzw[0] = vertexPositions[v].x();
|
||||
vtx.xyzw[1] = vertexPositions[v].y();
|
||||
vtx.xyzw[2] = vertexPositions[v].z();
|
||||
vtx.xyzw[3] = 1.f;
|
||||
vtx.normal[0] = vertexNormals[v].x();
|
||||
vtx.normal[1] = vertexNormals[v].y();
|
||||
vtx.normal[2] = vertexNormals[v].z();
|
||||
vtx.uv[0] = 0.5f;
|
||||
vtx.uv[1] = 0.5f;
|
||||
visualShape.m_vertices->push_back(vtx);
|
||||
}
|
||||
btAssert(vertexNormals.size() == vertexPositions.size());
|
||||
for (int v = 0; v < vertexPositions.size(); v++)
|
||||
{
|
||||
GLInstanceVertex vtx;
|
||||
vtx.xyzw[0] = vertexPositions[v].x();
|
||||
vtx.xyzw[1] = vertexPositions[v].y();
|
||||
vtx.xyzw[2] = vertexPositions[v].z();
|
||||
vtx.xyzw[3] = 1.f;
|
||||
vtx.normal[0] = vertexNormals[v].x();
|
||||
vtx.normal[1] = vertexNormals[v].y();
|
||||
vtx.normal[2] = vertexNormals[v].z();
|
||||
vtx.uv[0] = 0.5f;
|
||||
vtx.uv[1] = 0.5f;
|
||||
visualShape.m_vertices->push_back(vtx);
|
||||
}
|
||||
|
||||
for (int index=0;index<indices.size();index++)
|
||||
{
|
||||
visualShape.m_indices->push_back(indices[index]+indexBase);
|
||||
}
|
||||
|
||||
|
||||
//b3Printf(" index_count =%dand vertexPositions.size=%d\n",indices.size(), vertexPositions.size());
|
||||
indexBase=visualShape.m_vertices->size();
|
||||
visualShape.m_numIndices = visualShape.m_indices->size();
|
||||
visualShape.m_numvertices = visualShape.m_vertices->size();
|
||||
}
|
||||
//b3Printf("geometry name=%s\n",geometryName);
|
||||
name2Shape.insert(geometryName,shapeIndex);
|
||||
} else
|
||||
{
|
||||
b3Warning("DAE exceeds number of visual shapes (%d/%d)",shapeIndex, MAX_VISUAL_SHAPES);
|
||||
}
|
||||
for (int index = 0; index < indices.size(); index++)
|
||||
{
|
||||
visualShape.m_indices->push_back(indices[index] + indexBase);
|
||||
}
|
||||
|
||||
}//for each geometry
|
||||
//b3Printf(" index_count =%dand vertexPositions.size=%d\n",indices.size(), vertexPositions.size());
|
||||
indexBase = visualShape.m_vertices->size();
|
||||
visualShape.m_numIndices = visualShape.m_indices->size();
|
||||
visualShape.m_numvertices = visualShape.m_vertices->size();
|
||||
}
|
||||
//b3Printf("geometry name=%s\n",geometryName);
|
||||
name2Shape.insert(geometryName, shapeIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Warning("DAE exceeds number of visual shapes (%d/%d)", shapeIndex, MAX_VISUAL_SHAPES);
|
||||
}
|
||||
|
||||
} //for each geometry
|
||||
}
|
||||
|
||||
void readNodeHierarchy(XMLElement* node,btHashMap<btHashString,int>& name2Shape, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances, const btMatrix4x4& parentTransMat)
|
||||
void readNodeHierarchy(XMLElement* node, btHashMap<btHashString, int>& name2Shape, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances, const btMatrix4x4& parentTransMat)
|
||||
{
|
||||
|
||||
|
||||
btMatrix4x4 nodeTrans;
|
||||
nodeTrans.setIdentity();
|
||||
|
||||
///todo(erwincoumans) we probably have to read the elements 'translate', 'scale', 'rotate' and 'matrix' in-order and accumulate them...
|
||||
{
|
||||
for (XMLElement* transElem = node->FirstChildElement("matrix");transElem;transElem=node->NextSiblingElement("matrix"))
|
||||
for (XMLElement* transElem = node->FirstChildElement("matrix"); transElem; transElem = node->NextSiblingElement("matrix"))
|
||||
{
|
||||
if (transElem->GetText())
|
||||
{
|
||||
btAlignedObjectArray<float> floatArray;
|
||||
TokenFloatArray adder(floatArray);
|
||||
tokenize(transElem->GetText(),adder);
|
||||
if (floatArray.size()==16)
|
||||
tokenize(transElem->GetText(), adder);
|
||||
if (floatArray.size() == 16)
|
||||
{
|
||||
btMatrix4x4 t(floatArray[0],floatArray[1],floatArray[2],floatArray[3],
|
||||
floatArray[4],floatArray[5],floatArray[6],floatArray[7],
|
||||
floatArray[8],floatArray[9],floatArray[10],floatArray[11],
|
||||
floatArray[12],floatArray[13],floatArray[14],floatArray[15]);
|
||||
btMatrix4x4 t(floatArray[0], floatArray[1], floatArray[2], floatArray[3],
|
||||
floatArray[4], floatArray[5], floatArray[6], floatArray[7],
|
||||
floatArray[8], floatArray[9], floatArray[10], floatArray[11],
|
||||
floatArray[12], floatArray[13], floatArray[14], floatArray[15]);
|
||||
|
||||
nodeTrans = nodeTrans*t;
|
||||
} else
|
||||
nodeTrans = nodeTrans * t;
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Warning("Error: expected 16 elements in a <matrix> element, skipping\n");
|
||||
}
|
||||
@@ -380,7 +376,7 @@ void readNodeHierarchy(XMLElement* node,btHashMap<btHashString,int>& name2Shape,
|
||||
}
|
||||
|
||||
{
|
||||
for (XMLElement* transElem = node->FirstChildElement("translate");transElem;transElem=node->NextSiblingElement("translate"))
|
||||
for (XMLElement* transElem = node->FirstChildElement("translate"); transElem; transElem = node->NextSiblingElement("translate"))
|
||||
{
|
||||
if (transElem->GetText())
|
||||
{
|
||||
@@ -388,45 +384,44 @@ void readNodeHierarchy(XMLElement* node,btHashMap<btHashString,int>& name2Shape,
|
||||
//nodePos+= unitScaling*parentScaling*pos;
|
||||
btMatrix4x4 t;
|
||||
t.setPureTranslation(pos);
|
||||
nodeTrans = nodeTrans*t;
|
||||
|
||||
nodeTrans = nodeTrans * t;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
for(XMLElement* scaleElem = node->FirstChildElement("scale");
|
||||
scaleElem!= NULL; scaleElem= node->NextSiblingElement("scale"))
|
||||
for (XMLElement* scaleElem = node->FirstChildElement("scale");
|
||||
scaleElem != NULL; scaleElem = node->NextSiblingElement("scale"))
|
||||
{
|
||||
if (scaleElem->GetText())
|
||||
{
|
||||
btVector3 scaling = getVector3FromXmlText(scaleElem->GetText());
|
||||
btMatrix4x4 t;
|
||||
t.setPureScaling(scaling);
|
||||
nodeTrans = nodeTrans*t;
|
||||
nodeTrans = nodeTrans * t;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
for(XMLElement* rotateElem = node->FirstChildElement("rotate");
|
||||
rotateElem!= NULL; rotateElem= node->NextSiblingElement("rotate"))
|
||||
for (XMLElement* rotateElem = node->FirstChildElement("rotate");
|
||||
rotateElem != NULL; rotateElem = node->NextSiblingElement("rotate"))
|
||||
{
|
||||
if (rotateElem->GetText())
|
||||
{
|
||||
//accumulate orientation
|
||||
btVector4 rotate = getVector4FromXmlText(rotateElem->GetText());
|
||||
btQuaternion orn(btVector3(rotate),btRadians(rotate[3]));//COLLADA DAE rotate is in degrees, convert to radians
|
||||
btQuaternion orn(btVector3(rotate), btRadians(rotate[3])); //COLLADA DAE rotate is in degrees, convert to radians
|
||||
btMatrix4x4 t;
|
||||
t.setPureRotation(orn);
|
||||
nodeTrans = nodeTrans*t;
|
||||
nodeTrans = nodeTrans * t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nodeTrans = parentTransMat*nodeTrans;
|
||||
|
||||
|
||||
nodeTrans = parentTransMat * nodeTrans;
|
||||
|
||||
for (XMLElement* instanceGeom = node->FirstChildElement("instance_geometry");
|
||||
instanceGeom!=0;
|
||||
instanceGeom=instanceGeom->NextSiblingElement("instance_geometry"))
|
||||
instanceGeom != 0;
|
||||
instanceGeom = instanceGeom->NextSiblingElement("instance_geometry"))
|
||||
{
|
||||
const char* geomUrl = instanceGeom->Attribute("url");
|
||||
//printf("node referring to geom %s\n", geomUrl);
|
||||
@@ -434,37 +429,38 @@ void readNodeHierarchy(XMLElement* node,btHashMap<btHashString,int>& name2Shape,
|
||||
int* shapeIndexPtr = name2Shape[geomUrl];
|
||||
if (shapeIndexPtr)
|
||||
{
|
||||
// int index = *shapeIndexPtr;
|
||||
// int index = *shapeIndexPtr;
|
||||
//printf("found geom with index %d\n", *shapeIndexPtr);
|
||||
ColladaGraphicsInstance& instance = visualShapeInstances.expand();
|
||||
instance.m_shapeIndex = *shapeIndexPtr;
|
||||
instance.m_worldTransform = nodeTrans;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Warning("geom not found\n");
|
||||
}
|
||||
}
|
||||
|
||||
for(XMLElement* childNode = node->FirstChildElement("node");
|
||||
childNode!= NULL; childNode = childNode->NextSiblingElement("node"))
|
||||
for (XMLElement* childNode = node->FirstChildElement("node");
|
||||
childNode != NULL; childNode = childNode->NextSiblingElement("node"))
|
||||
{
|
||||
readNodeHierarchy(childNode,name2Shape,visualShapeInstances, nodeTrans);
|
||||
readNodeHierarchy(childNode, name2Shape, visualShapeInstances, nodeTrans);
|
||||
}
|
||||
}
|
||||
void readVisualSceneInstanceGeometries(XMLDocument& doc, btHashMap<btHashString,int>& name2Shape, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances)
|
||||
void readVisualSceneInstanceGeometries(XMLDocument& doc, btHashMap<btHashString, int>& name2Shape, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances)
|
||||
{
|
||||
btHashMap<btHashString,XMLElement* > allVisualScenes;
|
||||
btHashMap<btHashString, XMLElement*> allVisualScenes;
|
||||
|
||||
XMLElement* libVisualScenes = doc.RootElement()->FirstChildElement("library_visual_scenes");
|
||||
if (libVisualScenes==0)
|
||||
if (libVisualScenes == 0)
|
||||
return;
|
||||
|
||||
{
|
||||
for(XMLElement* scene = libVisualScenes->FirstChildElement("visual_scene");
|
||||
scene != NULL; scene = scene->NextSiblingElement("visual_scene"))
|
||||
for (XMLElement* scene = libVisualScenes->FirstChildElement("visual_scene");
|
||||
scene != NULL; scene = scene->NextSiblingElement("visual_scene"))
|
||||
{
|
||||
const char* sceneName = scene->Attribute("id");
|
||||
allVisualScenes.insert(sceneName,scene);
|
||||
allVisualScenes.insert(sceneName, scene);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,7 +473,7 @@ void readVisualSceneInstanceGeometries(XMLDocument& doc, btHashMap<btHashString,
|
||||
if (instanceSceneReference)
|
||||
{
|
||||
const char* instanceSceneUrl = instanceSceneReference->Attribute("url");
|
||||
XMLElement** sceneInstancePtr = allVisualScenes[instanceSceneUrl+1];//skip #
|
||||
XMLElement** sceneInstancePtr = allVisualScenes[instanceSceneUrl + 1]; //skip #
|
||||
if (sceneInstancePtr)
|
||||
{
|
||||
scene = *sceneInstancePtr;
|
||||
@@ -488,28 +484,26 @@ void readVisualSceneInstanceGeometries(XMLDocument& doc, btHashMap<btHashString,
|
||||
|
||||
if (scene)
|
||||
{
|
||||
for(XMLElement* node = scene->FirstChildElement("node");
|
||||
node != NULL; node = node->NextSiblingElement("node"))
|
||||
for (XMLElement* node = scene->FirstChildElement("node");
|
||||
node != NULL; node = node->NextSiblingElement("node"))
|
||||
{
|
||||
btMatrix4x4 identity;
|
||||
identity.setIdentity();
|
||||
btVector3 identScaling(1,1,1);
|
||||
readNodeHierarchy(node,name2Shape,visualShapeInstances, identity);
|
||||
|
||||
btVector3 identScaling(1, 1, 1);
|
||||
readNodeHierarchy(node, name2Shape, visualShapeInstances, identity);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void getUnitMeterScalingAndUpAxisTransform(XMLDocument& doc, btTransform& tr, float& unitMeterScaling, int clientUpAxis)
|
||||
{
|
||||
///todo(erwincoumans) those up-axis transformations have been quickly coded without rigorous testing
|
||||
|
||||
|
||||
XMLElement* unitMeter = doc.RootElement()->FirstChildElement("asset")->FirstChildElement("unit");
|
||||
if (unitMeter)
|
||||
{
|
||||
const char* meterText = unitMeter->Attribute("meter");
|
||||
//printf("meterText=%s\n", meterText);
|
||||
//printf("meterText=%s\n", meterText);
|
||||
unitMeterScaling = atof(meterText);
|
||||
}
|
||||
|
||||
@@ -518,13 +512,12 @@ void getUnitMeterScalingAndUpAxisTransform(XMLDocument& doc, btTransform& tr, fl
|
||||
{
|
||||
switch (clientUpAxis)
|
||||
{
|
||||
|
||||
case 1:
|
||||
{
|
||||
std::string upAxisTxt = upAxisElem->GetText();
|
||||
if (upAxisTxt == "X_UP")
|
||||
{
|
||||
btQuaternion x2y(btVector3(0,0,1),SIMD_HALF_PI);
|
||||
btQuaternion x2y(btVector3(0, 0, 1), SIMD_HALF_PI);
|
||||
tr.setRotation(x2y);
|
||||
}
|
||||
if (upAxisTxt == "Y_UP")
|
||||
@@ -534,7 +527,7 @@ void getUnitMeterScalingAndUpAxisTransform(XMLDocument& doc, btTransform& tr, fl
|
||||
}
|
||||
if (upAxisTxt == "Z_UP")
|
||||
{
|
||||
btQuaternion z2y(btVector3(1,0,0),-SIMD_HALF_PI);
|
||||
btQuaternion z2y(btVector3(1, 0, 0), -SIMD_HALF_PI);
|
||||
tr.setRotation(z2y);
|
||||
}
|
||||
break;
|
||||
@@ -544,12 +537,12 @@ void getUnitMeterScalingAndUpAxisTransform(XMLDocument& doc, btTransform& tr, fl
|
||||
std::string upAxisTxt = upAxisElem->GetText();
|
||||
if (upAxisTxt == "X_UP")
|
||||
{
|
||||
btQuaternion x2z(btVector3(0,1,0),-SIMD_HALF_PI);
|
||||
btQuaternion x2z(btVector3(0, 1, 0), -SIMD_HALF_PI);
|
||||
tr.setRotation(x2z);
|
||||
}
|
||||
if (upAxisTxt == "Y_UP")
|
||||
{
|
||||
btQuaternion y2z(btVector3(1,0,0),SIMD_HALF_PI);
|
||||
btQuaternion y2z(btVector3(1, 0, 0), SIMD_HALF_PI);
|
||||
tr.setRotation(y2z);
|
||||
}
|
||||
if (upAxisTxt == "Z_UP")
|
||||
@@ -568,46 +561,42 @@ void getUnitMeterScalingAndUpAxisTransform(XMLDocument& doc, btTransform& tr, fl
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMeshFromCollada(const char* relativeFileName, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances, btTransform& upAxisTransform, float& unitMeterScaling,int clientUpAxis)
|
||||
void LoadMeshFromCollada(const char* relativeFileName, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances, btTransform& upAxisTransform, float& unitMeterScaling, int clientUpAxis)
|
||||
{
|
||||
// GLInstanceGraphicsShape* instance = 0;
|
||||
|
||||
// GLInstanceGraphicsShape* instance = 0;
|
||||
|
||||
//usually COLLADA files don't have that many visual geometries/shapes
|
||||
visualShapes.reserve(MAX_VISUAL_SHAPES);
|
||||
|
||||
float extraScaling = 1;//0.01;
|
||||
float extraScaling = 1; //0.01;
|
||||
btHashMap<btHashString, int> name2ShapeIndex;
|
||||
b3FileUtils f;
|
||||
char filename[1024];
|
||||
if (!f.findFile(relativeFileName,filename,1024))
|
||||
if (!f.findFile(relativeFileName, filename, 1024))
|
||||
{
|
||||
b3Warning("File not found: %s\n", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
XMLDocument doc;
|
||||
if (doc.LoadFile(filename) != XML_SUCCESS)
|
||||
return;
|
||||
|
||||
//We need units to be in meter, so apply a scaling using the asset/units meter
|
||||
unitMeterScaling=1;
|
||||
//We need units to be in meter, so apply a scaling using the asset/units meter
|
||||
unitMeterScaling = 1;
|
||||
upAxisTransform.setIdentity();
|
||||
|
||||
//Also we can optionally compensate all transforms using the asset/up_axis as well as unit meter scaling
|
||||
getUnitMeterScalingAndUpAxisTransform(doc, upAxisTransform, unitMeterScaling,clientUpAxis);
|
||||
|
||||
getUnitMeterScalingAndUpAxisTransform(doc, upAxisTransform, unitMeterScaling, clientUpAxis);
|
||||
|
||||
btMatrix4x4 ident;
|
||||
ident.setIdentity();
|
||||
|
||||
readLibraryGeometries(doc, visualShapes, name2ShapeIndex, extraScaling);
|
||||
|
||||
|
||||
readVisualSceneInstanceGeometries(doc, name2ShapeIndex, visualShapeInstances);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef COMPARE_WITH_ASSIMP
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
@@ -615,127 +604,128 @@ void LoadMeshFromCollada(const char* relativeFileName, btAlignedObjectArray<GLIn
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/scene.h>
|
||||
|
||||
|
||||
# include "assimp/ColladaLoader.h"
|
||||
#include "assimp/ColladaLoader.h"
|
||||
//# include "STLLoader.h"
|
||||
# include "assimp/SortByPTypeProcess.h"
|
||||
# include "assimp/LimitBoneWeightsProcess.h"
|
||||
# include "assimp/TriangulateProcess.h"
|
||||
# include "assimp/JoinVerticesProcess.h"
|
||||
# include "assimp/RemoveVCProcess.h"
|
||||
#include "assimp/SortByPTypeProcess.h"
|
||||
#include "assimp/LimitBoneWeightsProcess.h"
|
||||
#include "assimp/TriangulateProcess.h"
|
||||
#include "assimp/JoinVerticesProcess.h"
|
||||
#include "assimp/RemoveVCProcess.h"
|
||||
|
||||
|
||||
namespace Assimp {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void GetImporterInstanceList(std::vector< BaseImporter* >& out)
|
||||
{
|
||||
out.push_back( new ColladaLoader());
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out)
|
||||
{
|
||||
out.push_back( new SortByPTypeProcess());
|
||||
out.push_back( new LimitBoneWeightsProcess());
|
||||
out.push_back( new TriangulateProcess());
|
||||
out.push_back( new JoinVerticesProcess());
|
||||
//out.push_back( new RemoveVCProcess());
|
||||
}
|
||||
|
||||
namespace Assimp
|
||||
{
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void GetImporterInstanceList(std::vector<BaseImporter*>& out)
|
||||
{
|
||||
out.push_back(new ColladaLoader());
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void GetPostProcessingStepInstanceList(std::vector<BaseProcess*>& out)
|
||||
{
|
||||
out.push_back(new SortByPTypeProcess());
|
||||
out.push_back(new LimitBoneWeightsProcess());
|
||||
out.push_back(new TriangulateProcess());
|
||||
out.push_back(new JoinVerticesProcess());
|
||||
//out.push_back( new RemoveVCProcess());
|
||||
}
|
||||
|
||||
} // namespace Assimp
|
||||
|
||||
static void addMeshParts(const aiScene* scene, const aiNode* node, GLInstanceGraphicsShape* outverts, const aiMatrix4x4& parentTr)
|
||||
{
|
||||
aiMatrix4x4 const& nodeTrans(node->mTransformation);
|
||||
|
||||
aiMatrix4x4 trans;
|
||||
trans = parentTr * nodeTrans;
|
||||
|
||||
for (size_t i = 0; i < node->mNumMeshes; ++i)
|
||||
aiMatrix4x4 const& nodeTrans(node->mTransformation);
|
||||
|
||||
aiMatrix4x4 trans;
|
||||
trans = parentTr * nodeTrans;
|
||||
|
||||
for (size_t i = 0; i < node->mNumMeshes; ++i)
|
||||
{
|
||||
aiMesh const* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
size_t num_vertices = mesh->mNumVertices;
|
||||
if (mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE)
|
||||
{
|
||||
aiMesh const* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
size_t num_vertices = mesh->mNumVertices;
|
||||
if (mesh->mPrimitiveTypes==aiPrimitiveType_TRIANGLE)
|
||||
int curVertexBase = outverts->m_vertices->size();
|
||||
|
||||
for (int v = 0; v < mesh->mNumVertices; v++)
|
||||
{
|
||||
int curVertexBase = outverts->m_vertices->size();
|
||||
|
||||
for (int v=0;v<mesh->mNumVertices;v++)
|
||||
GLInstanceVertex vtx;
|
||||
aiVector3D vWorld = trans * mesh->mVertices[v];
|
||||
vtx.xyzw[0] = vWorld.x;
|
||||
vtx.xyzw[1] = vWorld.y;
|
||||
vtx.xyzw[2] = vWorld.z;
|
||||
vtx.xyzw[3] = 1;
|
||||
if (mesh->HasNormals())
|
||||
{
|
||||
GLInstanceVertex vtx;
|
||||
aiVector3D vWorld = trans*mesh->mVertices[v];
|
||||
vtx.xyzw[0] = vWorld.x;
|
||||
vtx.xyzw[1] = vWorld.y;
|
||||
vtx.xyzw[2] = vWorld.z;
|
||||
vtx.xyzw[3] = 1;
|
||||
if (mesh->HasNormals())
|
||||
{
|
||||
vtx.normal[0] = mesh->mNormals[v].x;
|
||||
vtx.normal[1] = mesh->mNormals[v].y;
|
||||
vtx.normal[2] = mesh->mNormals[v].z;
|
||||
} else
|
||||
{
|
||||
vtx.normal[0] = 0;
|
||||
vtx.normal[1] = 0;
|
||||
vtx.normal[2] = 1;
|
||||
}
|
||||
if (mesh->HasTextureCoords(0))
|
||||
{
|
||||
vtx.uv[0] = mesh->mTextureCoords[0][v].x;
|
||||
vtx.uv[1] = mesh->mTextureCoords[0][v].y;
|
||||
} else
|
||||
{
|
||||
vtx.uv[0]=0.5f;
|
||||
vtx.uv[1]=0.5f;
|
||||
}
|
||||
outverts->m_vertices->push_back(vtx);
|
||||
vtx.normal[0] = mesh->mNormals[v].x;
|
||||
vtx.normal[1] = mesh->mNormals[v].y;
|
||||
vtx.normal[2] = mesh->mNormals[v].z;
|
||||
}
|
||||
for (int f=0;f<mesh->mNumFaces;f++)
|
||||
else
|
||||
{
|
||||
b3Assert(mesh->mFaces[f].mNumIndices == 3);
|
||||
int i0 = mesh->mFaces[f].mIndices[0];
|
||||
int i1 = mesh->mFaces[f].mIndices[1];
|
||||
int i2 = mesh->mFaces[f].mIndices[2];
|
||||
outverts->m_indices->push_back(i0+curVertexBase);
|
||||
outverts->m_indices->push_back(i1+curVertexBase);
|
||||
outverts->m_indices->push_back(i2+curVertexBase);
|
||||
vtx.normal[0] = 0;
|
||||
vtx.normal[1] = 0;
|
||||
vtx.normal[2] = 1;
|
||||
}
|
||||
if (mesh->HasTextureCoords(0))
|
||||
{
|
||||
vtx.uv[0] = mesh->mTextureCoords[0][v].x;
|
||||
vtx.uv[1] = mesh->mTextureCoords[0][v].y;
|
||||
}
|
||||
else
|
||||
{
|
||||
vtx.uv[0] = 0.5f;
|
||||
vtx.uv[1] = 0.5f;
|
||||
}
|
||||
outverts->m_vertices->push_back(vtx);
|
||||
}
|
||||
}
|
||||
for (size_t i=0 ; i<node->mNumChildren ; ++i) {
|
||||
addMeshParts(scene,node->mChildren[i], outverts, trans);
|
||||
}
|
||||
for (int f = 0; f < mesh->mNumFaces; f++)
|
||||
{
|
||||
b3Assert(mesh->mFaces[f].mNumIndices == 3);
|
||||
int i0 = mesh->mFaces[f].mIndices[0];
|
||||
int i1 = mesh->mFaces[f].mIndices[1];
|
||||
int i2 = mesh->mFaces[f].mIndices[2];
|
||||
outverts->m_indices->push_back(i0 + curVertexBase);
|
||||
outverts->m_indices->push_back(i1 + curVertexBase);
|
||||
outverts->m_indices->push_back(i2 + curVertexBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < node->mNumChildren; ++i)
|
||||
{
|
||||
addMeshParts(scene, node->mChildren[i], outverts, trans);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LoadMeshFromColladaAssimp(const char* relativeFileName, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances,btTransform& upAxisTrans, float& unitMeterScaling)
|
||||
void LoadMeshFromColladaAssimp(const char* relativeFileName, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances, btTransform& upAxisTrans, float& unitMeterScaling)
|
||||
{
|
||||
upAxisTrans.setIdentity();
|
||||
unitMeterScaling=1;
|
||||
unitMeterScaling = 1;
|
||||
|
||||
GLInstanceGraphicsShape* shape = 0;
|
||||
|
||||
|
||||
FILE* file = fopen(relativeFileName,"rb");
|
||||
|
||||
FILE* file = fopen(relativeFileName, "rb");
|
||||
if (file)
|
||||
{
|
||||
int size=0;
|
||||
int size = 0;
|
||||
if (fseek(file, 0, SEEK_END) || (size = ftell(file)) == EOF || fseek(file, 0, SEEK_SET))
|
||||
{
|
||||
b3Warning("Error: Cannot access file to determine size of %s\n", relativeFileName);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
//printf("Open DAE file of %d bytes\n",size);
|
||||
|
||||
|
||||
Assimp::Importer importer;
|
||||
//importer.SetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS, aiComponent_NORMALS | aiComponent_COLORS);
|
||||
importer.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE | aiPrimitiveType_POINT);
|
||||
// importer.SetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION, 1);
|
||||
// importer.SetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION, 1);
|
||||
aiScene const* scene = importer.ReadFile(relativeFileName,
|
||||
aiProcess_JoinIdenticalVertices |
|
||||
//aiProcess_RemoveComponent |
|
||||
aiProcess_SortByPType |
|
||||
aiProcess_Triangulate);
|
||||
aiProcess_JoinIdenticalVertices |
|
||||
//aiProcess_RemoveComponent |
|
||||
aiProcess_SortByPType |
|
||||
aiProcess_Triangulate);
|
||||
if (scene)
|
||||
{
|
||||
shape = &visualShapes.expand();
|
||||
@@ -749,16 +739,14 @@ void LoadMeshFromColladaAssimp(const char* relativeFileName, btAlignedObjectArra
|
||||
|
||||
aiMatrix4x4 ident;
|
||||
addMeshParts(scene, scene->mRootNode, shape, ident);
|
||||
shape->m_numIndices = shape->m_indices->size();
|
||||
shape->m_numIndices = shape->m_indices->size();
|
||||
shape->m_numvertices = shape->m_vertices->size();
|
||||
ColladaGraphicsInstance& instance = visualShapeInstances.expand();
|
||||
instance.m_shapeIndex = visualShapes.size()-1;
|
||||
instance.m_shapeIndex = visualShapes.size() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //COMPARE_WITH_ASSIMP
|
||||
#endif //COMPARE_WITH_ASSIMP
|
||||
|
||||
@@ -15,7 +15,6 @@ subject to the following restrictions:
|
||||
//original author: Erwin Coumans
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LOAD_MESH_FROM_COLLADA_H
|
||||
#define LOAD_MESH_FROM_COLLADA_H
|
||||
|
||||
@@ -24,22 +23,20 @@ subject to the following restrictions:
|
||||
#include "../../OpenGLWindow/GLInstanceGraphicsShape.h"
|
||||
#include "ColladaGraphicsInstance.h"
|
||||
|
||||
|
||||
void LoadMeshFromCollada(const char* relativeFileName,
|
||||
btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes,
|
||||
btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances,
|
||||
btTransform& upAxisTrans,
|
||||
float& unitMeterScaling,
|
||||
btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes,
|
||||
btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances,
|
||||
btTransform& upAxisTrans,
|
||||
float& unitMeterScaling,
|
||||
int clientUpAxis);
|
||||
|
||||
//#define COMPARE_WITH_ASSIMP
|
||||
#ifdef COMPARE_WITH_ASSIMP
|
||||
void LoadMeshFromColladaAssimp(const char* relativeFileName,
|
||||
btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes,
|
||||
btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances,
|
||||
btTransform& upAxisTrans,
|
||||
float& unitMeterScaling
|
||||
);
|
||||
#endif //COMPARE_WITH_ASSIMP
|
||||
void LoadMeshFromColladaAssimp(const char* relativeFileName,
|
||||
btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes,
|
||||
btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances,
|
||||
btTransform& upAxisTrans,
|
||||
float& unitMeterScaling);
|
||||
#endif //COMPARE_WITH_ASSIMP
|
||||
|
||||
#endif //LOAD_MESH_FROM_COLLADA_H
|
||||
#endif //LOAD_MESH_FROM_COLLADA_H
|
||||
|
||||
@@ -15,7 +15,6 @@ subject to the following restrictions:
|
||||
//original author: Erwin Coumans
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MATRIX4x4_H
|
||||
#define MATRIX4x4_H
|
||||
|
||||
@@ -23,55 +22,56 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btQuaternion.h"
|
||||
|
||||
///This 4x4 matrix class is extremely limited, just created for the purpose of accumulating transform matrices in COLLADA .dae files
|
||||
ATTRIBUTE_ALIGNED16(class) btMatrix4x4
|
||||
ATTRIBUTE_ALIGNED16(class)
|
||||
btMatrix4x4
|
||||
{
|
||||
btVector4 m_el[4];
|
||||
public:
|
||||
|
||||
public:
|
||||
btMatrix4x4()
|
||||
{
|
||||
}
|
||||
btMatrix4x4(const btScalar& xx, const btScalar& xy, const btScalar& xz,const btScalar& xw,
|
||||
const btScalar& yx, const btScalar& yy, const btScalar& yz,const btScalar& yw,
|
||||
const btScalar& zx, const btScalar& zy, const btScalar& zz, const btScalar& zw,
|
||||
const btScalar& wx, const btScalar& wy, const btScalar& wz, const btScalar& ww)
|
||||
{
|
||||
btMatrix4x4(const btScalar& xx, const btScalar& xy, const btScalar& xz, const btScalar& xw,
|
||||
const btScalar& yx, const btScalar& yy, const btScalar& yz, const btScalar& yw,
|
||||
const btScalar& zx, const btScalar& zy, const btScalar& zz, const btScalar& zw,
|
||||
const btScalar& wx, const btScalar& wy, const btScalar& wz, const btScalar& ww)
|
||||
{
|
||||
setValue(xx, xy, xz, xw,
|
||||
yx, yy, yz, yw,
|
||||
zx, zy, zz,zw,
|
||||
wx, wy, wz,ww);
|
||||
yx, yy, yz, yw,
|
||||
zx, zy, zz, zw,
|
||||
wx, wy, wz, ww);
|
||||
}
|
||||
|
||||
~btMatrix4x4()
|
||||
{
|
||||
}
|
||||
|
||||
inline void setValue(const btScalar& xx, const btScalar& xy, const btScalar& xz,const btScalar& xw,
|
||||
const btScalar& yx, const btScalar& yy, const btScalar& yz,const btScalar& yw,
|
||||
const btScalar& zx, const btScalar& zy, const btScalar& zz, const btScalar& zw,
|
||||
const btScalar& wx, const btScalar& wy, const btScalar& wz, const btScalar& ww)
|
||||
{
|
||||
m_el[0].setValue(xx,xy,xz,xw);
|
||||
m_el[1].setValue(yx,yy,yz,yw);
|
||||
m_el[2].setValue(zx,zy,zz,zw);
|
||||
m_el[3].setValue(wx,wy,wz,ww);
|
||||
inline void setValue(const btScalar& xx, const btScalar& xy, const btScalar& xz, const btScalar& xw,
|
||||
const btScalar& yx, const btScalar& yy, const btScalar& yz, const btScalar& yw,
|
||||
const btScalar& zx, const btScalar& zy, const btScalar& zz, const btScalar& zw,
|
||||
const btScalar& wx, const btScalar& wy, const btScalar& wz, const btScalar& ww)
|
||||
{
|
||||
m_el[0].setValue(xx, xy, xz, xw);
|
||||
m_el[1].setValue(yx, yy, yz, yw);
|
||||
m_el[2].setValue(zx, zy, zz, zw);
|
||||
m_el[3].setValue(wx, wy, wz, ww);
|
||||
}
|
||||
|
||||
inline void setIdentity()
|
||||
{
|
||||
m_el[0].setValue(1,0,0,0);
|
||||
m_el[1].setValue(0,1,0,0);
|
||||
m_el[2].setValue(0,0,1,0);
|
||||
m_el[3].setValue(0,0,0,1);
|
||||
m_el[0].setValue(1, 0, 0, 0);
|
||||
m_el[1].setValue(0, 1, 0, 0);
|
||||
m_el[2].setValue(0, 0, 1, 0);
|
||||
m_el[3].setValue(0, 0, 0, 1);
|
||||
}
|
||||
inline void setPureRotation(const btQuaternion& orn)
|
||||
{
|
||||
setIdentity();
|
||||
|
||||
btMatrix3x3 m3(orn);
|
||||
for (int i=0;i<3;i++)
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j=0;j<3;j++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
m_el[i][j] = m3[i][j];
|
||||
}
|
||||
@@ -80,78 +80,73 @@ ATTRIBUTE_ALIGNED16(class) btMatrix4x4
|
||||
|
||||
inline void setPureScaling(const btVector3& scale)
|
||||
{
|
||||
m_el[0].setValue(scale[0],0,0,0);
|
||||
m_el[1].setValue(0,scale[1],0,0);
|
||||
m_el[2].setValue(0,0,scale[2],0);
|
||||
m_el[3].setValue(0,0,0,1);
|
||||
m_el[0].setValue(scale[0], 0, 0, 0);
|
||||
m_el[1].setValue(0, scale[1], 0, 0);
|
||||
m_el[2].setValue(0, 0, scale[2], 0);
|
||||
m_el[3].setValue(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
inline void setPureTranslation(const btVector3& pos)
|
||||
{
|
||||
m_el[0].setValue(1,0,0,pos[0]);
|
||||
m_el[1].setValue(0,1,0,pos[1]);
|
||||
m_el[2].setValue(0,0,1,pos[2]);
|
||||
m_el[3].setValue(0,0,0,1);
|
||||
|
||||
m_el[0].setValue(1, 0, 0, pos[0]);
|
||||
m_el[1].setValue(0, 1, 0, pos[1]);
|
||||
m_el[2].setValue(0, 0, 1, pos[2]);
|
||||
m_el[3].setValue(0, 0, 0, 1);
|
||||
}
|
||||
SIMD_FORCE_INLINE const btVector4& operator[](int i) const
|
||||
{
|
||||
btFullAssert(0 <= i && i < 3);
|
||||
return m_el[i];
|
||||
return m_el[i];
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btScalar tdotx(const btVector4& v) const
|
||||
SIMD_FORCE_INLINE btScalar tdotx(const btVector4& v) const
|
||||
{
|
||||
return m_el[0].x() * v.x() + m_el[1].x() * v.y() + m_el[2].x() * v.z() + m_el[3].x()* v.w();
|
||||
return m_el[0].x() * v.x() + m_el[1].x() * v.y() + m_el[2].x() * v.z() + m_el[3].x() * v.w();
|
||||
}
|
||||
SIMD_FORCE_INLINE btScalar tdoty(const btVector4& v) const
|
||||
SIMD_FORCE_INLINE btScalar tdoty(const btVector4& v) const
|
||||
{
|
||||
return m_el[0].y() * v.x() + m_el[1].y() * v.y() + m_el[2].y() * v.z() + m_el[3].y() * v.w();
|
||||
}
|
||||
SIMD_FORCE_INLINE btScalar tdotz(const btVector4& v) const
|
||||
SIMD_FORCE_INLINE btScalar tdotz(const btVector4& v) const
|
||||
{
|
||||
return m_el[0].z() * v.x() + m_el[1].z() * v.y() + m_el[2].z() * v.z() + m_el[3].z() * v.w();
|
||||
}
|
||||
SIMD_FORCE_INLINE btScalar tdotw(const btVector4& v) const
|
||||
SIMD_FORCE_INLINE btScalar tdotw(const btVector4& v) const
|
||||
{
|
||||
return m_el[0].w() * v.x() + m_el[1].w() * v.y() + m_el[2].w() * v.z() + m_el[3].w() * v.w();
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btMatrix4x4 &
|
||||
SIMD_FORCE_INLINE btMatrix4x4&
|
||||
operator*=(const btMatrix4x4& m)
|
||||
{
|
||||
setValue(
|
||||
m.tdotx(m_el[0]), m.tdoty(m_el[0]), m.tdotz(m_el[0]),m.tdotw(m_el[0]),
|
||||
m.tdotx(m_el[1]), m.tdoty(m_el[1]), m.tdotz(m_el[1]),m.tdotw(m_el[1]),
|
||||
m.tdotx(m_el[2]), m.tdoty(m_el[2]), m.tdotz(m_el[2]),m.tdotw(m_el[2]),
|
||||
m.tdotx(m_el[3]), m.tdoty(m_el[3]), m.tdotz(m_el[3]),m.tdotw(m_el[3]));
|
||||
m.tdotx(m_el[0]), m.tdoty(m_el[0]), m.tdotz(m_el[0]), m.tdotw(m_el[0]),
|
||||
m.tdotx(m_el[1]), m.tdoty(m_el[1]), m.tdotz(m_el[1]), m.tdotw(m_el[1]),
|
||||
m.tdotx(m_el[2]), m.tdoty(m_el[2]), m.tdotz(m_el[2]), m.tdotw(m_el[2]),
|
||||
m.tdotx(m_el[3]), m.tdoty(m_el[3]), m.tdotz(m_el[3]), m.tdotw(m_el[3]));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
inline btScalar btDot4(const btVector4& v0, const btVector4& v1)
|
||||
{
|
||||
return v0.x()*v1.x()+v0.y()*v1.y()+v0.z()*v1.z()+v0.w()*v1.w();
|
||||
return v0.x() * v1.x() + v0.y() * v1.y() + v0.z() * v1.z() + v0.w() * v1.w();
|
||||
}
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
operator*(const btMatrix4x4& m, const btVector3& v1)
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
operator*(const btMatrix4x4& m, const btVector3& v1)
|
||||
{
|
||||
btVector4 v(v1[0],v1[1],v1[2],1);
|
||||
return btVector3(btDot4(m[0],v), btDot4(m[1],v), btDot4(m[2],v));
|
||||
btVector4 v(v1[0], v1[1], v1[2], 1);
|
||||
return btVector3(btDot4(m[0], v), btDot4(m[1], v), btDot4(m[2], v));
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btMatrix4x4
|
||||
operator*(const btMatrix4x4& m1, btMatrix4x4& m2)
|
||||
{
|
||||
return btMatrix4x4(
|
||||
m2.tdotx(m1[0]), m2.tdoty(m1[0]), m2.tdotz(m1[0]),m2.tdotw(m1[0]),
|
||||
m2.tdotx(m1[1]), m2.tdoty(m1[1]), m2.tdotz(m1[1]),m2.tdotw(m1[1]),
|
||||
m2.tdotx(m1[2]), m2.tdoty(m1[2]), m2.tdotz(m1[2]),m2.tdotw(m1[2]),
|
||||
m2.tdotx(m1[3]), m2.tdoty(m1[3]), m2.tdotz(m1[3]),m2.tdotw(m1[3]));
|
||||
}
|
||||
SIMD_FORCE_INLINE btMatrix4x4
|
||||
operator*(const btMatrix4x4& m1, btMatrix4x4& m2)
|
||||
{
|
||||
return btMatrix4x4(
|
||||
m2.tdotx(m1[0]), m2.tdoty(m1[0]), m2.tdotz(m1[0]), m2.tdotw(m1[0]),
|
||||
m2.tdotx(m1[1]), m2.tdoty(m1[1]), m2.tdotz(m1[1]), m2.tdotw(m1[1]),
|
||||
m2.tdotx(m1[2]), m2.tdoty(m1[2]), m2.tdotz(m1[2]), m2.tdotw(m1[2]),
|
||||
m2.tdotx(m1[3]), m2.tdoty(m1[3]), m2.tdotz(m1[3]), m2.tdotw(m1[3]));
|
||||
}
|
||||
|
||||
|
||||
#endif //MATRIX4x4_H
|
||||
#endif //MATRIX4x4_H
|
||||
|
||||
Reference in New Issue
Block a user