|
@@ -1,4 +1,8 @@
|
|
|
|
|
+/*
|
|
|
|
|
+ * DAESceneEncoder.h
|
|
|
|
|
+ */
|
|
|
#include "Base.h"
|
|
#include "Base.h"
|
|
|
|
|
+
|
|
|
#include "DAESceneEncoder.h"
|
|
#include "DAESceneEncoder.h"
|
|
|
#include "DAEOptimizer.h"
|
|
#include "DAEOptimizer.h"
|
|
|
|
|
|
|
@@ -16,28 +20,10 @@ DAESceneEncoder::~DAESceneEncoder()
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-std::string getFilenameFromFilePath(const std::string& filepath)
|
|
|
|
|
-{
|
|
|
|
|
- if (filepath.find_last_of("/") != std::string::npos)
|
|
|
|
|
- {
|
|
|
|
|
- return filepath.substr(filepath.find_last_of("/")+1);
|
|
|
|
|
- }
|
|
|
|
|
- return "";
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-std::string getFilenameNoExt(const std::string& filename)
|
|
|
|
|
-{
|
|
|
|
|
- if (filename.find_last_of(".") != std::string::npos)
|
|
|
|
|
- {
|
|
|
|
|
- return filename.substr(0, filename.find_last_of("."));
|
|
|
|
|
- }
|
|
|
|
|
- return filename;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
unsigned int getMaxOffset(domInputLocalOffset_Array& inputArray)
|
|
unsigned int getMaxOffset(domInputLocalOffset_Array& inputArray)
|
|
|
{
|
|
{
|
|
|
unsigned int maxOffset = 0;
|
|
unsigned int maxOffset = 0;
|
|
|
- for (unsigned int i = 0; i < (int)inputArray.getCount(); i++ )
|
|
|
|
|
|
|
+ for (unsigned int i = 0; i < (int)inputArray.getCount(); ++i)
|
|
|
{
|
|
{
|
|
|
if ( inputArray[i]->getOffset() > maxOffset )
|
|
if ( inputArray[i]->getOffset() > maxOffset )
|
|
|
{
|
|
{
|
|
@@ -58,7 +44,7 @@ void DAESceneEncoder::optimizeCOLLADA(const EncoderArguments& arguments, domCOLL
|
|
|
if (size > 0)
|
|
if (size > 0)
|
|
|
{
|
|
{
|
|
|
begin();
|
|
begin();
|
|
|
- for (size_t i = 0; i < size; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < size; ++i)
|
|
|
{
|
|
{
|
|
|
optimizer.combineAnimations(groupAnimatioNodeIds[i], groupAnimatioIds[i]);
|
|
optimizer.combineAnimations(groupAnimatioNodeIds[i], groupAnimatioIds[i]);
|
|
|
}
|
|
}
|
|
@@ -78,7 +64,7 @@ void DAESceneEncoder::triangulate(DAE* dae)
|
|
|
daeDatabase* dataBase = dae->getDatabase();
|
|
daeDatabase* dataBase = dae->getDatabase();
|
|
|
|
|
|
|
|
int geometryCount = (int)(dataBase->getElementCount(0, "geometry"));
|
|
int geometryCount = (int)(dataBase->getElementCount(0, "geometry"));
|
|
|
- for (int i = 0; i < geometryCount; i++)
|
|
|
|
|
|
|
+ for (int i = 0; i < geometryCount; ++i)
|
|
|
{
|
|
{
|
|
|
// Find the next geometry element.
|
|
// Find the next geometry element.
|
|
|
domGeometry* domGeometry;
|
|
domGeometry* domGeometry;
|
|
@@ -93,14 +79,14 @@ void DAESceneEncoder::triangulate(DAE* dae)
|
|
|
|
|
|
|
|
// Loop over all the polygons elements.
|
|
// Loop over all the polygons elements.
|
|
|
int polygonsCount = (int)(domMesh->getPolygons_array().getCount());
|
|
int polygonsCount = (int)(domMesh->getPolygons_array().getCount());
|
|
|
- for (int j = 0; j < polygonsCount; j++)
|
|
|
|
|
|
|
+ for (int j = 0; j < polygonsCount; ++j)
|
|
|
{
|
|
{
|
|
|
// Get the polygons out of the mesh.
|
|
// Get the polygons out of the mesh.
|
|
|
domPolygons* domPolygons = domMesh->getPolygons_array()[j];
|
|
domPolygons* domPolygons = domMesh->getPolygons_array()[j];
|
|
|
// Create the triangles from the polygons
|
|
// Create the triangles from the polygons
|
|
|
createTrianglesFromPolygons(domMesh, domPolygons);
|
|
createTrianglesFromPolygons(domMesh, domPolygons);
|
|
|
}
|
|
}
|
|
|
- while(domMesh->getPolygons_array().getCount() > 0)
|
|
|
|
|
|
|
+ while (domMesh->getPolygons_array().getCount() > 0)
|
|
|
{
|
|
{
|
|
|
domPolygons* domPolygons = domMesh->getPolygons_array().get(0);
|
|
domPolygons* domPolygons = domMesh->getPolygons_array().get(0);
|
|
|
// Remove the polygons from the mesh.
|
|
// Remove the polygons from the mesh.
|
|
@@ -109,14 +95,14 @@ void DAESceneEncoder::triangulate(DAE* dae)
|
|
|
|
|
|
|
|
// Loop over all the polylist elements.
|
|
// Loop over all the polylist elements.
|
|
|
int polylistCount = (int)(domMesh->getPolylist_array().getCount());
|
|
int polylistCount = (int)(domMesh->getPolylist_array().getCount());
|
|
|
- for (int j = 0; j < polylistCount; j++)
|
|
|
|
|
|
|
+ for (int j = 0; j < polylistCount; ++j)
|
|
|
{
|
|
{
|
|
|
// Get the polylist out of the mesh.
|
|
// Get the polylist out of the mesh.
|
|
|
domPolylist* domPolylist = domMesh->getPolylist_array()[j];
|
|
domPolylist* domPolylist = domMesh->getPolylist_array()[j];
|
|
|
// Create the triangles from the polygon list
|
|
// Create the triangles from the polygon list
|
|
|
createTrianglesFromPolylist(domMesh, domPolylist);
|
|
createTrianglesFromPolylist(domMesh, domPolylist);
|
|
|
}
|
|
}
|
|
|
- while(domMesh->getPolylist_array().getCount() > 0)
|
|
|
|
|
|
|
+ while (domMesh->getPolylist_array().getCount() > 0)
|
|
|
{
|
|
{
|
|
|
domPolylist* domPolylist = domMesh->getPolylist_array().get(0);
|
|
domPolylist* domPolylist = domMesh->getPolylist_array().get(0);
|
|
|
// Remove the polylist from the mesh.
|
|
// Remove the polylist from the mesh.
|
|
@@ -134,7 +120,7 @@ void DAESceneEncoder::createTrianglesFromPolygons(domMesh* domMesh, domPolygons*
|
|
|
domP* domTrianglesP = (domP*)triangles->createAndPlace("p");
|
|
domP* domTrianglesP = (domP*)triangles->createAndPlace("p");
|
|
|
|
|
|
|
|
// Give the new <triangles> the same <_dae> and <parameters> as the old <polygons>.
|
|
// Give the new <triangles> the same <_dae> and <parameters> as the old <polygons>.
|
|
|
- for (unsigned int i = 0; i < domPolygons->getInput_array().getCount(); i++)
|
|
|
|
|
|
|
+ for (unsigned int i = 0; i < domPolygons->getInput_array().getCount(); ++i)
|
|
|
{
|
|
{
|
|
|
triangles->placeElement(domPolygons->getInput_array()[i]->clone());
|
|
triangles->placeElement(domPolygons->getInput_array()[i]->clone());
|
|
|
}
|
|
}
|
|
@@ -144,7 +130,7 @@ void DAESceneEncoder::createTrianglesFromPolygons(domMesh* domMesh, domPolygons*
|
|
|
unsigned int primitiveCount = domPolygons->getP_array().getCount();
|
|
unsigned int primitiveCount = domPolygons->getP_array().getCount();
|
|
|
|
|
|
|
|
// Triangulate all the primitives, this generates all the triangles in a single <p> element.
|
|
// Triangulate all the primitives, this generates all the triangles in a single <p> element.
|
|
|
- for (unsigned int j = 0; j < primitiveCount; j++)
|
|
|
|
|
|
|
+ for (unsigned int j = 0; j < primitiveCount; ++j)
|
|
|
{
|
|
{
|
|
|
// Check the polygons for consistancy (some exported files have had the wrong number of indices).
|
|
// Check the polygons for consistancy (some exported files have had the wrong number of indices).
|
|
|
domP* domCurrentP = domPolygons->getP_array()[j];
|
|
domP* domCurrentP = domPolygons->getP_array()[j];
|
|
@@ -159,21 +145,21 @@ void DAESceneEncoder::createTrianglesFromPolygons(domMesh* domMesh, domPolygons*
|
|
|
|
|
|
|
|
// Write out the primitives as triangles, just fan using the first element as the base.
|
|
// Write out the primitives as triangles, just fan using the first element as the base.
|
|
|
unsigned int index = inputCount;
|
|
unsigned int index = inputCount;
|
|
|
- for (unsigned int k = 0; k < triangleCount; k++)
|
|
|
|
|
|
|
+ for (unsigned int k = 0; k < triangleCount; ++k)
|
|
|
{
|
|
{
|
|
|
// First vertex.
|
|
// First vertex.
|
|
|
- for (unsigned int l = 0; l < inputCount; l++)
|
|
|
|
|
|
|
+ for (unsigned int l = 0; l < inputCount; ++l)
|
|
|
{
|
|
{
|
|
|
domTrianglesP->getValue().append(domCurrentP->getValue()[l]);
|
|
domTrianglesP->getValue().append(domCurrentP->getValue()[l]);
|
|
|
}
|
|
}
|
|
|
// Second vertex.
|
|
// Second vertex.
|
|
|
- for (unsigned int l = 0; l < inputCount; l++)
|
|
|
|
|
|
|
+ for (unsigned int l = 0; l < inputCount; ++l)
|
|
|
{
|
|
{
|
|
|
domTrianglesP->getValue().append(domCurrentP->getValue()[index + l]);
|
|
domTrianglesP->getValue().append(domCurrentP->getValue()[index + l]);
|
|
|
}
|
|
}
|
|
|
// Third vertex.
|
|
// Third vertex.
|
|
|
index += inputCount;
|
|
index += inputCount;
|
|
|
- for (unsigned int l = 0; l < inputCount; l++)
|
|
|
|
|
|
|
+ for (unsigned int l = 0; l < inputCount; ++l)
|
|
|
{
|
|
{
|
|
|
domTrianglesP->getValue().append(domCurrentP->getValue()[index + l]);
|
|
domTrianglesP->getValue().append(domCurrentP->getValue()[index + l]);
|
|
|
}
|
|
}
|
|
@@ -191,7 +177,7 @@ void DAESceneEncoder::createTrianglesFromPolylist(domMesh* domMesh, domPolylist*
|
|
|
domP* domTrianglesP = (domP*)triangles->createAndPlace("p");
|
|
domP* domTrianglesP = (domP*)triangles->createAndPlace("p");
|
|
|
|
|
|
|
|
// Give the new <triangles> the same <_dae> and <parameters> as the old <polylist>.
|
|
// Give the new <triangles> the same <_dae> and <parameters> as the old <polylist>.
|
|
|
- for (int i = 0; i < (int)(domPolylist->getInput_array().getCount()); i++)
|
|
|
|
|
|
|
+ for (int i = 0; i < (int)(domPolylist->getInput_array().getCount()); ++i)
|
|
|
{
|
|
{
|
|
|
triangles->placeElement(domPolylist->getInput_array()[i]->clone());
|
|
triangles->placeElement(domPolylist->getInput_array()[i]->clone());
|
|
|
}
|
|
}
|
|
@@ -204,27 +190,27 @@ void DAESceneEncoder::createTrianglesFromPolylist(domMesh* domMesh, domPolylist*
|
|
|
unsigned int trianglesProcessed = 0;
|
|
unsigned int trianglesProcessed = 0;
|
|
|
|
|
|
|
|
// Triangulate all the primitives, this generates all the triangles in a single <p> element.
|
|
// Triangulate all the primitives, this generates all the triangles in a single <p> element.
|
|
|
- for (unsigned int j = 0; j < primitiveCount; j++)
|
|
|
|
|
|
|
+ for (unsigned int j = 0; j < primitiveCount; ++j)
|
|
|
{
|
|
{
|
|
|
unsigned int triangleCount = (unsigned int)domPolylist->getVcount()->getValue()[j] - 2;
|
|
unsigned int triangleCount = (unsigned int)domPolylist->getVcount()->getValue()[j] - 2;
|
|
|
|
|
|
|
|
// Write out the primitives as triangles, just fan using the first element as the base.
|
|
// Write out the primitives as triangles, just fan using the first element as the base.
|
|
|
int index = inputCount;
|
|
int index = inputCount;
|
|
|
- for (unsigned int k = 0; k < triangleCount; k++)
|
|
|
|
|
|
|
+ for (unsigned int k = 0; k < triangleCount; ++k)
|
|
|
{
|
|
{
|
|
|
// First vertex.
|
|
// First vertex.
|
|
|
- for (unsigned int l = 0; l < inputCount; l++)
|
|
|
|
|
|
|
+ for (unsigned int l = 0; l < inputCount; ++l)
|
|
|
{
|
|
{
|
|
|
domTrianglesP->getValue().append(domPolylist->getP()->getValue()[offset + l]);
|
|
domTrianglesP->getValue().append(domPolylist->getP()->getValue()[offset + l]);
|
|
|
}
|
|
}
|
|
|
// Second vertex.
|
|
// Second vertex.
|
|
|
- for (unsigned int l = 0; l < inputCount; l++)
|
|
|
|
|
|
|
+ for (unsigned int l = 0; l < inputCount; ++l)
|
|
|
{
|
|
{
|
|
|
domTrianglesP->getValue().append(domPolylist->getP()->getValue()[offset + index + l]);
|
|
domTrianglesP->getValue().append(domPolylist->getP()->getValue()[offset + index + l]);
|
|
|
}
|
|
}
|
|
|
// Third vertex.
|
|
// Third vertex.
|
|
|
index += inputCount;
|
|
index += inputCount;
|
|
|
- for (unsigned int l = 0; l < inputCount; l++)
|
|
|
|
|
|
|
+ for (unsigned int l = 0; l < inputCount; ++l)
|
|
|
{
|
|
{
|
|
|
domTrianglesP->getValue().append(domPolylist->getP()->getValue()[offset + index + l]);
|
|
domTrianglesP->getValue().append(domPolylist->getP()->getValue()[offset + index + l]);
|
|
|
}
|
|
}
|
|
@@ -359,12 +345,12 @@ void DAESceneEncoder::loadAnimations(const domCOLLADA* dom)
|
|
|
// Call loadAnimation on all <animation> elements in all <library_animations>
|
|
// Call loadAnimation on all <animation> elements in all <library_animations>
|
|
|
const domLibrary_animations_Array& animationLibrarys = dom->getLibrary_animations_array();
|
|
const domLibrary_animations_Array& animationLibrarys = dom->getLibrary_animations_array();
|
|
|
size_t animationLibrarysCount = animationLibrarys.getCount();
|
|
size_t animationLibrarysCount = animationLibrarys.getCount();
|
|
|
- for (size_t i = 0; i < animationLibrarysCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < animationLibrarysCount; ++i)
|
|
|
{
|
|
{
|
|
|
const domLibrary_animationsRef& libraryAnimation = animationLibrarys.get(i);
|
|
const domLibrary_animationsRef& libraryAnimation = animationLibrarys.get(i);
|
|
|
const domAnimation_Array& animationArray = libraryAnimation->getAnimation_array();
|
|
const domAnimation_Array& animationArray = libraryAnimation->getAnimation_array();
|
|
|
size_t animationCount = animationArray.getCount();
|
|
size_t animationCount = animationArray.getCount();
|
|
|
- for (size_t j = 0; j < animationCount; j++)
|
|
|
|
|
|
|
+ for (size_t j = 0; j < animationCount; ++j)
|
|
|
{
|
|
{
|
|
|
const domAnimationRef& animationRef = animationArray.get(j);
|
|
const domAnimationRef& animationRef = animationArray.get(j);
|
|
|
loadAnimation(animationRef);
|
|
loadAnimation(animationRef);
|
|
@@ -387,7 +373,7 @@ void DAESceneEncoder::loadAnimation(const domAnimationRef animationRef)
|
|
|
// <channel>
|
|
// <channel>
|
|
|
const domChannel_Array& channelArray = animationRef->getChannel_array();
|
|
const domChannel_Array& channelArray = animationRef->getChannel_array();
|
|
|
size_t channelArrayCount = channelArray.getCount();
|
|
size_t channelArrayCount = channelArray.getCount();
|
|
|
- for (size_t i = 0; i < channelArrayCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < channelArrayCount; ++i)
|
|
|
{
|
|
{
|
|
|
AnimationChannel* animationChannel = new AnimationChannel();
|
|
AnimationChannel* animationChannel = new AnimationChannel();
|
|
|
|
|
|
|
@@ -400,7 +386,7 @@ void DAESceneEncoder::loadAnimation(const domAnimationRef animationRef)
|
|
|
// <input>
|
|
// <input>
|
|
|
const domInputLocal_Array& inputArray = sampler->getInput_array();
|
|
const domInputLocal_Array& inputArray = sampler->getInput_array();
|
|
|
size_t inputArrayCount = inputArray.getCount();
|
|
size_t inputArrayCount = inputArray.getCount();
|
|
|
- for (size_t j = 0; j < inputArrayCount; j++)
|
|
|
|
|
|
|
+ for (size_t j = 0; j < inputArrayCount; ++j)
|
|
|
{
|
|
{
|
|
|
const domInputLocalRef& inputLocal = inputArray.get(j);
|
|
const domInputLocalRef& inputLocal = inputArray.get(j);
|
|
|
|
|
|
|
@@ -421,7 +407,7 @@ void DAESceneEncoder::loadAnimation(const domAnimationRef animationRef)
|
|
|
if (equals(semantic, "INPUT"))
|
|
if (equals(semantic, "INPUT"))
|
|
|
{
|
|
{
|
|
|
// TODO: Ensure param name is TIME?
|
|
// TODO: Ensure param name is TIME?
|
|
|
- for (std::vector<float>::iterator k = floats.begin(); k != floats.end(); k++)
|
|
|
|
|
|
|
+ for (std::vector<float>::iterator k = floats.begin(); k != floats.end(); ++k)
|
|
|
{
|
|
{
|
|
|
// Convert seconds to milliseconds
|
|
// Convert seconds to milliseconds
|
|
|
*k = *k * 1000.0f;
|
|
*k = *k * 1000.0f;
|
|
@@ -469,7 +455,7 @@ void DAESceneEncoder::loadInterpolation(const domSourceRef source, AnimationChan
|
|
|
values.resize(count);
|
|
values.resize(count);
|
|
|
if (count > 0)
|
|
if (count > 0)
|
|
|
{
|
|
{
|
|
|
- for (size_t i = 0; i < count; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < count; ++i)
|
|
|
{
|
|
{
|
|
|
values[i] = AnimationChannel::getInterpolationType(names.get(i));
|
|
values[i] = AnimationChannel::getInterpolationType(names.get(i));
|
|
|
}
|
|
}
|
|
@@ -478,7 +464,7 @@ void DAESceneEncoder::loadInterpolation(const domSourceRef source, AnimationChan
|
|
|
// instead of storing the same type for each key frame.
|
|
// instead of storing the same type for each key frame.
|
|
|
unsigned int firstType = values[0];
|
|
unsigned int firstType = values[0];
|
|
|
bool allEqual = true;
|
|
bool allEqual = true;
|
|
|
- for (size_t i = 1; i < count; i++)
|
|
|
|
|
|
|
+ for (size_t i = 1; i < count; ++i)
|
|
|
{
|
|
{
|
|
|
if (firstType != values[i])
|
|
if (firstType != values[i])
|
|
|
{
|
|
{
|
|
@@ -508,7 +494,7 @@ bool DAESceneEncoder::loadTarget(const domChannelRef& channelRef, AnimationChann
|
|
|
const char* targetId = channelTarget.getTargetId().c_str();
|
|
const char* targetId = channelTarget.getTargetId().c_str();
|
|
|
|
|
|
|
|
// TODO: Do we want to support more than one? If yes then this needs to be fixed.
|
|
// TODO: Do we want to support more than one? If yes then this needs to be fixed.
|
|
|
- for (size_t i = 0; i < channelTarget.getTargetAttributeCount(); i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < channelTarget.getTargetAttributeCount(); ++i)
|
|
|
{
|
|
{
|
|
|
std::string prop;
|
|
std::string prop;
|
|
|
channelTarget.getPropertyName(i, &prop);
|
|
channelTarget.getPropertyName(i, &prop);
|
|
@@ -544,7 +530,7 @@ bool DAESceneEncoder::loadTarget(const domChannelRef& channelRef, AnimationChann
|
|
|
// Convert (ANGLE ANGLE ANGLE) to (X Y Z ANGLE X Y Z ANGLE X Y Z ANGLE)
|
|
// Convert (ANGLE ANGLE ANGLE) to (X Y Z ANGLE X Y Z ANGLE X Y Z ANGLE)
|
|
|
std::vector<float> floats(size * 4);
|
|
std::vector<float> floats(size * 4);
|
|
|
// Duplicate rotation axis. We will replace only the angle that COLLADA is targeting.
|
|
// Duplicate rotation axis. We will replace only the angle that COLLADA is targeting.
|
|
|
- for (size_t j = 0; j < size; j++)
|
|
|
|
|
|
|
+ for (size_t j = 0; j < size; ++j)
|
|
|
{
|
|
{
|
|
|
size_t k = j * 4;
|
|
size_t k = j * 4;
|
|
|
floats[k+0] = x;
|
|
floats[k+0] = x;
|
|
@@ -620,7 +606,7 @@ bool DAESceneEncoder::loadTarget(const domChannelRef& channelRef, AnimationChann
|
|
|
std::vector<float> floats(newSize);
|
|
std::vector<float> floats(newSize);
|
|
|
|
|
|
|
|
size_t matrixCount = keyValues.size() / 16;
|
|
size_t matrixCount = keyValues.size() / 16;
|
|
|
- for (size_t i = 0; i < matrixCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < matrixCount; ++i)
|
|
|
{
|
|
{
|
|
|
size_t j = i * 16;
|
|
size_t j = i * 16;
|
|
|
// COLLADA used row-major but the Matrix class uses column-major
|
|
// COLLADA used row-major but the Matrix class uses column-major
|
|
@@ -678,7 +664,7 @@ void DAESceneEncoder::copyFloats(const domFloat_array* source, std::vector<float
|
|
|
size_t count = (size_t)source->getCount();
|
|
size_t count = (size_t)source->getCount();
|
|
|
t.resize(count);
|
|
t.resize(count);
|
|
|
const domListOfFloats& listOfFloats = source->getValue();
|
|
const domListOfFloats& listOfFloats = source->getValue();
|
|
|
- for (size_t i = 0; i < count; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < count; ++i)
|
|
|
{
|
|
{
|
|
|
t[i] = (float)listOfFloats.get(i);
|
|
t[i] = (float)listOfFloats.get(i);
|
|
|
}
|
|
}
|
|
@@ -691,7 +677,7 @@ void DAESceneEncoder::loadScene(const domVisual_scene* visualScene)
|
|
|
const domNode_Array& nodes = visualScene->getNode_array();
|
|
const domNode_Array& nodes = visualScene->getNode_array();
|
|
|
scene->setId(visualScene->getId());
|
|
scene->setId(visualScene->getId());
|
|
|
size_t childCount = nodes.getCount();
|
|
size_t childCount = nodes.getCount();
|
|
|
- for (size_t i = 0; i < childCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < childCount; ++i)
|
|
|
{
|
|
{
|
|
|
scene->add(loadNode(nodes[i], NULL));
|
|
scene->add(loadNode(nodes[i], NULL));
|
|
|
}
|
|
}
|
|
@@ -713,11 +699,11 @@ Node* DAESceneEncoder::findSceneActiveCameraNode(const domVisual_scene* visualSc
|
|
|
// Find the active camera
|
|
// Find the active camera
|
|
|
const domVisual_scene::domEvaluate_scene_Array& evaluateScenes = visualScene->getEvaluate_scene_array();
|
|
const domVisual_scene::domEvaluate_scene_Array& evaluateScenes = visualScene->getEvaluate_scene_array();
|
|
|
size_t evaluateSceneCount = evaluateScenes.getCount();
|
|
size_t evaluateSceneCount = evaluateScenes.getCount();
|
|
|
- for (size_t i = 0; i < evaluateSceneCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < evaluateSceneCount; ++i)
|
|
|
{
|
|
{
|
|
|
const domVisual_scene::domEvaluate_scene::domRender_Array& renders = evaluateScenes[i]->getRender_array();
|
|
const domVisual_scene::domEvaluate_scene::domRender_Array& renders = evaluateScenes[i]->getRender_array();
|
|
|
size_t renderCount = renders.getCount();
|
|
size_t renderCount = renders.getCount();
|
|
|
- for (size_t j = 0; j < renderCount; j++)
|
|
|
|
|
|
|
+ for (size_t j = 0; j < renderCount; ++j)
|
|
|
{
|
|
{
|
|
|
xsAnyURI cameraNodeURI = renders[i]->getCamera_node();
|
|
xsAnyURI cameraNodeURI = renders[i]->getCamera_node();
|
|
|
domNode* nodeRef = daeSafeCast<domNode>(cameraNodeURI.getElement());
|
|
domNode* nodeRef = daeSafeCast<domNode>(cameraNodeURI.getElement());
|
|
@@ -779,7 +765,7 @@ Node* DAESceneEncoder::loadNode(domNode* n, Node* parent)
|
|
|
// Load child nodes
|
|
// Load child nodes
|
|
|
const domNode_Array& childNodes = n->getNode_array();
|
|
const domNode_Array& childNodes = n->getNode_array();
|
|
|
size_t childCount = childNodes.getCount();
|
|
size_t childCount = childNodes.getCount();
|
|
|
- for (size_t i = 0; i < childCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < childCount; ++i)
|
|
|
{
|
|
{
|
|
|
loadNode(childNodes.get(i), node);
|
|
loadNode(childNodes.get(i), node);
|
|
|
}
|
|
}
|
|
@@ -830,7 +816,7 @@ void DAESceneEncoder::calcTransform(domNode* domNode, Matrix& dstTransform)
|
|
|
daeTArray<daeSmartRef<daeElement> > children;
|
|
daeTArray<daeSmartRef<daeElement> > children;
|
|
|
domNode->getChildren(children);
|
|
domNode->getChildren(children);
|
|
|
size_t childCount = children.getCount();
|
|
size_t childCount = children.getCount();
|
|
|
- for (size_t i = 0; i < childCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < childCount; ++i)
|
|
|
{
|
|
{
|
|
|
daeElementRef childElement = children[i];
|
|
daeElementRef childElement = children[i];
|
|
|
switch (childElement->getElementType())
|
|
switch (childElement->getElementType())
|
|
@@ -895,7 +881,7 @@ void DAESceneEncoder::loadCameraInstance(const domNode* n, Node* node)
|
|
|
// Does this node have any camera instances?
|
|
// Does this node have any camera instances?
|
|
|
const domInstance_camera_Array& instanceCameras = n->getInstance_camera_array();
|
|
const domInstance_camera_Array& instanceCameras = n->getInstance_camera_array();
|
|
|
size_t instanceCameraCount = instanceCameras.getCount();
|
|
size_t instanceCameraCount = instanceCameras.getCount();
|
|
|
- for (size_t i = 0; i < instanceCameraCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < instanceCameraCount; ++i)
|
|
|
{
|
|
{
|
|
|
// Get the camrea object
|
|
// Get the camrea object
|
|
|
const domInstance_camera* cameraInstanceRef = instanceCameras.get(i);
|
|
const domInstance_camera* cameraInstanceRef = instanceCameras.get(i);
|
|
@@ -904,10 +890,10 @@ void DAESceneEncoder::loadCameraInstance(const domNode* n, Node* node)
|
|
|
|
|
|
|
|
if (cameraRef)
|
|
if (cameraRef)
|
|
|
{
|
|
{
|
|
|
- CameraInstance* cameraInstance = loadCamera(cameraRef);
|
|
|
|
|
- if (cameraInstance)
|
|
|
|
|
|
|
+ Camera* camera = loadCamera(cameraRef);
|
|
|
|
|
+ if (camera)
|
|
|
{
|
|
{
|
|
|
- node->setCameraInstance(cameraInstance);
|
|
|
|
|
|
|
+ node->setCamera(camera);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -922,7 +908,7 @@ void DAESceneEncoder::loadLightInstance(const domNode* n, Node* node)
|
|
|
// Does this node have any light instances?
|
|
// Does this node have any light instances?
|
|
|
const domInstance_light_Array& instanceLights = n->getInstance_light_array();
|
|
const domInstance_light_Array& instanceLights = n->getInstance_light_array();
|
|
|
size_t instanceLightCount = instanceLights.getCount();
|
|
size_t instanceLightCount = instanceLights.getCount();
|
|
|
- for (size_t i = 0; i < instanceLightCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < instanceLightCount; ++i)
|
|
|
{
|
|
{
|
|
|
// Get the camrea object
|
|
// Get the camrea object
|
|
|
const domInstance_light* lightInstanceRef = instanceLights.get(i);
|
|
const domInstance_light* lightInstanceRef = instanceLights.get(i);
|
|
@@ -931,10 +917,10 @@ void DAESceneEncoder::loadLightInstance(const domNode* n, Node* node)
|
|
|
|
|
|
|
|
if (lightRef)
|
|
if (lightRef)
|
|
|
{
|
|
{
|
|
|
- LightInstance* lightInstance = loadLight(lightRef);
|
|
|
|
|
- if (lightInstance)
|
|
|
|
|
|
|
+ Light* light = loadLight(lightRef);
|
|
|
|
|
+ if (light)
|
|
|
{
|
|
{
|
|
|
- node->setLightInstance(lightInstance);
|
|
|
|
|
|
|
+ node->setLight(light);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -949,7 +935,7 @@ void DAESceneEncoder::loadGeometryInstance(const domNode* n, Node* node)
|
|
|
// Does this node have any geometry instances?
|
|
// Does this node have any geometry instances?
|
|
|
const domInstance_geometry_Array& instanceGeometries = n->getInstance_geometry_array();
|
|
const domInstance_geometry_Array& instanceGeometries = n->getInstance_geometry_array();
|
|
|
size_t instanceGeometryCount = instanceGeometries.getCount();
|
|
size_t instanceGeometryCount = instanceGeometries.getCount();
|
|
|
- for (size_t i = 0; i < instanceGeometryCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < instanceGeometryCount; ++i)
|
|
|
{
|
|
{
|
|
|
// Get the geometry object
|
|
// Get the geometry object
|
|
|
const domInstance_geometryRef geometryInstanceRef = instanceGeometries.get(i);
|
|
const domInstance_geometryRef geometryInstanceRef = instanceGeometries.get(i);
|
|
@@ -977,7 +963,7 @@ void DAESceneEncoder::loadControllerInstance(const domNode* n, Node* node)
|
|
|
// Does this node have any controller instances?
|
|
// Does this node have any controller instances?
|
|
|
const domInstance_controller_Array& instanceControllers = n->getInstance_controller_array();
|
|
const domInstance_controller_Array& instanceControllers = n->getInstance_controller_array();
|
|
|
size_t instanceControllerCount = instanceControllers.getCount();
|
|
size_t instanceControllerCount = instanceControllers.getCount();
|
|
|
- for (size_t i = 0; i < instanceControllerCount; i++)
|
|
|
|
|
|
|
+ for (size_t i = 0; i < instanceControllerCount; ++i)
|
|
|
{
|
|
{
|
|
|
const domInstance_controllerRef instanceControllerRef = instanceControllers.get(i);
|
|
const domInstance_controllerRef instanceControllerRef = instanceControllers.get(i);
|
|
|
xsAnyURI controllerURI = instanceControllerRef->getUrl();
|
|
xsAnyURI controllerURI = instanceControllerRef->getUrl();
|
|
@@ -1016,202 +1002,181 @@ void DAESceneEncoder::loadControllerInstance(const domNode* n, Node* node)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-CameraInstance* DAESceneEncoder::loadCamera(const domCamera* cameraRef)
|
|
|
|
|
|
|
+Camera* DAESceneEncoder::loadCamera(const domCamera* cameraRef)
|
|
|
{
|
|
{
|
|
|
- ///////////////////////////// CAMERA
|
|
|
|
|
|
|
+ Camera* camera = new Camera();
|
|
|
|
|
+ camera->setId(cameraRef->getId());
|
|
|
|
|
|
|
|
- // check if camera is already added to gamePlayFile
|
|
|
|
|
- const char* id = cameraRef->getId();
|
|
|
|
|
- Camera* camera = _gamePlayFile.getCamera(id);
|
|
|
|
|
- if (camera == NULL)
|
|
|
|
|
|
|
+ // Optics
|
|
|
|
|
+ const domCamera::domOpticsRef opticsRef = cameraRef->getOptics();
|
|
|
|
|
+ if (opticsRef.cast())
|
|
|
{
|
|
{
|
|
|
- camera = new Camera();
|
|
|
|
|
- camera->setId(id);
|
|
|
|
|
|
|
+ const domCamera::domOptics::domTechnique_commonRef techRef = opticsRef->getTechnique_common();
|
|
|
|
|
|
|
|
- // Optics
|
|
|
|
|
- const domCamera::domOpticsRef opticsRef = cameraRef->getOptics();
|
|
|
|
|
- if (opticsRef.cast())
|
|
|
|
|
|
|
+ // Orthographics
|
|
|
|
|
+ const domCamera::domOptics::domTechnique_common::domOrthographicRef orthographicRef = techRef->getOrthographic();
|
|
|
|
|
+ if (orthographicRef.cast())
|
|
|
{
|
|
{
|
|
|
- const domCamera::domOptics::domTechnique_commonRef techRef = opticsRef->getTechnique_common();
|
|
|
|
|
-
|
|
|
|
|
- // Orthographics
|
|
|
|
|
- const domCamera::domOptics::domTechnique_common::domOrthographicRef orthographicRef = techRef->getOrthographic();
|
|
|
|
|
- if (orthographicRef.cast())
|
|
|
|
|
|
|
+ camera->setOrthographic();
|
|
|
|
|
+ camera->setAspectRatio((float)orthographicRef->getAspect_ratio()->getValue());
|
|
|
|
|
+ camera->setNearPlane((float)orthographicRef->getZnear()->getValue());
|
|
|
|
|
+ camera->setFarPlane((float)orthographicRef->getZfar()->getValue());
|
|
|
|
|
+
|
|
|
|
|
+ const domTargetableFloatRef xmag = orthographicRef->getXmag();
|
|
|
|
|
+ const domTargetableFloatRef ymag = orthographicRef->getYmag();
|
|
|
|
|
+ // Viewport width
|
|
|
|
|
+ if (xmag.cast())
|
|
|
{
|
|
{
|
|
|
- camera->setOrthographic();
|
|
|
|
|
- camera->setNearPlane((float)orthographicRef->getZnear()->getValue());
|
|
|
|
|
- camera->setFarPlane((float)orthographicRef->getZfar()->getValue());
|
|
|
|
|
-
|
|
|
|
|
- const domTargetableFloatRef xmag = orthographicRef->getXmag();
|
|
|
|
|
- const domTargetableFloatRef ymag = orthographicRef->getYmag();
|
|
|
|
|
- // Viewport width
|
|
|
|
|
- if (xmag.cast())
|
|
|
|
|
- {
|
|
|
|
|
- camera->setViewportWidth((float)xmag->getValue());
|
|
|
|
|
- }
|
|
|
|
|
- // Viewport height
|
|
|
|
|
- if (ymag.cast())
|
|
|
|
|
- {
|
|
|
|
|
- camera->setViewportHeight((float)ymag->getValue());
|
|
|
|
|
- }
|
|
|
|
|
- // TODO: Viewport x and y?
|
|
|
|
|
|
|
+ camera->setViewportWidth((float)xmag->getValue());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Perspective
|
|
|
|
|
- const domCamera::domOptics::domTechnique_common::domPerspectiveRef perspectiveRef = techRef->getPerspective();
|
|
|
|
|
- if (perspectiveRef.cast())
|
|
|
|
|
|
|
+ // Viewport height
|
|
|
|
|
+ if (ymag.cast())
|
|
|
{
|
|
{
|
|
|
- camera->setPerspective();
|
|
|
|
|
- camera->setNearPlane((float)perspectiveRef->getZnear()->getValue());
|
|
|
|
|
- camera->setFarPlane((float)perspectiveRef->getZfar()->getValue());
|
|
|
|
|
|
|
+ camera->setViewportHeight((float)ymag->getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ // TODO: Viewport x and y?
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- float aspectRatio = -1.0f;
|
|
|
|
|
- if (perspectiveRef->getAspect_ratio().cast())
|
|
|
|
|
- {
|
|
|
|
|
- aspectRatio = (float)perspectiveRef->getAspect_ratio()->getValue();
|
|
|
|
|
- camera->setAspectRatio(aspectRatio);
|
|
|
|
|
- }
|
|
|
|
|
- if (perspectiveRef->getYfov().cast())
|
|
|
|
|
- {
|
|
|
|
|
- camera->setFieldOfView((float)perspectiveRef->getYfov()->getValue());
|
|
|
|
|
- }
|
|
|
|
|
- else if (perspectiveRef->getXfov().cast() && aspectRatio > 0.0f)
|
|
|
|
|
- {
|
|
|
|
|
- // The gameplaybinary stores the yfov but collada might have specified
|
|
|
|
|
- // an xfov and an aspect ratio. So use those to calculate the yfov.
|
|
|
|
|
- float xfov = (float)perspectiveRef->getXfov()->getValue();
|
|
|
|
|
- float yfov = xfov / aspectRatio;
|
|
|
|
|
- camera->setFieldOfView(yfov);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Perspective
|
|
|
|
|
+ const domCamera::domOptics::domTechnique_common::domPerspectiveRef perspectiveRef = techRef->getPerspective();
|
|
|
|
|
+ if (perspectiveRef.cast())
|
|
|
|
|
+ {
|
|
|
|
|
+ camera->setPerspective();
|
|
|
|
|
+ camera->setNearPlane((float)perspectiveRef->getZnear()->getValue());
|
|
|
|
|
+ camera->setFarPlane((float)perspectiveRef->getZfar()->getValue());
|
|
|
|
|
+
|
|
|
|
|
+ float aspectRatio = -1.0f;
|
|
|
|
|
+ if (perspectiveRef->getAspect_ratio().cast())
|
|
|
|
|
+ {
|
|
|
|
|
+ aspectRatio = (float)perspectiveRef->getAspect_ratio()->getValue();
|
|
|
|
|
+ camera->setAspectRatio(aspectRatio);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (perspectiveRef->getYfov().cast())
|
|
|
|
|
+ {
|
|
|
|
|
+ camera->setFieldOfView((float)perspectiveRef->getYfov()->getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (perspectiveRef->getXfov().cast() && aspectRatio > 0.0f)
|
|
|
|
|
+ {
|
|
|
|
|
+ // The gameplaybinary stores the yfov but collada might have specified
|
|
|
|
|
+ // an xfov and an aspect ratio. So use those to calculate the yfov.
|
|
|
|
|
+ float xfov = (float)perspectiveRef->getXfov()->getValue();
|
|
|
|
|
+ float yfov = xfov / aspectRatio;
|
|
|
|
|
+ camera->setFieldOfView(yfov);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- _gamePlayFile.addCamera(camera);
|
|
|
|
|
}
|
|
}
|
|
|
- CameraInstance* cameraInstance = new CameraInstance();
|
|
|
|
|
- cameraInstance->setCamera(camera);
|
|
|
|
|
- return cameraInstance;
|
|
|
|
|
|
|
+ _gamePlayFile.addCamera(camera);
|
|
|
|
|
+ return camera;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-LightInstance* DAESceneEncoder::loadLight(const domLight* lightRef)
|
|
|
|
|
|
|
+Light* DAESceneEncoder::loadLight(const domLight* lightRef)
|
|
|
{
|
|
{
|
|
|
- ///////////////////////////// LIGHT
|
|
|
|
|
-
|
|
|
|
|
- // check if light is already added to gamePlayFile
|
|
|
|
|
- const char* id = lightRef->getId();
|
|
|
|
|
- Light* light = _gamePlayFile.getLight(id);
|
|
|
|
|
- if (light == NULL)
|
|
|
|
|
- {
|
|
|
|
|
- light = new Light();
|
|
|
|
|
- light->setId(lightRef->getId());
|
|
|
|
|
|
|
+ Light* light = new Light();
|
|
|
|
|
+ light->setId(lightRef->getId());
|
|
|
|
|
|
|
|
- const domLight::domTechnique_commonRef techRef = lightRef->getTechnique_common();
|
|
|
|
|
|
|
+ const domLight::domTechnique_commonRef techRef = lightRef->getTechnique_common();
|
|
|
|
|
|
|
|
- // Ambient light
|
|
|
|
|
|
|
+ // Ambient light
|
|
|
|
|
+ {
|
|
|
|
|
+ const domLight::domTechnique_common::domAmbientRef ambientRef = techRef->getAmbient();
|
|
|
|
|
+ if (ambientRef.cast())
|
|
|
{
|
|
{
|
|
|
- const domLight::domTechnique_common::domAmbientRef ambientRef = techRef->getAmbient();
|
|
|
|
|
- if (ambientRef.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setAmbientLight();
|
|
|
|
|
- // color
|
|
|
|
|
- const domTargetableFloat3Ref float3Ref = ambientRef->getColor();
|
|
|
|
|
- const domFloat3& color3 = float3Ref->getValue();
|
|
|
|
|
- light->setColor((float)color3.get(0), (float)color3.get(1), (float)color3.get(2));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ light->setAmbientLight();
|
|
|
|
|
+ // color
|
|
|
|
|
+ const domTargetableFloat3Ref float3Ref = ambientRef->getColor();
|
|
|
|
|
+ const domFloat3& color3 = float3Ref->getValue();
|
|
|
|
|
+ light->setColor((float)color3.get(0), (float)color3.get(1), (float)color3.get(2));
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Directional light
|
|
|
|
|
|
|
+ // Directional light
|
|
|
|
|
+ {
|
|
|
|
|
+ const domLight::domTechnique_common::domDirectionalRef direcitonalRef = techRef->getDirectional();
|
|
|
|
|
+ if (direcitonalRef.cast())
|
|
|
{
|
|
{
|
|
|
- const domLight::domTechnique_common::domDirectionalRef direcitonalRef = techRef->getDirectional();
|
|
|
|
|
- if (direcitonalRef.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setDirectionalLight();
|
|
|
|
|
- // color
|
|
|
|
|
- const domTargetableFloat3Ref float3Ref = direcitonalRef->getColor();
|
|
|
|
|
- const domFloat3& color3 = float3Ref->getValue();
|
|
|
|
|
- light->setColor((float)color3.get(0), (float)color3.get(1), (float)color3.get(2));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ light->setDirectionalLight();
|
|
|
|
|
+ // color
|
|
|
|
|
+ const domTargetableFloat3Ref float3Ref = direcitonalRef->getColor();
|
|
|
|
|
+ const domFloat3& color3 = float3Ref->getValue();
|
|
|
|
|
+ light->setColor((float)color3.get(0), (float)color3.get(1), (float)color3.get(2));
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Spot light
|
|
|
|
|
|
|
+ // Spot light
|
|
|
|
|
+ {
|
|
|
|
|
+ const domLight::domTechnique_common::domSpotRef spotRef = techRef->getSpot();
|
|
|
|
|
+ if (spotRef.cast())
|
|
|
{
|
|
{
|
|
|
- const domLight::domTechnique_common::domSpotRef spotRef = techRef->getSpot();
|
|
|
|
|
- if (spotRef.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setSpotLight();
|
|
|
|
|
- // color
|
|
|
|
|
- const domTargetableFloat3Ref float3Ref = spotRef->getColor();
|
|
|
|
|
- const domFloat3& color3 = float3Ref->getValue();
|
|
|
|
|
- light->setColor((float)color3.get(0), (float)color3.get(1), (float)color3.get(2));
|
|
|
|
|
|
|
+ light->setSpotLight();
|
|
|
|
|
+ // color
|
|
|
|
|
+ const domTargetableFloat3Ref float3Ref = spotRef->getColor();
|
|
|
|
|
+ const domFloat3& color3 = float3Ref->getValue();
|
|
|
|
|
+ light->setColor((float)color3.get(0), (float)color3.get(1), (float)color3.get(2));
|
|
|
|
|
|
|
|
- const domTargetableFloatRef& constAtt = spotRef->getConstant_attenuation();
|
|
|
|
|
- if (constAtt.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setConstantAttenuation((float)constAtt->getValue());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const domTargetableFloatRef& linearAtt = spotRef->getLinear_attenuation();
|
|
|
|
|
- if (linearAtt.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setLinearAttenuation((float)linearAtt->getValue());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const domTargetableFloatRef& constAtt = spotRef->getConstant_attenuation();
|
|
|
|
|
+ if (constAtt.cast())
|
|
|
|
|
+ {
|
|
|
|
|
+ light->setConstantAttenuation((float)constAtt->getValue());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- const domTargetableFloatRef& quadAtt = spotRef->getQuadratic_attenuation();
|
|
|
|
|
- if (quadAtt.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setQuadraticAttenuation((float)quadAtt->getValue());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const domTargetableFloatRef& linearAtt = spotRef->getLinear_attenuation();
|
|
|
|
|
+ if (linearAtt.cast())
|
|
|
|
|
+ {
|
|
|
|
|
+ light->setLinearAttenuation((float)linearAtt->getValue());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- const domTargetableFloatRef& falloffAngle = spotRef->getFalloff_angle();
|
|
|
|
|
- if (falloffAngle.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setFalloffAngle((float)falloffAngle->getValue());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const domTargetableFloatRef& quadAtt = spotRef->getQuadratic_attenuation();
|
|
|
|
|
+ if (quadAtt.cast())
|
|
|
|
|
+ {
|
|
|
|
|
+ light->setQuadraticAttenuation((float)quadAtt->getValue());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- const domTargetableFloatRef& falloffExp = spotRef->getFalloff_exponent();
|
|
|
|
|
- if (falloffExp.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setFalloffExponent((float)falloffExp->getValue());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const domTargetableFloatRef& falloffAngle = spotRef->getFalloff_angle();
|
|
|
|
|
+ if (falloffAngle.cast())
|
|
|
|
|
+ {
|
|
|
|
|
+ light->setFalloffAngle((float)falloffAngle->getValue());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ const domTargetableFloatRef& falloffExp = spotRef->getFalloff_exponent();
|
|
|
|
|
+ if (falloffExp.cast())
|
|
|
|
|
+ {
|
|
|
|
|
+ light->setFalloffExponent((float)falloffExp->getValue());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Point light
|
|
|
|
|
|
|
+ // Point light
|
|
|
|
|
+ {
|
|
|
|
|
+ const domLight::domTechnique_common::domPointRef pointRef = techRef->getPoint();
|
|
|
|
|
+ if (pointRef.cast())
|
|
|
{
|
|
{
|
|
|
- const domLight::domTechnique_common::domPointRef pointRef = techRef->getPoint();
|
|
|
|
|
- if (pointRef.cast())
|
|
|
|
|
|
|
+ light->setPointLight();
|
|
|
|
|
+ // color
|
|
|
|
|
+ const domTargetableFloat3Ref float3Ref = pointRef->getColor();
|
|
|
|
|
+ const domFloat3& color3 = float3Ref->getValue();
|
|
|
|
|
+ light->setColor((float)color3.get(0), (float)color3.get(1), (float)color3.get(2));
|
|
|
|
|
+
|
|
|
|
|
+ const domTargetableFloatRef& constAtt = pointRef->getConstant_attenuation();
|
|
|
|
|
+ if (constAtt.cast())
|
|
|
{
|
|
{
|
|
|
- light->setPointLight();
|
|
|
|
|
- // color
|
|
|
|
|
- const domTargetableFloat3Ref float3Ref = pointRef->getColor();
|
|
|
|
|
- const domFloat3& color3 = float3Ref->getValue();
|
|
|
|
|
- light->setColor((float)color3.get(0), (float)color3.get(1), (float)color3.get(2));
|
|
|
|
|
-
|
|
|
|
|
- const domTargetableFloatRef& constAtt = pointRef->getConstant_attenuation();
|
|
|
|
|
- if (constAtt.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setConstantAttenuation((float)constAtt->getValue());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ light->setConstantAttenuation((float)constAtt->getValue());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- const domTargetableFloatRef& linearAtt = pointRef->getLinear_attenuation();
|
|
|
|
|
- if (linearAtt.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setLinearAttenuation((float)linearAtt->getValue());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const domTargetableFloatRef& linearAtt = pointRef->getLinear_attenuation();
|
|
|
|
|
+ if (linearAtt.cast())
|
|
|
|
|
+ {
|
|
|
|
|
+ light->setLinearAttenuation((float)linearAtt->getValue());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- const domTargetableFloatRef& quadAtt = pointRef->getQuadratic_attenuation();
|
|
|
|
|
- if (quadAtt.cast())
|
|
|
|
|
- {
|
|
|
|
|
- light->setQuadraticAttenuation((float)quadAtt->getValue());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const domTargetableFloatRef& quadAtt = pointRef->getQuadratic_attenuation();
|
|
|
|
|
+ if (quadAtt.cast())
|
|
|
|
|
+ {
|
|
|
|
|
+ light->setQuadraticAttenuation((float)quadAtt->getValue());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- _gamePlayFile.addLight(light);
|
|
|
|
|
}
|
|
}
|
|
|
- LightInstance* lightInstance = new LightInstance();
|
|
|
|
|
- lightInstance->setLight(light);
|
|
|
|
|
- return lightInstance;
|
|
|
|
|
|
|
+ _gamePlayFile.addLight(light);
|
|
|
|
|
+ return light;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void DAESceneEncoder::loadSkeleton(domInstance_controller::domSkeleton* skeletonElement, MeshSkin* skin)
|
|
void DAESceneEncoder::loadSkeleton(domInstance_controller::domSkeleton* skeletonElement, MeshSkin* skin)
|
|
@@ -1300,7 +1265,7 @@ Model* DAESceneEncoder::loadSkin(const domSkin* skinElement)
|
|
|
|
|
|
|
|
// Process "JOINT" input semantic first (we need to do this to set the joint count)
|
|
// Process "JOINT" input semantic first (we need to do this to set the joint count)
|
|
|
unsigned int jointCount = 0;
|
|
unsigned int jointCount = 0;
|
|
|
- for (unsigned int i = 0; i < jointInputs.getCount(); i++)
|
|
|
|
|
|
|
+ for (unsigned int i = 0; i < jointInputs.getCount(); ++i)
|
|
|
{
|
|
{
|
|
|
domInputLocalRef input = jointInputs.get(i);
|
|
domInputLocalRef input = jointInputs.get(i);
|
|
|
std::string inputSemantic = std::string(input->getSemantic());
|
|
std::string inputSemantic = std::string(input->getSemantic());
|
|
@@ -1351,7 +1316,7 @@ Model* DAESceneEncoder::loadSkin(const domSkin* skinElement)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Process "INV_BIND_MATRIX" next
|
|
// Process "INV_BIND_MATRIX" next
|
|
|
- for (unsigned int i = 0; i < jointInputs.getCount(); i++)
|
|
|
|
|
|
|
+ for (unsigned int i = 0; i < jointInputs.getCount(); ++i)
|
|
|
{
|
|
{
|
|
|
domInputLocalRef input = jointInputs.get(i);
|
|
domInputLocalRef input = jointInputs.get(i);
|
|
|
std::string inputSemantic = std::string(input->getSemantic());
|
|
std::string inputSemantic = std::string(input->getSemantic());
|
|
@@ -1365,7 +1330,7 @@ Model* DAESceneEncoder::loadSkin(const domSkin* skinElement)
|
|
|
//unsigned int matrixFloatsCount = (unsigned int)source->getFloat_array()->getCount();
|
|
//unsigned int matrixFloatsCount = (unsigned int)source->getFloat_array()->getCount();
|
|
|
unsigned int jointIndex = 0;
|
|
unsigned int jointIndex = 0;
|
|
|
|
|
|
|
|
- for (unsigned int j = 0; j < jointCount; j++)
|
|
|
|
|
|
|
+ for (unsigned int j = 0; j < jointCount; ++j)
|
|
|
{
|
|
{
|
|
|
Matrix matrix((float)matrixFloats.get(jointIndex + 0), (float)matrixFloats.get(jointIndex + 4), (float)matrixFloats.get(jointIndex + 8), (float)matrixFloats.get(jointIndex + 12),
|
|
Matrix matrix((float)matrixFloats.get(jointIndex + 0), (float)matrixFloats.get(jointIndex + 4), (float)matrixFloats.get(jointIndex + 8), (float)matrixFloats.get(jointIndex + 12),
|
|
|
(float)matrixFloats.get(jointIndex + 1), (float)matrixFloats.get(jointIndex + 5), (float)matrixFloats.get(jointIndex + 9), (float)matrixFloats.get(jointIndex + 13),
|
|
(float)matrixFloats.get(jointIndex + 1), (float)matrixFloats.get(jointIndex + 5), (float)matrixFloats.get(jointIndex + 9), (float)matrixFloats.get(jointIndex + 13),
|
|
@@ -1386,7 +1351,7 @@ Model* DAESceneEncoder::loadSkin(const domSkin* skinElement)
|
|
|
unsigned int vertexWeightsCount = (unsigned int)vertexWeights->getCount();
|
|
unsigned int vertexWeightsCount = (unsigned int)vertexWeights->getCount();
|
|
|
domListOfFloats jointWeights;
|
|
domListOfFloats jointWeights;
|
|
|
|
|
|
|
|
- for (unsigned int i = 0; i < jointInputs.getCount(); i++)
|
|
|
|
|
|
|
+ for (unsigned int i = 0; i < jointInputs.getCount(); ++i)
|
|
|
{
|
|
{
|
|
|
domInputLocalOffsetRef input = vertexWeightsInputs.get(i);
|
|
domInputLocalOffsetRef input = vertexWeightsInputs.get(i);
|
|
|
std::string inputSemantic = std::string(input->getSemantic());
|
|
std::string inputSemantic = std::string(input->getSemantic());
|
|
@@ -1432,7 +1397,7 @@ Model* DAESceneEncoder::loadSkin(const domSkin* skinElement)
|
|
|
int weightOffset = 0;
|
|
int weightOffset = 0;
|
|
|
|
|
|
|
|
// Go through all the skin vertex influence weights from the indexed data.
|
|
// Go through all the skin vertex influence weights from the indexed data.
|
|
|
- for (int i = 0; i < skinVertexInfluenceCountTotal; i++)
|
|
|
|
|
|
|
+ for (int i = 0; i < skinVertexInfluenceCountTotal; ++i)
|
|
|
{
|
|
{
|
|
|
// Get the influence count and directly get the vertext blend weights and indices.
|
|
// Get the influence count and directly get the vertext blend weights and indices.
|
|
|
unsigned int vertexInfluenceCount = (unsigned int)skinVertexInfluenceCounts.get(i);
|
|
unsigned int vertexInfluenceCount = (unsigned int)skinVertexInfluenceCounts.get(i);
|
|
@@ -1441,7 +1406,7 @@ Model* DAESceneEncoder::loadSkin(const domSkin* skinElement)
|
|
|
//vertexInfluences.SetCapacity(vertexInfluenceCount);
|
|
//vertexInfluences.SetCapacity(vertexInfluenceCount);
|
|
|
|
|
|
|
|
// Get the index/weight pairs and some the weight totals while at it.
|
|
// Get the index/weight pairs and some the weight totals while at it.
|
|
|
- for (unsigned int j = 0; j < vertexInfluenceCount; j++)
|
|
|
|
|
|
|
+ for (unsigned int j = 0; j < vertexInfluenceCount; ++j)
|
|
|
{
|
|
{
|
|
|
float weight = (float)jointWeights.get((unsigned int)skinVertexJointWeightPairIndices[vOffset + 1]);
|
|
float weight = (float)jointWeights.get((unsigned int)skinVertexJointWeightPairIndices[vOffset + 1]);
|
|
|
int index = (int)skinVertexJointWeightPairIndices[vOffset];
|
|
int index = (int)skinVertexJointWeightPairIndices[vOffset];
|
|
@@ -1461,7 +1426,7 @@ Model* DAESceneEncoder::loadSkin(const domSkin* skinElement)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Get up the the maximum vertex weight influence count.
|
|
// Get up the the maximum vertex weight influence count.
|
|
|
- for (unsigned int j = 0; j < maxVertexInfluencesCount; j++)
|
|
|
|
|
|
|
+ for (unsigned int j = 0; j < maxVertexInfluencesCount; ++j)
|
|
|
{
|
|
{
|
|
|
if (j < vertexInfluenceCount)
|
|
if (j < vertexInfluenceCount)
|
|
|
{
|
|
{
|
|
@@ -1569,7 +1534,7 @@ Mesh* DAESceneEncoder::loadMesh(const domMesh* meshElement, const std::string& g
|
|
|
unsigned int inputCount = (unsigned int)-1;
|
|
unsigned int inputCount = (unsigned int)-1;
|
|
|
|
|
|
|
|
// Loop through our set of triangle lists (each list of triangles corresponds to a single MeshPart)
|
|
// Loop through our set of triangle lists (each list of triangles corresponds to a single MeshPart)
|
|
|
- for (unsigned int i = 0; i < trianglesArrayCount; i++)
|
|
|
|
|
|
|
+ for (unsigned int i = 0; i < trianglesArrayCount; ++i)
|
|
|
{
|
|
{
|
|
|
const domTrianglesRef& triangles = trianglesArray.get(i);
|
|
const domTrianglesRef& triangles = trianglesArray.get(i);
|
|
|
const domInputLocalOffset_Array& inputArray = triangles->getInput_array();
|
|
const domInputLocalOffset_Array& inputArray = triangles->getInput_array();
|
|
@@ -1579,7 +1544,8 @@ Mesh* DAESceneEncoder::loadMesh(const domMesh* meshElement, const std::string& g
|
|
|
{
|
|
{
|
|
|
inputCount = (unsigned int)inputArray.getCount();
|
|
inputCount = (unsigned int)inputArray.getCount();
|
|
|
|
|
|
|
|
- for (unsigned int j = 0; j < inputCount; j++)
|
|
|
|
|
|
|
+ int texCoordCount = 0;
|
|
|
|
|
+ for (unsigned int j = 0; j < inputCount; ++j)
|
|
|
{
|
|
{
|
|
|
const domInputLocalOffsetRef& input = inputArray.get(j);
|
|
const domInputLocalOffsetRef& input = inputArray.get(j);
|
|
|
std::string inputSemantic = input->getSemantic();
|
|
std::string inputSemantic = input->getSemantic();
|
|
@@ -1588,7 +1554,7 @@ Mesh* DAESceneEncoder::loadMesh(const domMesh* meshElement, const std::string& g
|
|
|
if (equals(inputSemantic, "VERTEX"))
|
|
if (equals(inputSemantic, "VERTEX"))
|
|
|
{
|
|
{
|
|
|
unsigned int vertexArrayCount = (unsigned int)vertexArray.getCount();
|
|
unsigned int vertexArrayCount = (unsigned int)vertexArray.getCount();
|
|
|
- for (unsigned int k = 0; k < vertexArrayCount; k++)
|
|
|
|
|
|
|
+ for (unsigned int k = 0; k < vertexArrayCount; ++k)
|
|
|
{
|
|
{
|
|
|
const domInputLocalRef& vertexInput = vertexArray.get(k);
|
|
const domInputLocalRef& vertexInput = vertexArray.get(k);
|
|
|
|
|
|
|
@@ -1616,6 +1582,14 @@ Mesh* DAESceneEncoder::loadMesh(const domMesh* meshElement, const std::string& g
|
|
|
if (type == -1)
|
|
if (type == -1)
|
|
|
{
|
|
{
|
|
|
warning(std::string("Semantic (") + semantic + ") is invalid/unsupported for geometry mesh: " + geometryId);
|
|
warning(std::string("Semantic (") + semantic + ") is invalid/unsupported for geometry mesh: " + geometryId);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (type == TEXCOORD0)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Some meshes have multiple texture coordinates
|
|
|
|
|
+ assert(texCoordCount <= 7);
|
|
|
|
|
+ type += texCoordCount;
|
|
|
|
|
+ ++texCoordCount;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
DAEPolygonInput* polygonInput = new DAEPolygonInput();
|
|
DAEPolygonInput* polygonInput = new DAEPolygonInput();
|
|
@@ -1643,7 +1617,7 @@ Mesh* DAESceneEncoder::loadMesh(const domMesh* meshElement, const std::string& g
|
|
|
// If there is a triangle array with a different number of inputs, this is not supported.
|
|
// If there is a triangle array with a different number of inputs, this is not supported.
|
|
|
if (inputCount != (unsigned int)inputArray.getCount())
|
|
if (inputCount != (unsigned int)inputArray.getCount())
|
|
|
{
|
|
{
|
|
|
- for (size_t j = 0; j < polygonInputs.size(); j++)
|
|
|
|
|
|
|
+ for (size_t j = 0; j < polygonInputs.size(); ++j)
|
|
|
{
|
|
{
|
|
|
delete polygonInputs[j];
|
|
delete polygonInputs[j];
|
|
|
}
|
|
}
|
|
@@ -1659,7 +1633,7 @@ Mesh* DAESceneEncoder::loadMesh(const domMesh* meshElement, const std::string& g
|
|
|
|
|
|
|
|
// Now we have validated that all input in all triangles are the same and in the same input layout.
|
|
// Now we have validated that all input in all triangles are the same and in the same input layout.
|
|
|
// Lets start to read them and build our subsets.
|
|
// Lets start to read them and build our subsets.
|
|
|
- for (unsigned int i = 0; i < trianglesArrayCount; i++)
|
|
|
|
|
|
|
+ for (unsigned int i = 0; i < trianglesArrayCount; ++i)
|
|
|
{
|
|
{
|
|
|
// Subset to be built.
|
|
// Subset to be built.
|
|
|
MeshPart* subset = new MeshPart();
|
|
MeshPart* subset = new MeshPart();
|
|
@@ -1765,6 +1739,11 @@ Mesh* DAESceneEncoder::loadMesh(const domMesh* meshElement, const std::string& g
|
|
|
vertex.texCoord.y = (float)source.get(polyIndex * 2 + 1);
|
|
vertex.texCoord.y = (float)source.get(polyIndex * 2 + 1);
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
|
|
+
|
|
|
|
|
+ case TEXCOORD1:
|
|
|
|
|
+ // TODO
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|