bvh: Introduce BVHMaterial independent of SGMaterial.

The bounding volumes in core should not depend on scenery.
Therefore reference material properties relevant for the BVH
tree in BVHMaterial.
This commit is contained in:
Mathias Froehlich 2012-08-24 21:20:40 +02:00
parent 22878b6f89
commit 7a879e2abf
10 changed files with 141 additions and 79 deletions

View File

@ -54,7 +54,7 @@ public:
{ return _linearVelocity; }
const SGVec3d& getAngularVelocity() const
{ return _angularVelocity; }
const SGMaterial* getMaterial() const
const BVHMaterial* getMaterial() const
{ return _material; }
BVHNode::Id getId() const
{ return _id; }
@ -87,7 +87,7 @@ private:
SGVec3d _normal;
SGVec3d _linearVelocity;
SGVec3d _angularVelocity;
const SGMaterial* _material;
const BVHMaterial* _material;
BVHNode::Id _id;
bool _haveHit;

View File

@ -0,0 +1,35 @@
// Copyright (C) 2008 - 2012 Mathias Froehlich - Mathias.Froehlich@web.de
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#include "BVHMaterial.hxx"
namespace simgear {
BVHMaterial::BVHMaterial() :
_solid(true),
_friction_factor(1),
_rolling_friction(0.02),
_bumpiness(0),
_load_resistance(1e30)
{
}
BVHMaterial::~BVHMaterial()
{
}
}

View File

@ -0,0 +1,75 @@
// Copyright (C) 2008 - 2012 Mathias Froehlich - Mathias.Froehlich@web.de
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#ifndef BVHMaterial_hxx
#define BVHMaterial_hxx
#include <simgear/structure/SGReferenced.hxx>
namespace simgear {
class BVHMaterial : public SGReferenced {
public:
BVHMaterial();
virtual ~BVHMaterial();
/**
* Return if the surface material is solid, if it is not solid, a fluid
* can be assumed, that is usually water.
*/
bool get_solid () const { return _solid; }
/**
* Get the friction factor for that material
*/
double get_friction_factor () const { return _friction_factor; }
/**
* Get the rolling friction for that material
*/
double get_rolling_friction () const { return _rolling_friction; }
/**
* Get the bumpines for that material
*/
double get_bumpiness () const { return _bumpiness; }
/**
* Get the load resistance
*/
double get_load_resistance () const { return _load_resistance; }
protected:
// True if the material is solid, false if it is a fluid
bool _solid;
// the friction factor of that surface material
double _friction_factor;
// the rolling friction of that surface material
double _rolling_friction;
// the bumpiness of that surface material
double _bumpiness;
// the load resistance of that surface material
double _load_resistance;
};
}
#endif

View File

@ -140,7 +140,7 @@ public:
{ return _linearVelocity; }
const SGVec3d& getAngularVelocity() const
{ return _angularVelocity; }
const SGMaterial* getMaterial() const
const BVHMaterial* getMaterial() const
{ return _material; }
BVHNode::Id getId() const
{ return _id; }
@ -155,7 +155,7 @@ private:
SGVec3d _point;
SGVec3d _linearVelocity;
SGVec3d _angularVelocity;
const SGMaterial* _material;
const BVHMaterial* _material;
BVHNode::Id _id;
bool _havePoint;

View File

@ -22,11 +22,7 @@
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/math/SGGeometry.hxx>
/// FIXME, the SGMaterial class is too much tied to the scenegraph aspects of
/// the materials. Use some class more decribing the
/// nature of the surface we live on ...
class SGMaterial;
#include "BVHMaterial.hxx"
namespace simgear {
@ -40,20 +36,20 @@ public:
{ return _vertices[i]; }
unsigned addMaterial(const SGMaterial* material)
unsigned addMaterial(const BVHMaterial* material)
{ _materials.push_back(material); return _materials.size() - 1; }
const SGMaterial* getMaterial(unsigned i) const
const BVHMaterial* getMaterial(unsigned i) const
{ if (_materials.size() <= i) return 0; return _materials[i]; }
void trim()
{
std::vector<SGVec3f>(_vertices).swap(_vertices);
std::vector<const SGMaterial*>(_materials).swap(_materials);
std::vector<SGSharedPtr<const BVHMaterial> >(_materials).swap(_materials);
}
private:
std::vector<SGVec3f> _vertices;
std::vector<const SGMaterial*> _materials;
std::vector<SGSharedPtr<const BVHMaterial> > _materials;
};
}

View File

@ -78,16 +78,16 @@ public:
typedef std::set<SGVec3<unsigned> > TriangleSet;
TriangleSet _triangleSet;
void setCurrentMaterial(const SGMaterial* material)
void setCurrentMaterial(const BVHMaterial* material)
{
_currentMaterial = material;
_currentMaterialIndex = addMaterial(material);
}
const SGMaterial* getCurrentMaterial() const
const BVHMaterial* getCurrentMaterial() const
{
return _currentMaterial;
}
unsigned addMaterial(const SGMaterial* material)
unsigned addMaterial(const BVHMaterial* material)
{
MaterialMap::const_iterator i = _materialMap.find(material);
if (i != _materialMap.end())
@ -97,9 +97,9 @@ public:
return index;
}
typedef std::map<const SGMaterial*, unsigned> MaterialMap;
typedef std::map<const BVHMaterial*, unsigned> MaterialMap;
MaterialMap _materialMap;
const SGMaterial* _currentMaterial;
const BVHMaterial* _currentMaterial;
unsigned _currentMaterialIndex;
void addTriangle(const SGVec3f& v1, const SGVec3f& v2, const SGVec3f& v3)

