Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
711cc512c5 | ||
|
|
d0dee701a9 | ||
|
|
e87a671942 | ||
|
|
234abdf85c |
+1
-1
@@ -1 +1 @@
|
|||||||
2020.3.12
|
2020.3.13
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <simgear_config.h>
|
#include <simgear_config.h>
|
||||||
|
|
||||||
#include "ErrorReportingCallback.hxx"
|
#include "ErrorReportingCallback.hxx"
|
||||||
|
#include "logstream.hxx"
|
||||||
|
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
|
||||||
@@ -27,6 +28,31 @@ static ErrorReportCallback static_callback;
|
|||||||
static ContextCallback static_contextCallback;
|
static ContextCallback static_contextCallback;
|
||||||
|
|
||||||
|
|
||||||
|
string_list static_errorNames = {
|
||||||
|
"shader/effect",
|
||||||
|
"loading texture",
|
||||||
|
"XML/animation load",
|
||||||
|
"3D model load",
|
||||||
|
"loading BTG",
|
||||||
|
"sceanrio load",
|
||||||
|
"UI dialog load",
|
||||||
|
"loading Audio/FX",
|
||||||
|
"Nasal/commnad load of XML",
|
||||||
|
"aircraft-systems",
|
||||||
|
"loading input/joystick config",
|
||||||
|
"load AI/traffic",
|
||||||
|
"from TerraSync"};
|
||||||
|
|
||||||
|
string_list static_errorTypeNames = {
|
||||||
|
"unknown",
|
||||||
|
"not found",
|
||||||
|
"out of memory",
|
||||||
|
"bad header",
|
||||||
|
"bad data",
|
||||||
|
"misconfigured",
|
||||||
|
"disk IO/permissions",
|
||||||
|
"network IO"};
|
||||||
|
|
||||||
void setErrorReportCallback(ErrorReportCallback cb)
|
void setErrorReportCallback(ErrorReportCallback cb)
|
||||||
{
|
{
|
||||||
static_callback = cb;
|
static_callback = cb;
|
||||||
@@ -53,6 +79,7 @@ static FailureCallback static_failureCallback;
|
|||||||
void reportFailure(LoadFailure type, ErrorCode code, const std::string& details, sg_location loc)
|
void reportFailure(LoadFailure type, ErrorCode code, const std::string& details, sg_location loc)
|
||||||
{
|
{
|
||||||
if (!static_failureCallback) {
|
if (!static_failureCallback) {
|
||||||
|
SG_LOG(SG_GENERAL, SG_WARN, "Error:" << static_errorTypeNames.at(static_cast<int>(type)) << " from " << static_errorNames.at(static_cast<int>(code)) << "::" << details << "\n\t" << loc.asString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +89,9 @@ void reportFailure(LoadFailure type, ErrorCode code, const std::string& details,
|
|||||||
void reportFailure(LoadFailure type, ErrorCode code, const std::string& details, const SGPath& path)
|
void reportFailure(LoadFailure type, ErrorCode code, const std::string& details, const SGPath& path)
|
||||||
{
|
{
|
||||||
if (!static_failureCallback) {
|
if (!static_failureCallback) {
|
||||||
|
// if no callback is registered, log here instead
|
||||||
|
SG_LOG(SG_GENERAL, SG_WARN, "Error:" << static_errorTypeNames.at(static_cast<int>(type)) << " from " << static_errorNames.at(static_cast<int>(code)) << "::" << details << "\n\t" << path);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,8 @@ size_t hash_value(const Effect::Key&);
|
|||||||
|
|
||||||
Effect* makeEffect(const std::string& name,
|
Effect* makeEffect(const std::string& name,
|
||||||
bool realizeTechniques,
|
bool realizeTechniques,
|
||||||
const SGReaderWriterOptions* options);
|
const SGReaderWriterOptions* options,
|
||||||
|
const SGPath& modelPath = SGPath{});
|
||||||
|
|
||||||
Effect* makeEffect(SGPropertyNode* prop,
|
Effect* makeEffect(SGPropertyNode* prop,
|
||||||
bool realizeTechniques,
|
bool realizeTechniques,
|
||||||
|
|||||||
@@ -114,7 +114,8 @@ void mergePropertyTrees(SGPropertyNode* resultNode,
|
|||||||
|
|
||||||
Effect* makeEffect(const string& name,
|
Effect* makeEffect(const string& name,
|
||||||
bool realizeTechniques,
|
bool realizeTechniques,
|
||||||
const SGReaderWriterOptions* options)
|
const SGReaderWriterOptions* options,
|
||||||
|
const SGPath& modelPath)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(effectMutex);
|
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(effectMutex);
|
||||||
@@ -125,8 +126,7 @@ Effect* makeEffect(const string& name,
|
|||||||
}
|
}
|
||||||
string effectFileName(name);
|
string effectFileName(name);
|
||||||
effectFileName += ".eff";
|
effectFileName += ".eff";
|
||||||
string absFileName
|
string absFileName = SGModelLib::findDataFile(effectFileName, options, modelPath);
|
||||||
= SGModelLib::findDataFile(effectFileName, options);
|
|
||||||
if (absFileName.empty()) {
|
if (absFileName.empty()) {
|
||||||
simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::LoadEffectsShaders, "Couldn't find Effect:" + effectFileName);
|
simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::LoadEffectsShaders, "Couldn't find Effect:" + effectFileName);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -197,7 +197,7 @@ Effect* makeEffect(SGPropertyNode* prop,
|
|||||||
Effect* parent = 0;
|
Effect* parent = 0;
|
||||||
if (inheritProp) {
|
if (inheritProp) {
|
||||||
//prop->removeChild("inherits-from");
|
//prop->removeChild("inherits-from");
|
||||||
parent = makeEffect(inheritProp->getStringValue(), false, options);
|
parent = makeEffect(inheritProp->getStringValue(), false, options, filePath);
|
||||||
if (parent) {
|
if (parent) {
|
||||||
Effect::Key key;
|
Effect::Key key;
|
||||||
key.unmerged = prop;
|
key.unmerged = prop;
|
||||||
|
|||||||
@@ -559,8 +559,8 @@ sgLoad3DModel_internal(const SGPath& path,
|
|||||||
// Some material animations (eventually all) are actually effects.
|
// Some material animations (eventually all) are actually effects.
|
||||||
makeEffectAnimations(animation_nodes, effect_nodes);
|
makeEffectAnimations(animation_nodes, effect_nodes);
|
||||||
{
|
{
|
||||||
ref_ptr<Node> modelWithEffects
|
ref_ptr<Node> modelWithEffects = instantiateEffects(group.get(), effect_nodes, options.get(),
|
||||||
= instantiateEffects(group.get(), effect_nodes, options.get());
|
path.dirPath());
|
||||||
group = static_cast<Group*>(modelWithEffects.get());
|
group = static_cast<Group*>(modelWithEffects.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ public:
|
|||||||
typedef std::map<string, SGPropertyNode_ptr> EffectMap;
|
typedef std::map<string, SGPropertyNode_ptr> EffectMap;
|
||||||
using SplicingVisitor::apply;
|
using SplicingVisitor::apply;
|
||||||
MakeEffectVisitor(const SGReaderWriterOptions* options = 0)
|
MakeEffectVisitor(const SGReaderWriterOptions* options = 0)
|
||||||
: _options(options)
|
: _options(options), _modelPath(SGPath{})
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual void apply(osg::Group& node);
|
virtual void apply(osg::Group& node);
|
||||||
@@ -246,10 +246,17 @@ public:
|
|||||||
_currentEffectParent = effect;
|
_currentEffectParent = effect;
|
||||||
}
|
}
|
||||||
SGPropertyNode* getDefaultEffect() { return _currentEffectParent; }
|
SGPropertyNode* getDefaultEffect() { return _currentEffectParent; }
|
||||||
|
|
||||||
|
void setModelPath(const SGPath& p)
|
||||||
|
{
|
||||||
|
_modelPath = p;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
EffectMap _effectMap;
|
EffectMap _effectMap;
|
||||||
SGPropertyNode_ptr _currentEffectParent;
|
SGPropertyNode_ptr _currentEffectParent;
|
||||||
osg::ref_ptr<const SGReaderWriterOptions> _options;
|
osg::ref_ptr<const SGReaderWriterOptions> _options;
|
||||||
|
SGPath _modelPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
void MakeEffectVisitor::apply(osg::Group& node)
|
void MakeEffectVisitor::apply(osg::Group& node)
|
||||||
@@ -287,7 +294,7 @@ void MakeEffectVisitor::apply(osg::Geode& geode)
|
|||||||
makeParametersFromStateSet(ssRoot, ss);
|
makeParametersFromStateSet(ssRoot, ss);
|
||||||
SGPropertyNode_ptr effectRoot = new SGPropertyNode;
|
SGPropertyNode_ptr effectRoot = new SGPropertyNode;
|
||||||
effect::mergePropertyTrees(effectRoot, ssRoot, _currentEffectParent);
|
effect::mergePropertyTrees(effectRoot, ssRoot, _currentEffectParent);
|
||||||
Effect* effect = makeEffect(effectRoot, true, _options.get());
|
Effect* effect = makeEffect(effectRoot, true, _options.get(), _modelPath);
|
||||||
EffectGeode* eg = dynamic_cast<EffectGeode*>(&geode);
|
EffectGeode* eg = dynamic_cast<EffectGeode*>(&geode);
|
||||||
if (eg) {
|
if (eg) {
|
||||||
eg->setEffect(effect);
|
eg->setEffect(effect);
|
||||||
@@ -332,7 +339,8 @@ protected:
|
|||||||
|
|
||||||
ref_ptr<Node> instantiateEffects(osg::Node* modelGroup,
|
ref_ptr<Node> instantiateEffects(osg::Node* modelGroup,
|
||||||
PropertyList& effectProps,
|
PropertyList& effectProps,
|
||||||
const SGReaderWriterOptions* options)
|
const SGReaderWriterOptions* options,
|
||||||
|
const SGPath& modelPath)
|
||||||
{
|
{
|
||||||
SGPropertyNode_ptr defaultEffectPropRoot;
|
SGPropertyNode_ptr defaultEffectPropRoot;
|
||||||
MakeEffectVisitor visitor(options);
|
MakeEffectVisitor visitor(options);
|
||||||
@@ -357,13 +365,15 @@ ref_ptr<Node> instantiateEffects(osg::Node* modelGroup,
|
|||||||
if (!defaultEffectPropRoot)
|
if (!defaultEffectPropRoot)
|
||||||
defaultEffectPropRoot = DefaultEffect::instance()->getEffect();
|
defaultEffectPropRoot = DefaultEffect::instance()->getEffect();
|
||||||
visitor.setDefaultEffect(defaultEffectPropRoot.ptr());
|
visitor.setDefaultEffect(defaultEffectPropRoot.ptr());
|
||||||
|
visitor.setModelPath(modelPath);
|
||||||
modelGroup->accept(visitor);
|
modelGroup->accept(visitor);
|
||||||
osg::NodeList& result = visitor.getResults();
|
osg::NodeList& result = visitor.getResults();
|
||||||
return ref_ptr<Node>(result[0].get());
|
return ref_ptr<Node>(result[0].get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ref_ptr<Node> instantiateMaterialEffects(osg::Node* modelGroup,
|
ref_ptr<Node> instantiateMaterialEffects(osg::Node* modelGroup,
|
||||||
const SGReaderWriterOptions* options)
|
const SGReaderWriterOptions* options,
|
||||||
|
const SGPath& modelPath)
|
||||||
{
|
{
|
||||||
|
|
||||||
SGPropertyNode_ptr effect;
|
SGPropertyNode_ptr effect;
|
||||||
@@ -390,7 +400,7 @@ ref_ptr<Node> instantiateMaterialEffects(osg::Node* modelGroup,
|
|||||||
|
|
||||||
effect->addChild("default")->setBoolValue(true);
|
effect->addChild("default")->setBoolValue(true);
|
||||||
effectProps.push_back(effect);
|
effectProps.push_back(effect);
|
||||||
return instantiateEffects(modelGroup, effectProps, options);
|
return instantiateEffects(modelGroup, effectProps, options, modelPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ public:
|
|||||||
osg::ref_ptr<osg::Node>
|
osg::ref_ptr<osg::Node>
|
||||||
instantiateEffects(osg::Node* model,
|
instantiateEffects(osg::Node* model,
|
||||||
PropertyList& effectProps,
|
PropertyList& effectProps,
|
||||||
const SGReaderWriterOptions* options);
|
const SGReaderWriterOptions* options,
|
||||||
|
const SGPath& currentDir = SGPath{});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a set of material-defined effects to a model
|
* Apply a set of material-defined effects to a model
|
||||||
@@ -112,9 +113,10 @@ instantiateEffects(osg::Node* model,
|
|||||||
*
|
*
|
||||||
* returns a copy if any nodes are changed
|
* returns a copy if any nodes are changed
|
||||||
*/
|
*/
|
||||||
osg::ref_ptr<osg::Node>
|
osg::ref_ptr<osg::Node>
|
||||||
instantiateMaterialEffects(osg::Node* model,
|
instantiateMaterialEffects(osg::Node* model,
|
||||||
const SGReaderWriterOptions* options);
|
const SGReaderWriterOptions* options,
|
||||||
|
const SGPath& modelPath = SGPath{});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform an OSG subgraph by substituting the Effects and
|
* Transform an OSG subgraph by substituting the Effects and
|
||||||
@@ -127,10 +129,11 @@ instantiateEffects(osg::Node* model,
|
|||||||
|
|
||||||
inline osg::ref_ptr<osg::Node>
|
inline osg::ref_ptr<osg::Node>
|
||||||
instantiateEffects(osg::Node* model,
|
instantiateEffects(osg::Node* model,
|
||||||
const SGReaderWriterOptions* options)
|
const SGReaderWriterOptions* options,
|
||||||
|
const SGPath& currentDir = SGPath{})
|
||||||
{
|
{
|
||||||
PropertyList effectProps;
|
PropertyList effectProps;
|
||||||
return instantiateEffects(model, effectProps, options);
|
return instantiateEffects(model, effectProps, options, currentDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // __MODEL_HXX
|
#endif // __MODEL_HXX
|
||||||
|
|||||||
@@ -267,12 +267,12 @@ public:
|
|||||||
SGVec2f texCoord = a*t0 + b*t1 + c*t2;
|
SGVec2f texCoord = a*t0 + b*t1 + c*t2;
|
||||||
|
|
||||||
// Check this random point against the object mask
|
// Check this random point against the object mask
|
||||||
// red channel.
|
// blue channel.
|
||||||
osg::Image* img = object_mask->getImage();
|
osg::Image* img = object_mask->getImage();
|
||||||
unsigned int x = (int) (img->s() * texCoord.x()) % img->s();
|
unsigned int x = (int) (img->s() * texCoord.x()) % img->s();
|
||||||
unsigned int y = (int) (img->t() * texCoord.y()) % img->t();
|
unsigned int y = (int) (img->t() * texCoord.y()) % img->t();
|
||||||
|
|
||||||
if (mt_rand(&seed) < img->getColor(x, y).r()) {
|
if (mt_rand(&seed) < img->getColor(x, y).b()) {
|
||||||
points.push_back(randomPoint);
|
points.push_back(randomPoint);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -192,12 +192,12 @@ public:
|
|||||||
SGVec2f texCoord = a*t0 + b*t1 + c*t2;
|
SGVec2f texCoord = a*t0 + b*t1 + c*t2;
|
||||||
|
|
||||||
// Check this random point against the object mask
|
// Check this random point against the object mask
|
||||||
// red channel.
|
// blue channel.
|
||||||
osg::Image* img = object_mask->getImage();
|
osg::Image* img = object_mask->getImage();
|
||||||
unsigned int x = (int) (img->s() * texCoord.x()) % img->s();
|
unsigned int x = (int) (img->s() * texCoord.x()) % img->s();
|
||||||
unsigned int y = (int) (img->t() * texCoord.y()) % img->t();
|
unsigned int y = (int) (img->t() * texCoord.y()) % img->t();
|
||||||
|
|
||||||
if (mt_rand(&seed) < img->getColor(x, y).r()) {
|
if (mt_rand(&seed) < img->getColor(x, y).b()) {
|
||||||
points.push_back(randomPoint);
|
points.push_back(randomPoint);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user