updates to existing importer (bugs, etc.) and addition of importer audio objects skeleton code

--HG--
branch : nfb
This commit is contained in:
Peter
2013-12-05 15:54:28 -08:00
parent 971dadd7f6
commit fef872cc6d
6 changed files with 493 additions and 0 deletions

View File

@@ -0,0 +1,212 @@
//
// ImporterAudioLists.cpp
//
#include "ImporterAudioLists.h"
//
// (1) UTILITIES
void IMPORTER_AUDIO_UTILITIES() { }
//
// Utility to convert a file code from a resource file into an object id
// <n> will convert to <n>
// <n>H will convert to <n> << 8
// <n>A will convert to <n> << 16
// A result of 0 implies a bad input code
//
unsigned long codeToID(char *code)
{
static char decode[64];
size_t l = strlen(code);
if (l <= 0) return 0; // no code string
if (l > 63) l = 63;
int type = 0;
switch (code[l-1]) {
case 'A' :
case 'a' :
type = 8;
case 'H' :
case 'h' :
type += 8;
strncpy(decode, code, l-1); // (dst, src, maxlength)
decode[l-1] = 0;
break;
default :
strncpy(decode, code, l);
decode[l] = 0;
break;
};
unsigned long id = strtol(decode, 0, 0); // (str, endptr, base)
id = id << type;
return id;
}
//
// (2) ZONE CORNERS
void IMPORTER_AUDIO_ZONE_CORNERS() { }
//
// (2a) A corners list for a given room/space
void zoneRoomCornersList::addCorner(zoneCorner *c)
{
}
void zoneRoomCornersList::generateZones(simpleList *zonelist)
{
}
//
// (2b) A list of all the corners lists
void zoneAllCornersList::addCorner(zoneCorner *c)
{
}
void zoneAllCornersList::generateSpheresFor(unsigned long id, simpleList *zonelist)
{
}
void zoneAllCornersList::generateSpheres(simpleList *zonelist)
{
}
//
// (3) RESOURCES
void IMPORTER_AUDIO_RESOURCES() { }
bool zoneResourceList::load(char *path1, char *path2)
{
return true;
}
//
// (4) ZONE NODE MANAGER
void IMPORTER_AUDIO_MANAGER() { }
zoneNodeManager::zoneNodeManager()
{
}
zoneNodeManager::~zoneNodeManager()
{
}
// (1) parse the resource files and create the resource list
bool zoneNodeManager::loadResources(char *path1, char *path2)
{
return resources.load(path1, path2);
}
// (2) given a locator add it to the correct list
//
// insert vector table list into this space!
bool addLocator_audioNode(zoneNodeManager *manager, char *idstring, KRVector3 where, double radius)
{
return true;
}
bool addLocator_ambientZone(zoneNodeManager *manager, char *idstring, KRVector3 where, double radius)
{
return true;
}
bool addLocator_reverbZone(zoneNodeManager *manager, char *idstring, KRVector3 where, double radius)
{
return true;
}
bool addLocator_ambientCorner(zoneNodeManager *manager, char *idstring, KRVector3 where, double radius)
{
return true;
}
bool addLocator_reverbCorner(zoneNodeManager *manager, char *idstring, KRVector3 where, double radius)
{
return true;
}
typedef bool (*addLocatorFunction)(zoneNodeManager *, char *, KRVector3, double);
typedef struct {
const char *prefix;
unsigned long prefix_length;
addLocatorFunction function;
} addLocatorTableItem;
addLocatorTableItem addLocatorVectorTable[] = {
{ "AN_", 3, addLocator_audioNode },
{ "AZpoint_", 8, addLocator_ambientZone },
{ "RZpoint_", 8, addLocator_reverbZone },
{ "AZcorner_", 9, addLocator_ambientCorner },
{ "RZcorner_", 9, addLocator_reverbCorner },
{ NULL, 0, NULL },
};
addLocatorTableItem *addLocator_findType(char *name)
{
addLocatorTableItem *result = addLocatorVectorTable;
while (NULL != result->prefix)
{
if (0 == strncmp(result->prefix, name, result->prefix_length)) return result;
result++;
}
return NULL;
}
bool zoneNodeManager::addLocatorToAList(char *name, KRVector3 point, double radius)
{
// (1) parse the name and add it to a list where appropriate
// AN_<node_name>_<unique> is an audio node
// AZpoint_<n>_<unique> is an audio zone point with a radius
// RZpoint_<n><p>_<unique> is a reverb zone point with a radius
// AZcorner_<n>_<order> is a corner for an ambient zone
// RZcorner_<n><p>_<order> is a corner for a reverb zone
//
addLocatorTableItem *item = addLocator_findType(name);
if (NULL != item)
{
//**** IN HERE we want to parse the args into the ID arg and the unique/order arg
//**** UPDATE (*addLocatorFunction) to handle the 'order' arg
char arg[AUDIO_IMPORTER_STRLEN];
strncpy(arg, &name[item->prefix_length], AUDIO_IMPORTER_STRLEN-1);
arg[AUDIO_IMPORTER_STRLEN-1] = 0;
item->function(this, arg, point, radius);
return true; // return true if this is an audio locator that was added to a list
}
return false; // return false if the FBX importer should handle the locator itself
}
// (3) turn corner definitions into spheres
void zoneNodeManager::generateSpheresForAllZones()
{
ambientCornersList.generateSpheres(&ambientZoneList);
reverbCornersList.generateSpheres(&reverbZoneList);
}
// (4) output ambient zones
// (5) output reverb zones
// (6) output audio nodes (props)
bool zoneNodeManager::outputAmbientZones()
{
return true;
}
bool zoneNodeManager::outputReverbZones()
{
return true;
}
bool zoneNodeManager::outputAudioNodes()
{
return true;
}
// END OF ImporterAudioLists.cpp

