mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
*** empty log message ***
This commit is contained in:
parent
ae5974dabc
commit
2e840cf2a7
@ -242,3 +242,17 @@ string_to_double(const string &str, double &result) {
|
|||||||
result = string_to_double(str, tail);
|
result = string_to_double(str, tail);
|
||||||
return tail.empty();
|
return tail.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: string_to_float
|
||||||
|
// Description: Another flavor of string_to_float(), this one
|
||||||
|
// returns true if the string is a perfectly valid
|
||||||
|
// number (and sets result to that value), or false
|
||||||
|
// otherwise.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
bool
|
||||||
|
string_to_float(const string &str, float &result) {
|
||||||
|
string tail;
|
||||||
|
result = string_to_double(str, tail);
|
||||||
|
return tail.empty();
|
||||||
|
}
|
||||||
|
@ -40,6 +40,7 @@ EXPCL_PANDA int string_to_int(const string &str, string &tail);
|
|||||||
EXPCL_PANDA bool string_to_int(const string &str, int &result);
|
EXPCL_PANDA bool string_to_int(const string &str, int &result);
|
||||||
EXPCL_PANDA double string_to_double(const string &str, string &tail);
|
EXPCL_PANDA double string_to_double(const string &str, string &tail);
|
||||||
EXPCL_PANDA bool string_to_double(const string &str, double &result);
|
EXPCL_PANDA bool string_to_double(const string &str, double &result);
|
||||||
|
EXPCL_PANDA bool string_to_float(const string &str, float &result);
|
||||||
|
|
||||||
// Convenience function to make a string from anything that has an
|
// Convenience function to make a string from anything that has an
|
||||||
// ostream operator.
|
// ostream operator.
|
||||||
|
@ -60,7 +60,7 @@ private:
|
|||||||
Filename _output_image_filename;
|
Filename _output_image_filename;
|
||||||
Filename _input_font_filename;
|
Filename _input_font_filename;
|
||||||
bool _got_output_size;
|
bool _got_output_size;
|
||||||
Colord _fg, _bg;
|
Colorf _fg, _bg;
|
||||||
bool _use_alpha;
|
bool _use_alpha;
|
||||||
int _output_xsize, _output_ysize, _output_zsize;
|
int _output_xsize, _output_ysize, _output_zsize;
|
||||||
double _buffer_pixels;
|
double _buffer_pixels;
|
||||||
|
149
pandatool/src/eggprogs/eggTextureCards.cxx
Normal file
149
pandatool/src/eggprogs/eggTextureCards.cxx
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
// Filename: eggTextureCards.cxx
|
||||||
|
// Created by: drose (21Feb01)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "eggTextureCards.h"
|
||||||
|
|
||||||
|
#include <eggGroup.h>
|
||||||
|
#include <eggVertexPool.h>
|
||||||
|
#include <eggVertex.h>
|
||||||
|
#include <eggTexture.h>
|
||||||
|
#include <eggPolygon.h>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: EggTextureCards::Constructor
|
||||||
|
// Access: Public
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
EggTextureCards::
|
||||||
|
EggTextureCards() : EggWriter(true, true) {
|
||||||
|
set_program_description
|
||||||
|
("egg-texture-cards generates an egg file consisting of several "
|
||||||
|
"square polygons, one for each texture name that appears on the "
|
||||||
|
"command line.\n\n"
|
||||||
|
|
||||||
|
"This is a handy thing to have for importing texture images through "
|
||||||
|
"egg-palettize, even when those textures do not appear on any real "
|
||||||
|
"geometry; it can also be used for creating a lot of simple polygons "
|
||||||
|
"for rendering click buttons and similar interfaces.");
|
||||||
|
|
||||||
|
clear_runlines();
|
||||||
|
add_runline("[opts] texture [texture ...] output.egg");
|
||||||
|
add_runline("[opts] -o output.egg texture [texture ...]");
|
||||||
|
add_runline("[opts] texture [texture ...] >output.egg");
|
||||||
|
|
||||||
|
add_option
|
||||||
|
("g", "left,right,bottom,top", 0,
|
||||||
|
"Specifies the geometry of each polygon. The default is a unit polygon "
|
||||||
|
"centered on the origin: -0.5,0.5,-0.5,0.5. Polygons are always created "
|
||||||
|
"on the X-Y plane.",
|
||||||
|
&EggTextureCards::dispatch_double_quad, NULL, &_polygon_geometry[0]);
|
||||||
|
|
||||||
|
add_option
|
||||||
|
("c", "r,g,b[,a]", 0,
|
||||||
|
"Specifies the color of each polygon. The default is white: 1,1,1,1.",
|
||||||
|
&EggTextureCards::dispatch_color, NULL, &_polygon_color[0]);
|
||||||
|
|
||||||
|
_polygon_geometry.set(-0.5, 0.5, -0.5, 0.5);
|
||||||
|
_polygon_color.set(1.0, 1.0, 1.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: EggTextureCards::handle_args
|
||||||
|
// Access: Protected, Virtual
|
||||||
|
// Description: Does something with the additional arguments on the
|
||||||
|
// command line (after all the -options have been
|
||||||
|
// parsed). Returns true if the arguments are good,
|
||||||
|
// false otherwise.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
bool EggTextureCards::
|
||||||
|
handle_args(ProgramBase::Args &args) {
|
||||||
|
if (!check_last_arg(args)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.empty()) {
|
||||||
|
nout << "No texture names specified on the command line.\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_texture_names.insert(_texture_names.end(), args.begin(), args.end());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: EggTextureCards::run
|
||||||
|
// Access: Public
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void EggTextureCards::
|
||||||
|
run() {
|
||||||
|
// First, create an enclosing group and a vertex pool with four
|
||||||
|
// vertices. We can use the same four vertices on all polygons.
|
||||||
|
|
||||||
|
EggGroup *group = new EggGroup();
|
||||||
|
_data.add_child(group);
|
||||||
|
EggVertexPool *vpool = new EggVertexPool("vpool");
|
||||||
|
group->add_child(vpool);
|
||||||
|
|
||||||
|
//
|
||||||
|
// 1 4
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 2 3
|
||||||
|
//
|
||||||
|
|
||||||
|
EggVertex *v1 = vpool->make_new_vertex
|
||||||
|
(LPoint3d(_polygon_geometry[0], _polygon_geometry[3], 0.0));
|
||||||
|
EggVertex *v2 = vpool->make_new_vertex
|
||||||
|
(LPoint3d(_polygon_geometry[0], _polygon_geometry[2], 0.0));
|
||||||
|
EggVertex *v3 = vpool->make_new_vertex
|
||||||
|
(LPoint3d(_polygon_geometry[1], _polygon_geometry[2], 0.0));
|
||||||
|
EggVertex *v4 = vpool->make_new_vertex
|
||||||
|
(LPoint3d(_polygon_geometry[1], _polygon_geometry[3], 0.0));
|
||||||
|
|
||||||
|
v1->set_uv(TexCoordd(0.0, 1.0));
|
||||||
|
v2->set_uv(TexCoordd(0.0, 0.0));
|
||||||
|
v3->set_uv(TexCoordd(1.0, 0.0));
|
||||||
|
v4->set_uv(TexCoordd(1.0, 1.0));
|
||||||
|
|
||||||
|
// Now, create a texture reference and a polygon for each texture.
|
||||||
|
// We don't really care whether the texture files actually exist at
|
||||||
|
// this point yet.
|
||||||
|
|
||||||
|
vector_string::const_iterator ti;
|
||||||
|
for (ti = _texture_names.begin(); ti != _texture_names.end(); ++ti) {
|
||||||
|
Filename filename = (*ti);
|
||||||
|
string name = filename.get_basename_wo_extension();
|
||||||
|
|
||||||
|
EggTexture *tref = new EggTexture(name, filename);
|
||||||
|
group->add_child(tref);
|
||||||
|
|
||||||
|
// Each polygon gets placed in its own sub-group. This will make
|
||||||
|
// pulling them out by name at runtime possible.
|
||||||
|
EggGroup *sub_group = new EggGroup(name);
|
||||||
|
group->add_child(sub_group);
|
||||||
|
EggPolygon *poly = new EggPolygon();
|
||||||
|
sub_group->add_child(poly);
|
||||||
|
poly->set_texture(tref);
|
||||||
|
poly->set_color(_polygon_color);
|
||||||
|
|
||||||
|
poly->add_vertex(v1);
|
||||||
|
poly->add_vertex(v2);
|
||||||
|
poly->add_vertex(v3);
|
||||||
|
poly->add_vertex(v4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Done!
|
||||||
|
_data.write_egg(get_output());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
EggTextureCards prog;
|
||||||
|
prog.parse_command_line(argc, argv);
|
||||||
|
prog.run();
|
||||||
|
return 0;
|
||||||
|
}
|
36
pandatool/src/eggprogs/eggTextureCards.h
Normal file
36
pandatool/src/eggprogs/eggTextureCards.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Filename: eggTextureCards.h
|
||||||
|
// Created by: drose (21Feb01)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef EGGTEXTURECARDS_H
|
||||||
|
#define EGGTEXTURECARDS_H
|
||||||
|
|
||||||
|
#include <pandatoolbase.h>
|
||||||
|
|
||||||
|
#include <eggWriter.h>
|
||||||
|
#include <luse.h>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Class : EggTextureCards
|
||||||
|
// Description : Generates an egg file featuring a number of polygons,
|
||||||
|
// one for each named texture. This is a support
|
||||||
|
// program for getting textures through egg-palettize.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
class EggTextureCards : public EggWriter {
|
||||||
|
public:
|
||||||
|
EggTextureCards();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool handle_args(Args &args);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void run();
|
||||||
|
|
||||||
|
LVecBase4d _polygon_geometry;
|
||||||
|
Colorf _polygon_color;
|
||||||
|
vector_string _texture_names;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -707,12 +707,12 @@ dispatch_double_quad(const string &opt, const string &arg, void *var) {
|
|||||||
// Access: Protected, Static
|
// Access: Protected, Static
|
||||||
// Description: Standard dispatch function for an option that takes a
|
// Description: Standard dispatch function for an option that takes a
|
||||||
// color, either as r,g,b or as r,g,b,a. The data
|
// color, either as r,g,b or as r,g,b,a. The data
|
||||||
// pointer is to an array of four doubles, e.g. a
|
// pointer is to an array of four floats, e.g. a
|
||||||
// Colord.
|
// Colorf.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool ProgramBase::
|
bool ProgramBase::
|
||||||
dispatch_color(const string &opt, const string &arg, void *var) {
|
dispatch_color(const string &opt, const string &arg, void *var) {
|
||||||
double *ip = (double *)var;
|
float *ip = (float *)var;
|
||||||
|
|
||||||
vector_string words;
|
vector_string words;
|
||||||
tokenize(arg, words, ",");
|
tokenize(arg, words, ",");
|
||||||
@ -720,16 +720,16 @@ dispatch_color(const string &opt, const string &arg, void *var) {
|
|||||||
bool okflag = false;
|
bool okflag = false;
|
||||||
if (words.size() == 4) {
|
if (words.size() == 4) {
|
||||||
okflag =
|
okflag =
|
||||||
string_to_double(words[0], ip[0]) &&
|
string_to_float(words[0], ip[0]) &&
|
||||||
string_to_double(words[1], ip[1]) &&
|
string_to_float(words[1], ip[1]) &&
|
||||||
string_to_double(words[2], ip[2]) &&
|
string_to_float(words[2], ip[2]) &&
|
||||||
string_to_double(words[3], ip[3]);
|
string_to_float(words[3], ip[3]);
|
||||||
|
|
||||||
} else if (words.size() == 3) {
|
} else if (words.size() == 3) {
|
||||||
okflag =
|
okflag =
|
||||||
string_to_double(words[0], ip[0]) &&
|
string_to_float(words[0], ip[0]) &&
|
||||||
string_to_double(words[1], ip[1]) &&
|
string_to_float(words[1], ip[1]) &&
|
||||||
string_to_double(words[2], ip[2]);
|
string_to_float(words[2], ip[2]);
|
||||||
ip[3] = 1.0;
|
ip[3] = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user