Support materials in bam2egg

This commit is contained in:
rdb 2015-02-24 21:40:55 +01:00
parent c0e4de3df7
commit 46ddd46c5c
2 changed files with 50 additions and 2 deletions

View File

@ -22,6 +22,7 @@
#include "transformState.h"
#include "colorScaleAttrib.h"
#include "colorAttrib.h"
#include "materialAttrib.h"
#include "textureAttrib.h"
#include "cullFaceAttrib.h"
#include "transparencyAttrib.h"
@ -577,6 +578,13 @@ convert_primitive(const GeomVertexData *vertex_data,
}
}
// Check for a material.
EggMaterial *egg_mat = (EggMaterial *)NULL;
const MaterialAttrib *ma = DCAST(MaterialAttrib, net_state->get_attrib(MaterialAttrib::get_class_type()));
if (ma != (const MaterialAttrib *)NULL) {
egg_mat = get_egg_material(ma->get_material());
}
// Check for a texture.
EggTexture *egg_tex = (EggTexture *)NULL;
const TextureAttrib *ta = DCAST(TextureAttrib, net_state->get_attrib(TextureAttrib::get_class_type()));
@ -703,11 +711,15 @@ convert_primitive(const GeomVertexData *vertex_data,
// Huh, an unknown geometry type.
return;
}
for (int i = 0; i < num_primitives; ++i) {
PT(EggPrimitive) egg_prim = (*make_func)();
egg_parent->add_child(egg_prim);
if (egg_mat != (EggMaterial *)NULL) {
egg_prim->set_material(egg_mat);
}
if (egg_tex != (EggTexture *)NULL) {
egg_prim->set_texture(egg_tex);
}
@ -947,6 +959,41 @@ apply_tag(EggGroup *egg_group, PandaNode *node, const string &tag) {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: EggSaver::get_egg_material
// Access: Private
// Description: Returns an EggMaterial pointer that corresponds to
// the indicated Material.
////////////////////////////////////////////////////////////////////
EggMaterial *EggSaver::
get_egg_material(Material *mat) {
if (mat != (Material *)NULL) {
EggMaterial temp(mat->get_name());
if (mat->has_ambient()) {
temp.set_amb(mat->get_ambient());
}
if (mat->has_diffuse()) {
temp.set_diff(mat->get_diffuse());
}
if (mat->has_specular()) {
temp.set_spec(mat->get_specular());
}
if (mat->has_emission()) {
temp.set_emit(mat->get_emission());
}
temp.set_shininess(mat->get_shininess());
temp.set_local(mat->get_local());
return _materials.create_unique_material(temp, ~EggMaterial::E_mref_name);
}
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: EggSaver::get_egg_texture
// Access: Private

View File

@ -92,6 +92,7 @@ private:
bool apply_tags(EggGroup *egg_group, PandaNode *node);
bool apply_tag(EggGroup *egg_group, PandaNode *node, const string &tag);
EggMaterial *get_egg_material(Material *tex);
EggTexture *get_egg_texture(Texture *tex);
static EggPrimitive *make_egg_polygon();
@ -102,8 +103,8 @@ private:
PT(EggData) _data;
PT(EggVertexPool) _vpool;
EggTextureCollection _textures;
EggMaterialCollection _materials;
EggTextureCollection _textures;
};
#include "eggSaver.I"