View File

@@ -0,0 +1,123 @@
//
// ImporterAudioLists.h
//
#ifndef _IMPORTER_AUDIO_LISTS_H_
#define _IMPORTER_AUDIO_LISTS_H_
#include "KRVector3.h"
#include "simpleList.h"
enum {
AUDIO_IMPORTER_STRLEN = 128
};
//
// (1) Nodes and Dummy Props
// A locator point
// AN_<node_name>_<unique>
struct audioPoint : public simpleListObject {
KRVector3 point;
char name[AUDIO_IMPORTER_STRLEN]; // this could change to a std::string
};
//
// (2) Zone Locators - for ambient zones and reverb zones
// A zone sphere object
// RZpoint_<n><p>_<unique> locRadius and AZpoint_<n>_<unique> locRadius
struct zone : public simpleListObject {
KRVector3 point;
double radius;
unsigned long id;
};
// A zone corner object
// RZcorner_<n><p>_<order_clockwise> and AZcorner_<n>_<order_clockwise>
struct zoneCorner : public simpleListObject {
KRVector3 point;
unsigned long id;
};
//
// A list of corners for a particular location
struct zoneRoomCornersList : public simpleListObject {
unsigned long id;
simpleList corners; // the zoneCorner objects for a given id
void addCorner(zoneCorner *c);
// add it into the list in presorted place/location_number order starting bottom left and going clockwise
void generateZones(simpleList *zonelist);
// create a set of spheres that fill in the space defined by the corners
// and add these spheres to the 'zonelist'
};
//
// A master list of lists of corners
struct zoneAllCornersList : public simpleList {
void addCorner(zoneCorner *c);
// find or create a zoneRoomCornersList for the incoming id, then use that list's addCorner() method
void generateSpheresFor(unsigned long id, simpleList *zonelist);
void generateSpheres(simpleList *zonelist);
// routines to generate circle points for the geometery of a given place + location_number
// .. and to place these cirlces into a given zone list
};
// A resource object
// <n><p> <resource file name> or <n> <resource file name>
struct zoneResource : public simpleListObject {
unsigned long id;
char resource_name[AUDIO_IMPORTER_STRLEN];
};
struct zoneResourceList : public simpleList {
bool load(char *path1, char *path2 = NULL);
// all resources are loaded into the same list from either 1 or 2 input files
// we can either put all the reverb and ambient info in 1 file, or split it across 2 files
};
//
// (3) Zone and Node Manager
struct zoneNodeManager {
zoneResourceList resources;
simpleList ambientZoneList; // list of 'zone' objects
zoneAllCornersList ambientCornersList;
simpleList reverbZoneList; // list of 'zone' objects
zoneAllCornersList reverbCornersList;
simpleList audioNodesList; // a list of 'audioPoint' objects
zoneNodeManager();
virtual ~zoneNodeManager();
// (1) parse the resource files and create the resource list
bool loadResources(char *path1, char *path2=NULL); // passed through to resources.load()
// (2) given a locator add it to the correct list
bool addLocatorToAList(char *name, KRVector3 point, double radius);
// (3) turn corner definitions into spheres
void generateSpheresForAllZones();
// (4) output ambient zones
// (5) output reverb zones
// (6) output audio nodes (props)
virtual bool outputAmbientZones();
virtual bool outputReverbZones();
virtual bool outputAudioNodes();
};
#endif
// END OF ImporterAudioLists.h

