mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
Overhauled texture handling
This commit is contained in:
parent
265130ae80
commit
1c54bdc2ed
@ -10,6 +10,7 @@
|
||||
|
||||
//Disable the forcing int to true or false performance warning
|
||||
#pragma warning(disable: 4800)
|
||||
#include "pathStore.h"
|
||||
|
||||
void SetICustEdit(HWND wnd, int nIDDlgItem, char *text)
|
||||
{
|
||||
@ -234,6 +235,7 @@ MaxEggOptions::MaxEggOptions() {
|
||||
_file_name[0]=0;
|
||||
_short_name[0]=0;
|
||||
_path_replace = new PathReplace;
|
||||
_path_replace->_path_store = PS_relative;
|
||||
_export_whole_scene = true;
|
||||
}
|
||||
|
||||
@ -551,6 +553,7 @@ bool MaxOptionsDialog::UpdateFromUI(HWND hWnd) {
|
||||
_anim_type = newAnimType;
|
||||
_double_sided = IsDlgButtonChecked(hWnd, IDC_CHECK1);
|
||||
_export_whole_scene = IsDlgButtonChecked(hWnd, IDC_EXPORT_ALL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -12,11 +12,6 @@
|
||||
|
||||
#pragma conform(forScope, off)
|
||||
|
||||
//Includes & Definitions
|
||||
|
||||
#define ME Logger::ST_MAP_ME_TO_APP_SPECIFIC_SYSTEM6
|
||||
#define MNEG Logger::ST_MAP_ME_TO_APP_SPECIFIC_SYSTEM2
|
||||
#define MNEG_GEOMETRY_GENERATION Logger::ST_MAP_ME_TO_APP_SPECIFIC_SYSTEM3
|
||||
|
||||
/* Externed Globals */
|
||||
extern HINSTANCE hInstance;
|
||||
|
@ -58,6 +58,9 @@ bool MaxToEggConverter::convert(MaxEggOptions *options) {
|
||||
|
||||
_options = options;
|
||||
|
||||
Filename fn = Filename::from_os_specific(_options->_file_name);
|
||||
_options->_path_replace->_path_directory = fn.get_dirname();
|
||||
|
||||
_egg_data = new EggData;
|
||||
if (_egg_data->get_coordinate_system() == CS_default) {
|
||||
_egg_data->set_coordinate_system(CS_zup_right);
|
||||
@ -824,38 +827,33 @@ get_vertex_weights(INode *max_node, EggVertexPool *vpool) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MaxToEggConverter::set_material_attributes
|
||||
// Function: MaxToEggConverter::get_material_textures
|
||||
// Access: Private
|
||||
// Description: Applies the known material attributes to the indicated
|
||||
// egg primitive.
|
||||
// Description: Converts a Max material into a set of Panda textures
|
||||
// and a primitive color.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void MaxToEggConverter::
|
||||
set_material_attributes(EggPrimitive &primitive, Mtl *maxMaterial, Face *face) {
|
||||
const MaxToEggConverter::PandaMaterial &MaxToEggConverter::
|
||||
get_material_textures(StdMat *maxMaterial) {
|
||||
|
||||
MaterialMap::iterator it = _material_map.find(maxMaterial);
|
||||
if (it != _material_map.end()) {
|
||||
return (*it).second;
|
||||
}
|
||||
|
||||
PandaMaterial &pandaMat = _material_map[maxMaterial];
|
||||
pandaMat._color = Colorf(1,1,1,1);
|
||||
|
||||
Texmap *diffuseTexmap;
|
||||
Texmap *transTexmap;
|
||||
Bitmap *diffuseBitmap;
|
||||
BitmapTex *diffuseBitmapTex;
|
||||
BitmapTex *transBitmapTex;
|
||||
// Mtl *maxMaterial;
|
||||
StdMat *maxStandardMaterial;
|
||||
Texmap *diffuseTexmap;
|
||||
Texmap *transTexmap;
|
||||
EggTexture *myEggTexture = null;
|
||||
string outString;
|
||||
string outHandle;
|
||||
bool has_diffuse_texture = false;
|
||||
bool has_trans_texture = false;
|
||||
|
||||
Point3 diffuseColor = Point3(1, 1, 1);
|
||||
|
||||
//First, get the material data associated with this node.
|
||||
if ( !maxMaterial ) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Now, determine wether it's a standard or multi material
|
||||
if ( maxMaterial->ClassID() == Class_ID(DMTL_CLASS_ID, 0 )) {
|
||||
maxStandardMaterial = (StdMat *)maxMaterial;
|
||||
|
||||
// Access the Diffuse map and see if it's a Bitmap texture
|
||||
diffuseTexmap = maxMaterial->GetSubTexmap(ID_DI);
|
||||
if (diffuseTexmap && (diffuseTexmap->ClassID() == Class_ID(BMTEX_CLASS_ID, 0))) {
|
||||
@ -883,7 +881,7 @@ set_material_attributes(EggPrimitive &primitive, Mtl *maxMaterial, Face *face) {
|
||||
fullpath, outpath);
|
||||
tex.set_filename(outpath);
|
||||
tex.set_fullpath(fullpath);
|
||||
apply_texture_properties(tex, maxStandardMaterial);
|
||||
apply_texture_properties(tex, maxMaterial);
|
||||
// *** Must add stuff here for looking for transparencies
|
||||
diffuseBitmap = diffuseBitmapTex->GetBitmap(0);
|
||||
//Query some parameters of the bitmap to get the format option.
|
||||
@ -916,42 +914,56 @@ set_material_attributes(EggPrimitive &primitive, Mtl *maxMaterial, Face *face) {
|
||||
tex.set_filename(outpath);
|
||||
tex.set_fullpath(fullpath);
|
||||
tex.set_format(EggTexture::F_alpha);
|
||||
apply_texture_properties(tex, maxStandardMaterial);
|
||||
apply_texture_properties(tex, maxMaterial);
|
||||
}
|
||||
EggTexture *new_tex =
|
||||
_textures.create_unique_texture(tex, ~EggTexture::E_tref_name);
|
||||
|
||||
primitive.set_texture(new_tex);
|
||||
}
|
||||
|
||||
// Also apply an overall color to the primitive.
|
||||
Colorf rgba(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
pandaMat._texture_list.push_back(new_tex);
|
||||
|
||||
// The existence of a texture on either color channel completely
|
||||
// replaces the corresponding flat color.
|
||||
if (!has_diffuse_texture) {
|
||||
// Get the default diffuse color of the material without the texture map
|
||||
diffuseColor = Point3(maxMaterial->GetDiffuse());
|
||||
rgba[0] = diffuseColor.x;
|
||||
rgba[1] = diffuseColor.y;
|
||||
rgba[2] = diffuseColor.z;
|
||||
diffuseColor = Point3(maxMaterial->GetDiffuse(0));
|
||||
pandaMat._color[0] = diffuseColor.x;
|
||||
pandaMat._color[1] = diffuseColor.y;
|
||||
pandaMat._color[2] = diffuseColor.z;
|
||||
}
|
||||
if (!has_trans_texture) {
|
||||
// *** Figure out how to actually get the opacity here
|
||||
rgba[3] = maxStandardMaterial->GetOpacity(_current_frame * GetTicksPerFrame());
|
||||
pandaMat._color[3] = maxMaterial->GetOpacity(_current_frame * GetTicksPerFrame());
|
||||
}
|
||||
}
|
||||
return pandaMat;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MaxToEggConverter::set_material_attributes
|
||||
// Access: Private
|
||||
// Description: Applies the known material attributes to the indicated
|
||||
// egg primitive.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void MaxToEggConverter::
|
||||
set_material_attributes(EggPrimitive &primitive, Mtl *maxMaterial, Face *face) {
|
||||
// Mtl *maxMaterial;
|
||||
StdMat *maxStandardMaterial;
|
||||
EggTexture *myEggTexture = null;
|
||||
string outString;
|
||||
string outHandle;
|
||||
|
||||
//First, get the material data associated with this node.
|
||||
if ( !maxMaterial ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// *** May need color gain, but I don't know what it is
|
||||
/*
|
||||
// But the color gain always gets applied.
|
||||
rgba[0] *= color_def._color_gain[0];
|
||||
rgba[1] *= color_def._color_gain[1];
|
||||
rgba[2] *= color_def._color_gain[2];
|
||||
rgba[3] *= color_def._color_gain[3];
|
||||
*/
|
||||
|
||||
primitive.set_color(rgba);
|
||||
|
||||
//Now, determine wether it's a standard or multi material
|
||||
if ( maxMaterial->ClassID() == Class_ID(DMTL_CLASS_ID, 0 )) {
|
||||
const PandaMaterial &pmat = get_material_textures((StdMat *)maxMaterial);
|
||||
for (int i=0; i<pmat._texture_list.size(); i++) {
|
||||
primitive.set_texture(pmat._texture_list[i]);
|
||||
}
|
||||
primitive.set_color(pmat._color);
|
||||
} else if ( maxMaterial->ClassID() == Class_ID(MULTI_CLASS_ID, 0 )) {
|
||||
// It's a multi-material. Find the submaterial for this face.
|
||||
// and call set_material_attributes again on the submaterial.
|
||||
|
@ -45,6 +45,11 @@ class MaxToEggConverter {
|
||||
bool convert(MaxEggOptions *options);
|
||||
|
||||
private:
|
||||
struct PandaMaterial {
|
||||
std::vector<EggTexture*> _texture_list;
|
||||
Colorf _color;
|
||||
};
|
||||
typedef std::map<StdMat*,PandaMaterial> MaterialMap;
|
||||
MaxEggOptions *_options;
|
||||
int _current_frame;
|
||||
PT(EggData) _egg_data;
|
||||
@ -52,6 +57,7 @@ class MaxToEggConverter {
|
||||
MaxNodeTree _tree;
|
||||
int _cur_tref;
|
||||
EggTextureCollection _textures;
|
||||
MaterialMap _material_map;
|
||||
|
||||
void reset();
|
||||
|
||||
@ -83,6 +89,8 @@ class MaxToEggConverter {
|
||||
|
||||
void set_material_attributes(EggPrimitive &primitive, Mtl *maxMaterial, Face *face);
|
||||
|
||||
const PandaMaterial &get_material_textures(StdMat *mtl);
|
||||
|
||||
void apply_texture_properties(EggTexture &tex,
|
||||
StdMat *maxMaterial);
|
||||
bool reparent_decals(EggGroupNode *egg_parent);
|
||||
|
Loading…
x
Reference in New Issue
Block a user