Support for newer versions of FCollada

This commit is contained in:
rdb 2008-12-22 11:05:59 +00:00
parent 1101c43b01
commit a1a1bf69b7
6 changed files with 79 additions and 34 deletions

View File

@ -17,11 +17,11 @@
daeToEggConverter.cxx daeToEggConverter.h \
daeCharacter.cxx daeCharacter.h \
daeMaterials.cxx daeMaterials.h \
pre_fcollada_include.h
pre_fcollada_include.h fcollada_utils.h
#define INSTALL_HEADERS \
config_daeegg.h daeToEggConverter.h \
daeCharacter.h daeMaterials.h \
pre_fcollada_include.h
pre_fcollada_include.h fcollada_utils.h
#end lib_target

View File

@ -14,6 +14,7 @@
#include "daeCharacter.h"
#include "config_daeegg.h"
#include "fcollada_utils.h"
#include "pt_EggVertex.h"
#include "eggXfmSAnim.h"
@ -23,15 +24,6 @@
TypeHandle DaeCharacter::_type_handle;
// Useful conversion stuff
#define TO_VEC3(v) (LVecBase3d(v[0], v[1], v[2]))
#define TO_VEC4(v) (LVecBase4d(v[0], v[1], v[2], v[3]))
#define TO_COLOR(v) (Colorf(v[0], v[1], v[2], v[3]))
#define FROM_VEC3(v) (FMVector3(v[0], v[1], v[2]))
#define FROM_VEC4(v) (FMVector4(v[0], v[1], v[2], v[3]))
#define FROM_MAT4(v) (FMMatrix44(v.getData()))
#define FROM_FSTRING(fs) (string(fs.c_str()))
////////////////////////////////////////////////////////////////////
// Function: DaeCharacter::Constructor
// Access: Public
@ -69,7 +61,12 @@ as_egg_bundle() {
skeleton->set_table_type(EggTable::TT_table);
bundle->add_child(skeleton);
// Loop through the joint hierarchy
#if FCOLLADA_VERSION < 0x00030005
FCDSceneNodeList roots = _controller_instance->FindSkeletonNodes();
#else
FCDSceneNodeList roots;
_controller_instance->FindSkeletonNodes(roots);
#endif
for (FCDSceneNodeList::iterator it = roots.begin(); it != roots.end(); ++it) {
process_joint(skeleton, *it);
}

View File

@ -14,6 +14,7 @@
#include "daeMaterials.h"
#include "config_daeegg.h"
#include "fcollada_utils.h"
#include "FCDocument/FCDocument.h"
#include "FCDocument/FCDMaterial.h"
@ -27,12 +28,6 @@
TypeHandle DaeMaterials::_type_handle;
// Useful conversion stuff
#define CONV_VEC3(v) (LVecBase3d(v[0], v[1], v[2]))
#define CONV_VEC4(v) (LVecBase4d(v[0], v[1], v[2], v[3]))
#define CONV_COLOR(v) (Colorf(v[0], v[1], v[2], v[3]))
#define FROM_FSTRING(fs) (string(fs.c_str()))
// luminance function, based on the ISO/CIE color standards
// see ITU-R Recommendation BT.709-4
#define luminance(c) ((c[0] * 0.212671 + c[1] * 0.715160 + c[2] * 0.072169))
@ -68,7 +63,7 @@ void DaeMaterials::add_material_instance(const FCDMaterialInstance* instance) {
for (size_t vib = 0; vib < instance->GetVertexInputBindingCount(); ++vib) {
const FCDMaterialInstanceBindVertexInput* mivib = instance->GetVertexInputBinding(vib);
assert(mivib != NULL);
_materials[semantic]->_uvsets[mivib->inputSet] = FROM_FSTRING(mivib->semantic);
_materials[semantic]->_uvsets[mivib->inputSet] = *mivib->semantic;
}
// Handle the material stuff
@ -87,26 +82,28 @@ void DaeMaterials::add_material_instance(const FCDMaterialInstance* instance) {
} else {
daeegg_cat.spam() << "Processing effect, material semantic is " << semantic << endl;
// Set the material parameters
egg_material->set_amb(CONV_COLOR(effect_common->GetAmbientColor()));
egg_material->set_amb(TO_COLOR(effect_common->GetAmbientColor()));
////TODO: find a better way for transparency
//LVecBase4f diffuse = CONV_COLOR(effect_common->GetDiffuseColor());
//LVecBase4f diffuse = TO_COLOR(effect_common->GetDiffuseColor());
//diffuse.set_w(diffuse.get_w() * (1.0f - effect_common->GetOpacity()));
//egg_material->set_diff(diffuse);
egg_material->set_diff(CONV_COLOR(effect_common->GetDiffuseColor()));
egg_material->set_emit(CONV_COLOR(effect_common->GetEmissionColor()) * effect_common->GetEmissionFactor());
egg_material->set_diff(TO_COLOR(effect_common->GetDiffuseColor()));
egg_material->set_emit(TO_COLOR(effect_common->GetEmissionColor()) * effect_common->GetEmissionFactor());
egg_material->set_shininess(effect_common->GetShininess());
egg_material->set_spec(CONV_COLOR(effect_common->GetSpecularColor()));
egg_material->set_spec(TO_COLOR(effect_common->GetSpecularColor()));
// Now try to load in the textures
process_texture_bucket(semantic, effect_common, FUDaeTextureChannel::DIFFUSE, EggTexture::ET_modulate);
process_texture_bucket(semantic, effect_common, FUDaeTextureChannel::BUMP, EggTexture::ET_normal);
process_texture_bucket(semantic, effect_common, FUDaeTextureChannel::SPECULAR, EggTexture::ET_modulate_gloss);
process_texture_bucket(semantic, effect_common, FUDaeTextureChannel::SPECULAR_LEVEL, EggTexture::ET_gloss);
process_texture_bucket(semantic, effect_common, FUDaeTextureChannel::OPACITY, EggTexture::ET_unspecified, EggTexture::F_alpha);
process_texture_bucket(semantic, effect_common, FUDaeTextureChannel::TRANSPARENT, EggTexture::ET_unspecified, EggTexture::F_alpha);
process_texture_bucket(semantic, effect_common, FUDaeTextureChannel::EMISSION, EggTexture::ET_add);
#if FCOLLADA_VERSION < 0x00030005
process_texture_bucket(semantic, effect_common, FUDaeTextureChannel::OPACITY, EggTexture::ET_unspecified, EggTexture::F_alpha);
#endif
// Now, calculate the color blend stuff.
_materials[semantic]->_blend = convert_blend(effect_common->GetTransparencyMode(),
CONV_COLOR(effect_common->GetTranslucencyColor()),
TO_COLOR(effect_common->GetTranslucencyColor()),
effect_common->GetTranslucencyFactor());
}
// Find an <extra> tag to support some extra stuff from extensions

View File

@ -13,6 +13,7 @@
////////////////////////////////////////////////////////////////////
#include "daeToEggConverter.h"
#include "fcollada_utils.h"
#include "config_daeegg.h"
#include "daeCharacter.h"
#include "dcast.h"
@ -35,6 +36,7 @@
#include "FCDocument/FCDGeometry.h"
#include "FCDocument/FCDGeometryInstance.h"
#include "FCDocument/FCDGeometryPolygons.h"
#include "FCDocument/FCDGeometryPolygonsInput.h"
#include "FCDocument/FCDGeometrySource.h"
#include "FCDocument/FCDSkinController.h"
#include "FCDocument/FCDController.h"
@ -45,15 +47,6 @@
#include "FCDocument/FCDEffect.h"
#include "FCDocument/FCDEffectStandard.h"
// Useful conversion stuff
#define TO_VEC3(v) (LVecBase3d(v[0], v[1], v[2]))
#define TO_VEC4(v) (LVecBase4d(v[0], v[1], v[2], v[3]))
#define TO_COLOR(v) (Colorf(v[0], v[1], v[2], v[3]))
#define FROM_VEC3(v) (FMVector3(v[0], v[1], v[2]))
#define FROM_VEC4(v) (FMVector4(v[0], v[1], v[2], v[3]))
#define FROM_MAT4(v) (FMMatrix44(v.getData()))
#define FROM_FSTRING(fs) (string(fs.c_str()))
////////////////////////////////////////////////////////////////////
// Function: DAEToEggConverter::Constructor
// Access: Public
@ -216,7 +209,12 @@ void DAEToEggConverter::preprocess(const FCDSceneNode* node) {
for (size_t in = 0; in < node->GetInstanceCount(); ++in) {
if (node->GetInstance(in)->GetType() == FCDEntityInstance::CONTROLLER) {
// Loop through the skeleton roots now.
#if FCOLLADA_VERSION < 0x00030005
FCDSceneNodeList roots = ((FCDControllerInstance*) node->GetInstance(in))->FindSkeletonNodes();
#else
FCDSceneNodeList roots;
((FCDControllerInstance*) node->GetInstance(in))->FindSkeletonNodes(roots);
#endif
for (FCDSceneNodeList::iterator it = roots.begin(); it != roots.end(); ++it) {
daeegg_cat.spam() << "Found referenced skeleton root " << FROM_FSTRING((*it)->GetDaeId()) << endl;
_skeletons.push_back(FROM_FSTRING((*it)->GetDaeId()));
@ -515,7 +513,12 @@ void DAEToEggConverter::process_controller(PT(EggGroup) parent, const FCDControl
}
}
// Add the joint hierarchy
#if FCOLLADA_VERSION < 0x00030005
FCDSceneNodeList roots = (const_cast<FCDControllerInstance*> (instance))->FindSkeletonNodes();
#else
FCDSceneNodeList roots;
(const_cast<FCDControllerInstance*> (instance))->FindSkeletonNodes(roots);
#endif
for (FCDSceneNodeList::iterator it = roots.begin(); it != roots.end(); ++it) {
process_node(DCAST(EggGroupNode, parent), *it, true);
}

View File

@ -0,0 +1,39 @@
// Filename: fcollada_utils.h
// Created by: pro-rsoft (22Dec08)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
// This file defines some conversion tools for conversion between
// FCollada and Panda3D
#ifndef FCOLLADA_UTILS_H
#define FCOLLADA_UTILS_H
#include "pre_fcollada_include.h"
#include "FCollada.h"
// Useful conversion stuff
inline LVecBase3d TO_VEC3(FMVector3 v) {
return LVecBase3d(v.x, v.y, v.z);
}
inline LVecBase4d TO_VEC4(FMVector4 v) {
return LVecBase4d(v.x, v.y, v.z, v.w);
}
inline Colorf TO_COLOR(FMVector4 v) {
return Colorf(v.x, v.y, v.z, v.w);
}
#define FROM_VEC3(v) (FMVector3(v[0], v[1], v[2]))
#define FROM_VEC4(v) (FMVector4(v[0], v[1], v[2], v[3]))
#define FROM_MAT4(v) (FMMatrix44(v.getData()))
#define FROM_FSTRING(fs) (string(fs.c_str()))
#endif

View File

@ -15,6 +15,13 @@
// This file defines some stuff that need to be defined before
// one includes FCollada.h
#ifndef PRE_FCOLLADA_INCLUDE_H
#define PRE_FCOLLADA_INCLUDE_H
#ifdef FCOLLADA_VERSION
#error You must include pre_fcollada_include.h before including FCollada.h!
#endif
// FCollada expects LINUX to be defined on linux
#ifdef IS_LINUX
#ifndef LINUX
@ -24,3 +31,5 @@
#define NO_LIBXML
#define FCOLLADA_NOMINMAX
#endif