15 #include "xFileMaterial.h"
16 #include "xFileToEggConverter.h"
17 #include "xFileDataNode.h"
18 #include "eggMaterial.h"
19 #include "eggTexture.h"
20 #include "eggPrimitive.h"
32 _face_color.set(1.0, 1.0, 1.0, 1.0);
33 _specular_color.set(0.0, 0.0, 0.0);
34 _emissive_color.set(0.0, 0.0, 0.0);
37 _has_material =
false;
58 if (egg_prim->has_color()) {
67 if (egg_mat->has_diff()) {
70 if (egg_mat->has_spec()) {
72 _specular_color.set(spec[0], spec[1], spec[2]);
74 if (egg_mat->has_emit()) {
76 _emissive_color.set(emit[0], emit[1], emit[2]);
78 if (egg_mat->has_shininess()) {
79 _power = egg_mat->get_shininess();
111 if (got_spec || got_emit) {
113 temp.set_diff(_face_color);
115 temp.set_shininess(_power);
116 temp.set_spec(
LColor(_specular_color[0], _specular_color[1],
117 _specular_color[2], 1.0));
120 temp.set_emit(
LColor(_emissive_color[0], _emissive_color[1],
121 _emissive_color[2], 1.0));
128 egg_prim->set_color(_face_color);
139 ct = _face_color.
compare_to(other._face_color);
141 ct = (_power == other._power) ? 0 : ((_power < other._power) ? -1 : 1);
144 ct = _specular_color.
compare_to(other._specular_color);
147 ct = _emissive_color.
compare_to(other._emissive_color);
150 ct = strcmp(_texture.c_str(), other._texture.c_str());
164 return _has_material;
188 _specular_color, _emissive_color);
205 _face_color = LCAST(PN_stdfloat, (*obj)[
"faceColor"].vec4());
206 _power = (*obj)[
"power"].d();
207 _specular_color = LCAST(PN_stdfloat, (*obj)[
"specularColor"].vec3());
208 _emissive_color = LCAST(PN_stdfloat, (*obj)[
"emissiveColor"].vec3());
209 _has_material =
true;
214 for (
int i = 0; i < num_objects; i++) {
221 if (xfile_cat.is_debug()) {
223 <<
"Ignoring material object of unknown type: "
int compare_to(const LVecBase4f &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
XFileDataNode * get_object(int n) const
Returns the nth child object of this node.
const string & get_template_name() const
A convenience function to return the name of the template used to define this data object...
LColor get_color() const
Returns the color set on this particular attribute.
virtual bool is_standard_object(const string &template_name) const
Returns true if this node represents an instance of the standard template with the indicated name...
Defines a texture map that may be applied to geometry.
void set_texture(EggTexture *texture)
Replaces the current list of textures with the indicated texture.
void apply_to_egg(EggPrimitive *egg_prim, XFileToEggConverter *converter)
Applies the properties in the material to the indicated egg primitive.
EggTexture * get_texture() const
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
static const LVecBase3f & zero()
Returns a zero-length vector.
void set_from_egg(EggPrimitive *egg_prim)
Sets the structure up from the indicated egg data.
EggMaterial * create_unique_material(const EggMaterial ©)
Returns an EggMaterial pointer whose properties match that of the the given EggMaterial, except for the mref name.
int get_num_objects() const
Returns the list of child objects of this node.
XFileDataNode * make_x_material(XFileNode *x_meshMaterials, const string &suffix)
Creates a Material object for the material list.
A single node of an X file.
XFileDataNode * add_TextureFilename(const string &name, const Filename &filename)
Creates a new TextureFilename instance, as a child of this node.
LColor get_diff() const
It is legal to call this even if has_diff() returns false.
int compare_to(const LVecBase3f &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
EggMaterial * get_material() const
Returns a pointer to the applied material, or NULL if there is no material applied.
The name of a file, such as a texture file or an Egg file.
void set_material(EggMaterial *material)
Applies the indicated material to the primitive.
const Filename & get_filename() const
Returns a nonmodifiable reference to the filename.
This is the base class for all three-component vectors and points.
bool has_material() const
Returns true if this material represents something meaningful, or false if the default material is su...
bool has_material() const
Returns true if the primitive is materiald (and get_material() will return a real pointer)...
This represents an X file "material", which consists of a color, lighting, and/or texture specificati...
This is an abstract base class for an XFileNode which is also an XFileDataObject. ...
EggTexture * create_unique_texture(const EggTexture ©)
Returns an EggTexture pointer whose properties match that of the the given EggTexture, except for the tref name.
bool fill_material(XFileDataNode *obj)
Fills the structure based on the raw data from the X file's Material object.
LColor get_spec() const
It is legal to call this even if has_spec() returns false.
LColor get_emit() const
It is legal to call this even if has_emit() returns false.
XFileDataNode * add_Material(const string &name, const LColor &face_color, double power, const LRGBColor &specular_color, const LRGBColor &emissive_color)
Creates a new Material instance, as a child of this node.
Filename convert_model_path(const Filename &orig_filename)
Converts the indicated model filename to a relative or absolute or whatever filename, according to _path_replace.
bool has_texture() const
Returns true if the primitive has any textures specified, false otherwise.
bool has_texture() const
Returns true if this material includes a texture map, false otherwise.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).