Allow custom meshes and textures for stars defined in .stc files.

ver1_5_1
Chris Laurel 2004-09-21 17:37:17 +00:00
parent 8e7dac1833
commit 3524450c51
6 changed files with 88 additions and 14 deletions

View File

@ -4997,8 +4997,16 @@ void Renderer::renderStar(const Star& star,
break;
}
#endif
tex = starTexA;
surface.baseTexture = MultiResTexture(tex, tex, tex);
MultiResTexture mtex = star.getTexture();
if (mtex.tex[textureResolution] != InvalidResource)
{
surface.baseTexture = mtex;
}
else
{
tex = starTexA;
surface.baseTexture = MultiResTexture(tex, tex, tex);
}
surface.appearanceFlags |= Surface::ApplyBaseTexture;
surface.appearanceFlags |= Surface::Emissive;
@ -5012,7 +5020,7 @@ void Renderer::renderStar(const Star& star,
rp.rings = NULL;
rp.radius = star.getRadius();
rp.oblateness = 0.0f;
rp.model = InvalidResource;
rp.model = star.getModel();
double rotation = 0.0;
// Watch out for the precision limits of floats when computing

View File

@ -675,6 +675,20 @@ StarDetails::setBolometricCorrection(float correction)
}
void
StarDetails::setTexture(const MultiResTexture& tex)
{
texture = tex;
}
void
StarDetails::setModel(ResourceHandle rh)
{
model = rh;
}
// Return the radius of the star in kilometers
float Star::getRadius() const
{
@ -698,6 +712,20 @@ float Star::getRadius() const
}
MultiResTexture
Star::getTexture() const
{
return details->getTexture();
}
ResourceHandle
Star::getModel() const
{
return details->getModel();
}
void Star::setCatalogNumber(uint32 n)
{
catalogNumber = n;

View File

@ -16,6 +16,7 @@
#include <celmath/vecmath.h>
#include <celengine/celestia.h>
#include <celengine/stellarclass.h>
#include <celengine/multitexture.h>
class Orbit;
@ -28,8 +29,8 @@ class StarDetails
inline float getTemperature() const;
inline float getRotationPeriod() const;
inline Vec3f getSemiAxes() const;
inline ResourceHandle getMesh() const;
inline ResourceHandle getTexture() const;
inline ResourceHandle getModel() const;
inline MultiResTexture getTexture() const;
inline const Orbit* getOrbit() const;
inline uint32 getKnowledge() const;
inline bool getKnowledge(uint32) const;
@ -43,6 +44,8 @@ class StarDetails
void addKnowledge(uint32);
void setSpectralType(const std::string&);
void setBolometricCorrection(float);
void setTexture(const MultiResTexture&);
void setModel(ResourceHandle);
enum
{
@ -59,6 +62,9 @@ class StarDetails
uint32 knowledge;
char spectralType[8];
MultiResTexture texture;
ResourceHandle model;
public:
static StarDetails* GetStarDetails(const StellarClass&);
static StarDetails* CreateStandardStarType(const std::string& _specType,
@ -100,15 +106,15 @@ StarDetails::getSemiAxes() const
}
ResourceHandle
StarDetails::getMesh() const
StarDetails::getModel() const
{
return InvalidResource;
return model;
}
ResourceHandle
MultiResTexture
StarDetails::getTexture() const
{
return InvalidResource;
return texture;
}
const Orbit*
@ -168,6 +174,8 @@ public:
inline float getRotationPeriod() const;
inline const char* getSpectralType() const;
inline float getBolometricMagnitude() const;
MultiResTexture getTexture() const;
ResourceHandle getModel() const;
enum {
InvalidCatalogNumber = 0xffffffff

View File

@ -19,6 +19,8 @@
#include "astro.h"
#include "stardb.h"
#include "parser.h"
#include "multitexture.h"
#include "meshmanager.h"
#include <celutil/debug.h>
using namespace std;
@ -743,7 +745,9 @@ void StarDatabase::buildIndexes()
}
static Star* CreateStar(uint32 catalogNumber, Hash* starData)
static Star* CreateStar(uint32 catalogNumber,
Hash* starData,
const string& path)
{
double ra = 0.0;
double dec = 0.0;
@ -790,6 +794,32 @@ static Star* CreateStar(uint32 catalogNumber, Hash* starData)
absMag = astro::appToAbsMag((float) appMag, (float) distance);
}
string modelName;
string textureName;
bool hasTexture = starData->getString("Texture", textureName);
bool hasModel = starData->getString("Mesh", modelName);
if (hasTexture || hasModel)
{
// If the star definition has extended information, clone the
// star details so we can customize it without affecting other
// stars of the same spectral type.
// TODO: Need better management of star details objects. The
// standard ones should be persistent, but the custom ones should
// probably be destroyed in the star destructor. Reference counting
// is probably the best strategy.
details = new StarDetails(*details);
}
if (hasTexture)
details->setTexture(MultiResTexture(textureName, path));
if (hasModel)
{
ResourceHandle modelHandle = GetModelManager()->getHandle(ModelInfo(modelName, path, Vec3f(0.0f, 0.0f, 0.0f)));
details->setModel(modelHandle);
}
Star* star = new Star();
star->setDetails(details);
star->setCatalogNumber(catalogNumber);
@ -805,7 +835,7 @@ static Star* CreateStar(uint32 catalogNumber, Hash* starData)
}
bool StarDatabase::load(istream& in)
bool StarDatabase::load(istream& in, const string& resourcePath)
{
Tokenizer tokenizer(&in);
Parser parser(&tokenizer);
@ -844,7 +874,7 @@ bool StarDatabase::load(istream& in)
}
Hash* starData = starDataValue->getHash();
Star* star = CreateStar(catalogNumber, starData);
Star* star = CreateStar(catalogNumber, starData, resourcePath);
if (star != NULL)
{
// Ensure that the star array is large enough

View File

@ -48,7 +48,7 @@ class StarDatabase
StarNameDatabase* getNameDatabase() const;
void setNameDatabase(StarNameDatabase*);
bool load(std::istream&);
bool load(std::istream&, const std::string& resourcePath);
bool loadBinary(std::istream&);
bool loadOldFormatBinary(std::istream&);

View File

@ -3503,7 +3503,7 @@ public:
ifstream starFile(fullname.c_str(), ios::in);
if (starFile.good())
{
bool success = starDB->load(starFile);
bool success = starDB->load(starFile, getPath());
if (!success)
{
DPRINTF(0, "Error reading star file: %s\n",