|
|
|
@ -26,12 +26,13 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include <libs/mangle/vfs/servers/ogre_vfs.hpp>
|
|
|
|
|
#include "components/nif/nif_file.hpp"
|
|
|
|
|
#include "components/nif/node.hpp"
|
|
|
|
|
#include "components/nif/data.hpp"
|
|
|
|
|
#include "components/nif/property.hpp"
|
|
|
|
|
#include "libs/platform/strings.h"
|
|
|
|
|
#include "../nif/nif_file.hpp"
|
|
|
|
|
#include "../nif/node.hpp"
|
|
|
|
|
#include "../nif/data.hpp"
|
|
|
|
|
#include "../nif/property.hpp"
|
|
|
|
|
#include <libs/platform/strings.h>
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
// For warning messages
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
@ -45,21 +46,43 @@ using namespace Ogre;
|
|
|
|
|
using namespace Nif;
|
|
|
|
|
using namespace Mangle::VFS;
|
|
|
|
|
|
|
|
|
|
// This is the interface to the Ogre resource system. It allows us to
|
|
|
|
|
// load NIFs from BSAs, in the file system and in any other place we
|
|
|
|
|
// tell Ogre to look (eg. in zip or rar files.) It's also used to
|
|
|
|
|
// check for the existence of texture files, so we can exchange the
|
|
|
|
|
// extension from .tga to .dds if the texture is missing.
|
|
|
|
|
static OgreVFS *vfs;
|
|
|
|
|
NIFLoader& NIFLoader::getSingleton()
|
|
|
|
|
{
|
|
|
|
|
static NIFLoader instance;
|
|
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Singleton instance used by load()
|
|
|
|
|
static NIFLoader g_sing;
|
|
|
|
|
NIFLoader* NIFLoader::getSingletonPtr()
|
|
|
|
|
{
|
|
|
|
|
return &getSingleton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NIFLoader::warn(string msg)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "NIFLoader: Warn:" << msg << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NIFLoader::fail(string msg)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "NIFLoader: Fail: "<< msg << std::endl;
|
|
|
|
|
assert(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3 NIFLoader::convertVector3(const Nif::Vector& vec)
|
|
|
|
|
{
|
|
|
|
|
return Ogre::Vector3(vec.array);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Makeshift error reporting system
|
|
|
|
|
static string errName;
|
|
|
|
|
static void warn(const string &msg)
|
|
|
|
|
Quaternion NIFLoader::convertRotation(const Nif::Matrix& rot)
|
|
|
|
|
{
|
|
|
|
|
cout << "WARNING (NIF:" << errName << "): " << msg << endl;
|
|
|
|
|
Real matrix[3][3];
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<3; i++)
|
|
|
|
|
for (int j=0; j<3; j++)
|
|
|
|
|
matrix[i][j] = rot.v[i].array[j];
|
|
|
|
|
|
|
|
|
|
return Quaternion(Matrix3(matrix));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helper class that computes the bounding box and of a mesh
|
|
|
|
@ -126,12 +149,24 @@ public:
|
|
|
|
|
return sqrt(X.getMaxSquared() + Y.getMaxSquared() + Z.getMaxSquared());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float minX() { return X.min; }
|
|
|
|
|
float maxX() { return X.max; }
|
|
|
|
|
float minY() { return Y.min; }
|
|
|
|
|
float maxY() { return Y.max; }
|
|
|
|
|
float minZ() { return Z.min; }
|
|
|
|
|
float maxZ() { return Z.max; }
|
|
|
|
|
float minX() {
|
|
|
|
|
return X.min;
|
|
|
|
|
}
|
|
|
|
|
float maxX() {
|
|
|
|
|
return X.max;
|
|
|
|
|
}
|
|
|
|
|
float minY() {
|
|
|
|
|
return Y.min;
|
|
|
|
|
}
|
|
|
|
|
float maxY() {
|
|
|
|
|
return Y.max;
|
|
|
|
|
}
|
|
|
|
|
float minZ() {
|
|
|
|
|
return Z.min;
|
|
|
|
|
}
|
|
|
|
|
float maxZ() {
|
|
|
|
|
return Z.max;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Conversion of blend / test mode from NIF -> OGRE.
|
|
|
|
@ -177,7 +212,7 @@ static CompareFunction getTestMode(int mode)
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void createMaterial(const String &name,
|
|
|
|
|
void NIFLoader::createMaterial(const String &name,
|
|
|
|
|
const Vector &ambient,
|
|
|
|
|
const Vector &diffuse,
|
|
|
|
|
const Vector &specular,
|
|
|
|
@ -186,7 +221,7 @@ static void createMaterial(const String &name,
|
|
|
|
|
float alphaFlags, float alphaTest,
|
|
|
|
|
const String &texName)
|
|
|
|
|
{
|
|
|
|
|
MaterialPtr material = MaterialManager::getSingleton().create(name, "General");
|
|
|
|
|
MaterialPtr material = MaterialManager::getSingleton().create(name, resourceGroup);
|
|
|
|
|
|
|
|
|
|
// This assigns the texture to this material. If the texture name is
|
|
|
|
|
// a file name, and this file exists (in a resource directory), it
|
|
|
|
@ -196,7 +231,8 @@ static void createMaterial(const String &name,
|
|
|
|
|
if (!texName.empty())
|
|
|
|
|
{
|
|
|
|
|
Pass *pass = material->getTechnique(0)->getPass(0);
|
|
|
|
|
/*TextureUnitState *txt =*/ pass->createTextureUnitState(texName);
|
|
|
|
|
/*TextureUnitState *txt =*/
|
|
|
|
|
pass->createTextureUnitState(texName);
|
|
|
|
|
|
|
|
|
|
/* As of yet UNTESTED code from Chris:
|
|
|
|
|
pass->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
|
|
|
|
@ -254,7 +290,7 @@ static void createMaterial(const String &name,
|
|
|
|
|
|
|
|
|
|
// Takes a name and adds a unique part to it. This is just used to
|
|
|
|
|
// make sure that all materials are given unique names.
|
|
|
|
|
static String getUniqueName(const String &input)
|
|
|
|
|
String NIFLoader::getUniqueName(const String &input)
|
|
|
|
|
{
|
|
|
|
|
static int addon = 0;
|
|
|
|
|
static char buf[8];
|
|
|
|
@ -270,7 +306,7 @@ static String getUniqueName(const String &input)
|
|
|
|
|
// does not, change the string IN PLACE to say .dds instead and try
|
|
|
|
|
// that. The texture may still not exist, but no information of value
|
|
|
|
|
// is lost in that case.
|
|
|
|
|
static void findRealTexture(String &texName)
|
|
|
|
|
void NIFLoader::findRealTexture(String &texName)
|
|
|
|
|
{
|
|
|
|
|
assert(vfs);
|
|
|
|
|
if (vfs->isFile(texName)) return;
|
|
|
|
@ -286,7 +322,7 @@ static void findRealTexture(String &texName)
|
|
|
|
|
|
|
|
|
|
// Convert Nif::NiTriShape to Ogre::SubMesh, attached to the given
|
|
|
|
|
// mesh.
|
|
|
|
|
static void createOgreMesh(Mesh *mesh, NiTriShape *shape, const String &material)
|
|
|
|
|
void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material)
|
|
|
|
|
{
|
|
|
|
|
NiTriShapeData *data = shape->data.getPtr();
|
|
|
|
|
SubMesh *sub = mesh->createSubMesh(shape->name.toString());
|
|
|
|
@ -301,13 +337,16 @@ static void createOgreMesh(Mesh *mesh, NiTriShape *shape, const String &material
|
|
|
|
|
sub->vertexData = new VertexData();
|
|
|
|
|
sub->vertexData->vertexCount = numVerts;
|
|
|
|
|
sub->useSharedVertices = false;
|
|
|
|
|
|
|
|
|
|
VertexDeclaration *decl = sub->vertexData->vertexDeclaration;
|
|
|
|
|
decl->addElement(nextBuf, 0, VET_FLOAT3, VES_POSITION);
|
|
|
|
|
|
|
|
|
|
HardwareVertexBufferSharedPtr vbuf =
|
|
|
|
|
HardwareBufferManager::getSingleton().createVertexBuffer(
|
|
|
|
|
VertexElement::getTypeSize(VET_FLOAT3),
|
|
|
|
|
numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
|
|
|
|
|
vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, true);
|
|
|
|
|
|
|
|
|
|
VertexBufferBinding* bind = sub->vertexData->vertexBufferBinding;
|
|
|
|
|
bind->setBinding(nextBuf++, vbuf);
|
|
|
|
|
|
|
|
|
@ -371,22 +410,6 @@ static void createOgreMesh(Mesh *mesh, NiTriShape *shape, const String &material
|
|
|
|
|
|
|
|
|
|
// Set material if one was given
|
|
|
|
|
if (!material.empty()) sub->setMaterialName(material);
|
|
|
|
|
|
|
|
|
|
/* Old commented D code. Might be useful when reimplementing
|
|
|
|
|
animation.
|
|
|
|
|
// Assign this submesh to the given bone
|
|
|
|
|
VertexBoneAssignment v;
|
|
|
|
|
v.boneIndex = ((Bone*)bone)->getHandle();
|
|
|
|
|
v.weight = 1.0;
|
|
|
|
|
|
|
|
|
|
std::cerr << "+ Assigning bone index " << v.boneIndex << "\n";
|
|
|
|
|
|
|
|
|
|
for(int i=0; i < numVerts; i++)
|
|
|
|
|
{
|
|
|
|
|
v.vertexIndex = i;
|
|
|
|
|
sub->addBoneAssignment(v);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helper math functions. Reinventing linear algebra for the win!
|
|
|
|
@ -432,7 +455,7 @@ static void vectorMul(const Matrix &A, float *C)
|
|
|
|
|
C[i] = a*A.v[i].array[0] + b*A.v[i].array[1] + c*A.v[i].array[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags, BoundsFinder &bounds)
|
|
|
|
|
void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bounds)
|
|
|
|
|
{
|
|
|
|
|
assert(shape != NULL);
|
|
|
|
|
|
|
|
|
@ -451,7 +474,10 @@ static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags, BoundsFin
|
|
|
|
|
// If the object was marked "NCO" earlier, it shouldn't collide with
|
|
|
|
|
// anything.
|
|
|
|
|
if (flags & 0x800)
|
|
|
|
|
{ collide = false; bbcollide = false; }
|
|
|
|
|
{
|
|
|
|
|
collide = false;
|
|
|
|
|
bbcollide = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!collide && !bbcollide && hidden)
|
|
|
|
|
// This mesh apparently isn't being used for anything, so don't
|
|
|
|
@ -569,7 +595,80 @@ static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags, BoundsFin
|
|
|
|
|
float *ptr = (float*)data->vertices.ptr;
|
|
|
|
|
float *optr = ptr;
|
|
|
|
|
|
|
|
|
|
// Rotate, scale and translate all the vertices
|
|
|
|
|
//use niskindata for the position of vertices.
|
|
|
|
|
if (!shape->skin.empty())
|
|
|
|
|
{
|
|
|
|
|
// vector that stores if the position if a vertex is absolute
|
|
|
|
|
std::vector<bool> vertexPosAbsolut(numVerts,false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float *ptrNormals = (float*)data->normals.ptr;
|
|
|
|
|
//the bone from skin->bones[boneIndex] is linked to skin->data->bones[boneIndex]
|
|
|
|
|
//the first one contains a link to the bone, the second vertex transformation
|
|
|
|
|
//relative to the bone
|
|
|
|
|
int boneIndex = 0;
|
|
|
|
|
Bone *bonePtr;
|
|
|
|
|
Vector3 vecPos;
|
|
|
|
|
Quaternion vecRot;
|
|
|
|
|
|
|
|
|
|
std::vector<NiSkinData::BoneInfo> boneList = shape->skin->data->bones;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Iterate through the boneList which contains what vertices are linked to
|
|
|
|
|
the bone (it->weights array) and at what position (it->trafo)
|
|
|
|
|
That position is added to every vertex.
|
|
|
|
|
*/
|
|
|
|
|
for (std::vector<NiSkinData::BoneInfo>::iterator it = boneList.begin();
|
|
|
|
|
it != boneList.end(); it++)
|
|
|
|
|
{
|
|
|
|
|
//get the bone from bones array of skindata
|
|
|
|
|
bonePtr = skel->getBone(shape->skin->bones[boneIndex].name.toString());
|
|
|
|
|
|
|
|
|
|
// final_vector = old_vector + old_rotation*new_vector*old_scale
|
|
|
|
|
vecPos = bonePtr->_getDerivedPosition() +
|
|
|
|
|
bonePtr->_getDerivedOrientation() * convertVector3(it->trafo->trans);
|
|
|
|
|
|
|
|
|
|
vecRot = bonePtr->_getDerivedOrientation() * convertRotation(it->trafo->rotation);
|
|
|
|
|
|
|
|
|
|
for (unsigned int i=0; i<it->weights.length; i++)
|
|
|
|
|
{
|
|
|
|
|
unsigned int verIndex = (it->weights.ptr + i)->vertex;
|
|
|
|
|
|
|
|
|
|
//Check if the vertex is relativ, FIXME: Is there a better solution?
|
|
|
|
|
if (vertexPosAbsolut[verIndex] == false)
|
|
|
|
|
{
|
|
|
|
|
//apply transformation to the vertices
|
|
|
|
|
Vector3 absVertPos = vecPos + vecRot * Vector3(ptr + verIndex *3);
|
|
|
|
|
|
|
|
|
|
//convert it back to float *
|
|
|
|
|
for (int j=0; j<3; j++)
|
|
|
|
|
(ptr + verIndex*3)[j] = absVertPos[j];
|
|
|
|
|
|
|
|
|
|
//apply rotation to the normals (not every vertex has a normal)
|
|
|
|
|
//FIXME: I guessed that vertex[i] = normal[i], is that true?
|
|
|
|
|
if (verIndex < data->normals.length)
|
|
|
|
|
{
|
|
|
|
|
Vector3 absNormalsPos = vecRot * Vector3(ptrNormals + verIndex *3);
|
|
|
|
|
|
|
|
|
|
for (int j=0; j<3; j++)
|
|
|
|
|
(ptrNormals + verIndex*3)[j] = absNormalsPos[j];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: create vbas, and give them to createOgreSubMesh
|
|
|
|
|
|
|
|
|
|
vertexPosAbsolut[verIndex] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boneIndex++;
|
|
|
|
|
//it->trafo (pos, rot, scale) of the vertex
|
|
|
|
|
//it->weights array containt the vertices linked to the bone and the weight
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Rotate, scale and translate all the vertices,
|
|
|
|
|
const Matrix &rot = shape->trafo->rotation;
|
|
|
|
|
const Vector &pos = shape->trafo->pos;
|
|
|
|
|
float scale = shape->trafo->scale;
|
|
|
|
@ -589,6 +688,7 @@ static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags, BoundsFin
|
|
|
|
|
ptr += 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hidden)
|
|
|
|
|
{
|
|
|
|
@ -596,12 +696,12 @@ static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags, BoundsFin
|
|
|
|
|
bounds.add(optr, numVerts);
|
|
|
|
|
|
|
|
|
|
// Create the submesh
|
|
|
|
|
createOgreMesh(mesh, shape, material);
|
|
|
|
|
createOgreSubMesh(shape, material);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void handleNode(Mesh* mesh, Nif::Node *node, int flags,
|
|
|
|
|
const Transformation *trafo, BoundsFinder &bounds)
|
|
|
|
|
void NIFLoader::handleNode(Nif::Node *node, int flags,
|
|
|
|
|
const Transformation *trafo, BoundsFinder &bounds, Bone *parentBone)
|
|
|
|
|
{
|
|
|
|
|
// Accumulate the flags from all the child nodes. This works for all
|
|
|
|
|
// the flags we currently use, at least.
|
|
|
|
@ -632,6 +732,29 @@ static void handleNode(Mesh* mesh, Nif::Node *node, int flags,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bone *bone = 0;
|
|
|
|
|
|
|
|
|
|
// create skeleton or add bones
|
|
|
|
|
if (node->recType == RC_NiNode)
|
|
|
|
|
{
|
|
|
|
|
if (node->name == "Bip01") //root node, create a skeleton
|
|
|
|
|
{
|
|
|
|
|
skel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!skel.isNull()) //if there is a skeleton
|
|
|
|
|
{
|
|
|
|
|
bone = skel->createBone(node->name.toString());
|
|
|
|
|
|
|
|
|
|
if (parentBone)
|
|
|
|
|
parentBone->addChild(bone);
|
|
|
|
|
|
|
|
|
|
bone->setInheritOrientation(true);
|
|
|
|
|
bone->setPosition(convertVector3(node->trafo->pos));
|
|
|
|
|
bone->setOrientation(convertRotation(node->trafo->rotation));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply the parent transformation to this node. We overwrite the
|
|
|
|
|
// existing data with the final transformation.
|
|
|
|
|
if (trafo)
|
|
|
|
@ -661,27 +784,31 @@ static void handleNode(Mesh* mesh, Nif::Node *node, int flags,
|
|
|
|
|
for (int i=0; i<n; i++)
|
|
|
|
|
{
|
|
|
|
|
if (list.has(i))
|
|
|
|
|
handleNode(mesh, &list[i], flags, node->trafo, bounds);
|
|
|
|
|
handleNode(&list[i], flags, node->trafo, bounds, bone);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (node->recType == RC_NiTriShape)
|
|
|
|
|
// For shapes
|
|
|
|
|
handleNiTriShape(mesh, dynamic_cast<NiTriShape*>(node), flags, bounds);
|
|
|
|
|
handleNiTriShape(dynamic_cast<NiTriShape*>(node), flags, bounds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NIFLoader::loadResource(Resource *resource)
|
|
|
|
|
{
|
|
|
|
|
resourceName = "";
|
|
|
|
|
mesh = 0;
|
|
|
|
|
skel.setNull();
|
|
|
|
|
|
|
|
|
|
// Set up the VFS if it hasn't been done already
|
|
|
|
|
if(!vfs) vfs = new OgreVFS("General");
|
|
|
|
|
if (!vfs) vfs = new OgreVFS(resourceGroup);
|
|
|
|
|
|
|
|
|
|
// Get the mesh
|
|
|
|
|
Mesh *mesh = dynamic_cast<Mesh*>(resource);
|
|
|
|
|
mesh = dynamic_cast<Mesh*>(resource);
|
|
|
|
|
assert(mesh);
|
|
|
|
|
|
|
|
|
|
// Look it up
|
|
|
|
|
const String &name = mesh->getName();
|
|
|
|
|
errName = name; // Set name for error messages
|
|
|
|
|
if(!vfs->isFile(name))
|
|
|
|
|
resourceName = mesh->getName();
|
|
|
|
|
|
|
|
|
|
if (!vfs->isFile(resourceName))
|
|
|
|
|
{
|
|
|
|
|
warn("File not found.");
|
|
|
|
|
return;
|
|
|
|
@ -694,7 +821,7 @@ void NIFLoader::loadResource(Resource *resource)
|
|
|
|
|
// of the early stages of development. Right now we WANT to catch
|
|
|
|
|
// every error as early and intrusively as possible, as it's most
|
|
|
|
|
// likely a sign of incomplete code rather than faulty input.
|
|
|
|
|
NIFFile nif(vfs->open(name), name);
|
|
|
|
|
NIFFile nif(vfs->open(resourceName), resourceName);
|
|
|
|
|
|
|
|
|
|
if (nif.numRecords() < 1)
|
|
|
|
|
{
|
|
|
|
@ -716,7 +843,11 @@ void NIFLoader::loadResource(Resource *resource)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle the node
|
|
|
|
|
handleNode(mesh, node, 0, NULL, bounds);
|
|
|
|
|
handleNode(node, 0, NULL, bounds, 0);
|
|
|
|
|
|
|
|
|
|
//set skeleton
|
|
|
|
|
// if (!skel.isNull())
|
|
|
|
|
// mesh->setSkeletonName(getSkeletonName());
|
|
|
|
|
|
|
|
|
|
// Finally, set the bounding value.
|
|
|
|
|
if (bounds.isValid())
|
|
|
|
@ -738,7 +869,7 @@ MeshPtr NIFLoader::load(const std::string &name,
|
|
|
|
|
return MeshPtr(ptr);
|
|
|
|
|
|
|
|
|
|
// Nope, create a new one.
|
|
|
|
|
return MeshManager::getSingleton().createManual(name, group, &g_sing);
|
|
|
|
|
return MeshManager::getSingleton().createManual(name, group, NIFLoader::getSingletonPtr());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* More code currently not in use, from the old D source. This was
|
|
|
|
@ -779,70 +910,5 @@ extern "C" void ogre_insertTexture(char* name, uint32_t width, uint32_t height,
|
|
|
|
|
pixelBuffer->unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We need this later for animated meshes.
|
|
|
|
|
extern "C" void* ogre_setupSkeleton(char* name)
|
|
|
|
|
{
|
|
|
|
|
SkeletonPtr skel = SkeletonManager::getSingleton().create(
|
|
|
|
|
name, "Closet", true);
|
|
|
|
|
|
|
|
|
|
skel->load();
|
|
|
|
|
|
|
|
|
|
// Create all bones at the origin and unrotated. This is necessary
|
|
|
|
|
// since our submeshes each have their own model space. We must
|
|
|
|
|
// move the bones after creating an entity, then copy this entity.
|
|
|
|
|
return (void*)skel->createBone();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" void *ogre_insertBone(char* name, void* rootBone, int32_t index)
|
|
|
|
|
{
|
|
|
|
|
return (void*) ( ((Bone*)rootBone)->createChild(index) );
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
/* This was the D part:
|
|
|
|
|
|
|
|
|
|
// Create a skeleton and get the root bone (index 0)
|
|
|
|
|
BonePtr bone = ogre_setupSkeleton(name);
|
|
|
|
|
|
|
|
|
|
// Reset the bone index. The next bone to be created has index 1.
|
|
|
|
|
boneIndex = 1;
|
|
|
|
|
// Create a mesh and assign the skeleton to it
|
|
|
|
|
MeshPtr mesh = ogre_setupMesh(name);
|
|
|
|
|
|
|
|
|
|
// Loop through the nodes, creating submeshes, materials and
|
|
|
|
|
// skeleton bones in the process.
|
|
|
|
|
handleNode(node, bone, mesh);
|
|
|
|
|
|
|
|
|
|
// Create the "template" entity
|
|
|
|
|
EntityPtr entity = ogre_createEntity(name);
|
|
|
|
|
|
|
|
|
|
// Loop through once again, this time to set the right
|
|
|
|
|
// transformations on the entity's SkeletonInstance. The order of
|
|
|
|
|
// children will be the same, allowing us to reference bones using
|
|
|
|
|
// their boneIndex.
|
|
|
|
|
int lastBone = boneIndex;
|
|
|
|
|
boneIndex = 1;
|
|
|
|
|
transformBones(node, entity);
|
|
|
|
|
if(lastBone != boneIndex) writefln("WARNING: Bone number doesn't match");
|
|
|
|
|
|
|
|
|
|
if(!hasBBox)
|
|
|
|
|
ogre_setMeshBoundingBox(mesh, minX, minY, minZ, maxX, maxY, maxZ);
|
|
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
void handleNode(Node node, BonePtr root, MeshPtr mesh)
|
|
|
|
|
{
|
|
|
|
|
// Insert a new bone for this node
|
|
|
|
|
BonePtr bone = ogre_insertBone(node.name, root, boneIndex++);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void transformBones(Node node, EntityPtr entity)
|
|
|
|
|
{
|
|
|
|
|
ogre_transformBone(entity, &node.trafo, boneIndex++);
|
|
|
|
|
|
|
|
|
|
NiNode n = cast(NiNode)node;
|
|
|
|
|
if(n !is null)
|
|
|
|
|
foreach(Node nd; n.children)
|
|
|
|
|
transformBones(nd, entity);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|