View File

@ -16,6 +16,7 @@ set(HEADERS
BVHStaticNode.hxx
BVHStaticTriangle.hxx
BVHSubTreeCollector.hxx
BVHMaterial.hxx
BVHTransform.hxx
BVHVisitor.hxx
)
@ -32,6 +33,7 @@ set(SOURCES
BVHStaticNode.cxx
BVHStaticTriangle.cxx
BVHSubTreeCollector.cxx
BVHMaterial.cxx
BVHTransform.cxx
)

View File

@ -347,11 +347,11 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
}
// surface values for use with ground reactions
solid = props->getBoolValue("solid", true);
friction_factor = props->getDoubleValue("friction-factor", 1.0);
rolling_friction = props->getDoubleValue("rolling-friction", 0.02);
bumpiness = props->getDoubleValue("bumpiness", 0.0);
load_resistance = props->getDoubleValue("load-resistance", 1e30);
_solid = props->getBoolValue("solid", _solid);
_friction_factor = props->getDoubleValue("friction-factor", _friction_factor);
_rolling_friction = props->getDoubleValue("rolling-friction", _rolling_friction);
_bumpiness = props->getDoubleValue("bumpiness", _bumpiness);
_load_resistance = props->getDoubleValue("load-resistance", _load_resistance);
// Taken from default values as used in ac3d
ambient[0] = props->getDoubleValue("ambient/r", 0.2);
@ -425,12 +425,6 @@ SGMaterial::init ()
light_coverage = 0.0;
building_coverage = 0.0;
solid = true;
friction_factor = 1;
rolling_friction = 0.02;
bumpiness = 0;
load_resistance = 1e30;
shininess = 1.0;
for (int i = 0; i < 4; i++) {
ambient[i] = (i < 3) ? 0.2 : 1.0;

View File

@ -44,6 +44,7 @@ class StateSet;
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/math/SGMath.hxx>
#include <simgear/bvh/BVHMaterial.hxx>
namespace simgear
{
@ -67,7 +68,7 @@ class SGTexturedTriangleBin;
* defined in the $FG_ROOT/materials.xml file, and can be changed
* at runtime.
*/
class SGMaterial : public SGReferenced {
class SGMaterial : public simgear::BVHMaterial {
public:
@ -254,32 +255,6 @@ public:
*/
inline std::string get_tree_texture () const { return tree_texture; }
/**
* Return if the surface material is solid, if it is not solid, a fluid
* can be assumed, that is usually water.
*/
bool get_solid () const { return solid; }
/**
* Get the friction factor for that material
*/
double get_friction_factor () const { return friction_factor; }
/**
* Get the rolling friction for that material
*/
double get_rolling_friction () const { return rolling_friction; }
/**
* Get the bumpines for that material
*/
double get_bumpiness () const { return bumpiness; }
/**
* Get the load resistance
*/
double get_load_resistance () const { return load_resistance; }
/**
* Get the list of names for this material
*/
@ -434,21 +409,6 @@ private:
// Number of varieties of tree texture
int tree_varieties;
// True if the material is solid, false if it is a fluid
bool solid;
// the friction factor of that surface material
double friction_factor;
// the rolling friction of that surface material
double rolling_friction;
// the bumpiness of that surface material
double bumpiness;
// the load resistance of that surface material
double load_resistance;
// material properties
SGVec4f ambient, diffuse, specular, emission;
double shininess;

View File

@ -334,11 +334,11 @@ public:
std::swap(_geometryBuilder, primitiveFunctor._geometryBuilder);
}
void setCurrentMaterial(const SGMaterial* material)
void setCurrentMaterial(const BVHMaterial* material)
{
_geometryBuilder->setCurrentMaterial(material);
}
const SGMaterial* getCurrentMaterial() const
const BVHMaterial* getCurrentMaterial() const
{
return _geometryBuilder->getCurrentMaterial();
}
@ -384,10 +384,10 @@ public:
{
}
const SGMaterial* pushMaterial(osg::Geode* geode)
const BVHMaterial* pushMaterial(osg::Geode* geode)
{
const SGMaterial* oldMaterial = _primitiveFunctor.getCurrentMaterial();
const SGMaterial* material = SGMaterialLib::findMaterial(geode);
const BVHMaterial* oldMaterial = _primitiveFunctor.getCurrentMaterial();
const BVHMaterial* material = SGMaterialLib::findMaterial(geode);
if (material)
_primitiveFunctor.setCurrentMaterial(material);
return oldMaterial;
@ -403,7 +403,7 @@ public:
if (hasBoundingVolumeTree(geode))
return;
const SGMaterial* oldMaterial = pushMaterial(&geode);
const BVHMaterial* oldMaterial = pushMaterial(&geode);
bool flushHere = getNodePath().size() <= 1 || _dumpIntoLeafs;
if (flushHere) {
@ -411,7 +411,7 @@ public:
PFunctor previousPrimitives;
_primitiveFunctor.swap(previousPrimitives);
const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
const BVHMaterial* mat = previousPrimitives.getCurrentMaterial();
_primitiveFunctor.setCurrentMaterial(mat);
// walk the children
@ -458,7 +458,7 @@ public:
PFunctor previousPrimitives;
_primitiveFunctor.swap(previousPrimitives);
const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
const BVHMaterial* mat = previousPrimitives.getCurrentMaterial();
_primitiveFunctor.setCurrentMaterial(mat);
// walk the children