View File

@@ -1613,6 +1613,9 @@ KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) {
//**** HACK A BIT TO FIND OUT HOW IT WORKS
const char *node_name = pNode->GetName();
FbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSourcePivot);
KRVector3 node_translation = KRVector3(local_translation[0], local_translation[1], local_translation[2]);
// if(strncmp(node_name, "physics_collider_", strlen("physics_collider_")) == 0) {
// // example hard coded compare
// }
@@ -1644,6 +1647,7 @@ KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) {
//
// create_prop telegraph_radio dummyprop 94.371559 4.400661 31.469673 0.05
// - creates a reference point that the radio sound is 'located at' later in the script
// create_node mitchell_phone 22.7842 18.7481 9.1446
//
// TO BE ADDED

View File

@@ -0,0 +1,87 @@
//
// simpleList.cpp
//
#include "simpleList.h"
simpleListObject::simpleListObject() { next = previous = NULL; }
simpleListObject::~simpleListObject() { }
simpleList::simpleList() {
first = last = NULL;
nelements = 0;
};
simpleList::~simpleList() { while((first)) remove(first); }
void simpleList::add(simpleListObject *elem, simpleListObject *after) {
if (NULL == elem) return;
if (NULL == first) {
first = last = elem;
elem->next = elem->previous = NULL;
}
else {
if (NULL == after) { after = last; }
if (last == after) {
elem->next = NULL;
elem->previous = last;
last->next = elem;
last = elem;
}
else {
elem->previous = after;
elem->next = after->next;
after->next->previous = elem;
after->next = elem;
}
}
nelements++;
}
void simpleList::insert(simpleListObject *elem, simpleListObject *before) {
if (NULL == elem) return;
if (NULL == first) {
first = last = elem;
elem->next = elem->previous = NULL;
}
else {
if (NULL == before) { before = first; }
if (first == before) {
elem->previous = NULL;
elem->next = first;
first->previous = elem;
first = elem;
}
else {
elem->previous = before->previous;
elem->next = before;
before->previous->next = elem;
before->previous = elem;
}
}
nelements++;
}
void simpleList::remove(simpleListObject *elem) {
if (0 == nelements) return;
if (NULL == elem) return;
if (NULL != elem->previous) elem->previous->next = elem->next;
if (NULL != elem->next) elem->next->previous = elem->previous;
if (elem == last) last = elem->previous;
if (elem == first) first = elem->next;
elem->previous = elem->next = NULL;
nelements--;
}
simpleListObject *simpleList::findByIndex(unsigned long index) {
simpleListObject *result = NULL;
if (index < nelements) {
simpleListObject *current = first;
for (unsigned long i = 0; (i < index) && (NULL != current); i++)
current = current->next;
result = current;
}
return result;
}
// END OF simpleList.cpp

View File

@@ -0,0 +1,35 @@
//
// simpleList.h
//
#ifndef _SIMPLE_LIST_OBJECTS_H_
#define _SIMPLE_LIST_OBJECTS_H_
#include <cstddef> // include for pre c++11 defines
struct simpleListObject {
simpleListObject *next;
simpleListObject *previous;
simpleListObject();
~simpleListObject();
}; // end of struct simpleListObject
struct simpleList {
simpleListObject *first;
simpleListObject *last;
unsigned long nelements;
simpleList();
~simpleList();
void add(simpleListObject *elem, simpleListObject *after=NULL);
void insert(simpleListObject *elem, simpleListObject *before=NULL);
void remove(simpleListObject *elem);
simpleListObject *findByIndex(unsigned long index);
}; // end of struct simpleList
#endif
// END OF simpleList.h