Removed usage of the osgUtil::TriStripVisitor is it generates osg::Geometry that perform very poorly when using VBO and VAO's vs GL DisplayLists.

With DisplayLists being deprecated in GL and VBO and VAO becoming standard it's best to standardize on using the osgUtil::MeshOptimizers instead of TripStrupVisitor
This commit is contained in:
Robert Osfield 2018-04-20 11:42:31 +01:00
parent f1593c38d9
commit 6863cdee9a
16 changed files with 24 additions and 207 deletions

View File

@ -393,8 +393,6 @@ public:
while (arguments.read("--dl")) { modifyDrawableSettings = true; useDisplayLists = true; }
while (arguments.read("-s", simplificatioRatio)) {}
while (arguments.read("--tristripper")) { useTriStripVisitor=true; }
while (arguments.read("--no-tristripper")) { useTriStripVisitor=false; }
while (arguments.read("--smoother")) { useSmoothingVisitor=true; }
while (arguments.read("--no-smoother")) { useSmoothingVisitor=false; }
@ -426,7 +424,6 @@ public:
OSG_NOTICE<<"Running simplifier with simplification ratio="<<simplificatioRatio<<std::endl;
float maxError = 4.0f;
osgUtil::Simplifier simplifier(simplificatioRatio, maxError);
simplifier.setDoTriStrip(useTriStripVisitor);
simplifier.setSmoothing(useSmoothingVisitor);
node->accept(simplifier);
}

View File

@ -17,8 +17,6 @@
#include <osgDB/FileNameUtils>
#include <osgDB/ReadFile>
#include <osgUtil/TriStripVisitor>
//MIKEC debug only for PrintVisitor
#include <osg/NodeVisitor>
@ -1139,10 +1137,6 @@ osg::Drawable* ReaderWriter3DS::ReaderObject::createDrawable(Lib3dsMesh *m,FaceL
} else {
fillTriangles<DrawElementsUInt> (*geom, remappedFaces, faceCount * 3);
}
#if 0
osgUtil::TriStripVisitor tsv;
tsv.stripify(*geom);
#endif
return geom;
}

View File

@ -74,7 +74,6 @@
#include<osg/PrimitiveSet>
#include <osg/MatrixTransform>
#include <osgUtil/TriStripVisitor>
#include <osgUtil/SmoothingVisitor>
//#define _LOG_DEBUG_

View File

@ -47,8 +47,6 @@
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgUtil/TriStripVisitor>
/// \class ReaderWritterOpenCASCADE
/// \brief contains implementation of reading IGES models
/// depends on OpenCascade library

View File

@ -1,7 +1,7 @@
#include <stdlib.h>
#include <osg/Geode>
#include <osgUtil/TriStripVisitor>
#include <osgUtil/MeshOptimizers>
#include "VBSPGeometry.h"
@ -653,9 +653,7 @@ ref_ptr<Group> VBSPGeometry::createGeometry()
// Now, stripify the geode to convert the POLYGON primitives to
// triangle strips
osgUtil::TriStripVisitor tsv;
geode->accept(tsv);
tsv.stripify();
osgUtil::optimizeMesh(geode);
}
// Now do the same for the displacement surfaces (if any)

View File

@ -9,7 +9,6 @@
#include <osg/TexGen>
#include <osg/TexEnvCombine>
#include <osgUtil/TriStripVisitor>
#include <osgUtil/Tessellator>
#include <osgDB/ReadFile>

View File

@ -12,7 +12,6 @@ SET(TARGET_SRC
RigAttributesVisitor.cpp
TriangleMeshSmoother.cpp
TangentSpaceVisitor.cpp
TriangleStripVisitor.cpp
IndexMeshVisitor.cpp
UnIndexMeshVisitor.cpp)
@ -49,7 +48,6 @@ SET(TARGET_H
TangentSpaceVisitor
TriangleMeshGraph
TriangleMeshSmoother
TriangleStripVisitor
UnIndexMeshVisitor
WireframeVisitor
)

View File

@ -34,7 +34,6 @@
#include "RemapGeometryVisitor"
#include "SmoothNormalVisitor"
#include "TangentSpaceVisitor"
#include "TriangleStripVisitor"
#include "UnIndexMeshVisitor"
#include "WireframeVisitor"
@ -51,14 +50,12 @@ public:
OpenGLESGeometryOptimizer() :
_mode("all"),
_useDrawArray(false),
_disableTriStrip(false),
_disableMeshOptimization(false),
_disableMergeTriStrip(false),
_disablePreTransform(false),
_disableAnimation(false),
_disableAnimationCleaning(false),
_enableAABBonBone(false),
_triStripCacheSize(16),
_triStripMinSize(2),
_generateTangentSpace(false),
_tangentUnit(0),
_maxIndexValue(65535),
@ -74,14 +71,12 @@ public:
void setMode(const std::string& mode) { _mode = mode; }
void setUseDrawArray(bool s) { _useDrawArray = s; }
void setDisableTriStrip(bool s) { _disableTriStrip = s; }
void setDisableMeshOptimization(bool s) { _disableMeshOptimization = s; }
void setDisableMergeTriStrip(bool s) { _disableMergeTriStrip = s; }
void setDisablePreTransform(bool s) { _disablePreTransform = s; }
void setDisableAnimation(bool s) { _disableAnimation = s; }
void setDisableAnimationCleaning(bool s) { _disableAnimationCleaning = s; }
void setEnableAABBonBone(bool s) { _enableAABBonBone = s; }
void setTripStripCacheSize(unsigned int size) { _triStripCacheSize = size; }
void setTripStripMinSize(unsigned int size) { _triStripMinSize = std::max<unsigned int>(size, 2); }
void setExportNonGeometryDrawables(bool value) { _exportNonGeometryDrawables = value; }
void setTexCoordChannelForTangentSpace(int uv) {
_tangentUnit = uv;
@ -93,7 +88,7 @@ public:
_wireframe = s;
if(_wireframe == std::string("outline")) {
// no use to build strip if we only want wireframe
setDisableTriStrip(true);
setDisableMeshOptimization(true);
}
}
void setMaxMorphTarget(unsigned int maxMorphTarget) {
@ -193,9 +188,8 @@ protected:
node->accept(remapper);
}
void makeTriStrip(osg::Node* node) {
TriangleStripVisitor strip(_triStripCacheSize, _triStripMinSize, !_disableMergeTriStrip);
node->accept(strip);
void makeOptimizeMesh(osg::Node* node) {
osgUtil::optimizeMesh(node);
}
void makeDrawArray(osg::Node* node) {
@ -226,14 +220,12 @@ protected:
std::string _mode;
bool _useDrawArray;
bool _disableTriStrip;
bool _disableMeshOptimization;
bool _disableMergeTriStrip;
bool _disablePreTransform;
bool _disableAnimation;
bool _disableAnimationCleaning;
bool _enableAABBonBone;
unsigned int _triStripCacheSize;
unsigned int _triStripMinSize;
bool _generateTangentSpace;
int _tangentUnit;

View File

@ -46,8 +46,8 @@ osg::Node* OpenGLESGeometryOptimizer::optimize(osg::Node& node) {
}
// strip
if(!_disableTriStrip) {
makeTriStrip(model.get());
if(!_disableMeshOptimization) {
makeOptimizeMesh(model.get());
}
if(_useDrawArray) {

View File

@ -40,14 +40,12 @@ public:
std::string enableWireframe;
bool generateTangentSpace;
int tangentSpaceTextureUnit;
bool disableTriStrip;
bool disableMeshOptimization;
bool disableMergeTriStrip;
bool disablePreTransform;
bool disableAnimation;
bool disableAnimationCleaning;
bool enableAABBonBone;
unsigned int triStripCacheSize;
unsigned int triStripMinSize;
bool useDrawArray;
bool disableIndex;
unsigned int maxIndexValue;
@ -59,14 +57,12 @@ public:
enableWireframe = "";
generateTangentSpace = false;
tangentSpaceTextureUnit = 0;
disableTriStrip = false;
disableMeshOptimization = false;
disableMergeTriStrip = false;
disablePreTransform = false;
disableAnimation = false;
disableAnimationCleaning = false;
enableAABBonBone = false;
triStripCacheSize = 16;
triStripMinSize = 2;
useDrawArray = false;
disableIndex = false;
maxIndexValue = 0;
@ -84,10 +80,8 @@ public:
supportsOption("enableWireframe[=inline]","create a wireframe geometry for each triangles geometry. The wire geometry will be stored along the solid geometry if 'inline' is specified.");
supportsOption("generateTangentSpace","Build tangent space to each geometry");
supportsOption("tangentSpaceTextureUnit=<unit>","Specify on which texture unit normal map is");
supportsOption("triStripCacheSize=<int>","set the cache size when doing tristrip");
supportsOption("triStripMinSize=<int>","set the minimum accepted length for a strip");
supportsOption("disableMergeTriStrip","disable the merge of all tristrip into one");
supportsOption("disableTriStrip","disable generation of tristrip");
supportsOption("disableMeshOptimization","disable mesh optimization");
supportsOption("disablePreTransform","disable pre-transform of geometries after split");
supportsOption("disableAnimation","disable animation support");
supportsOption("disableAnimationCleaning","disable animations/channels cleaning");
@ -114,9 +108,7 @@ public:
optimizer.setMode(options.glesMode);
optimizer.setUseDrawArray(options.useDrawArray);
optimizer.setTripStripCacheSize(options.triStripCacheSize);
optimizer.setTripStripMinSize(options.triStripMinSize);
optimizer.setDisableTriStrip(options.disableTriStrip);
optimizer.setDisableMeshOptimization(options.disableMeshOptimization);
optimizer.setDisableMergeTriStrip(options.disableMergeTriStrip);
optimizer.setDisablePreTransform(options.disablePreTransform);
optimizer.setDisableAnimation(options.disableAnimation);
@ -260,9 +252,9 @@ public:
{
localOptions.enableAABBonBone = true;
}
if (pre_equals == "disableTriStrip")
if (pre_equals == "disableMeshOptimization")
{
localOptions.disableTriStrip = true;
localOptions.disableMeshOptimization = true;
}
if (pre_equals == "generateTangentSpace")
{
@ -280,12 +272,6 @@ public:
if (pre_equals == "tangentSpaceTextureUnit") {
localOptions.tangentSpaceTextureUnit = atoi(post_equals.c_str());
}
if (pre_equals == "triStripCacheSize") {
localOptions.triStripCacheSize = atoi(post_equals.c_str());
}
if (pre_equals == "triStripMinSize") {
localOptions.triStripMinSize = atoi(post_equals.c_str());
}
if (pre_equals == "maxIndexValue") {
localOptions.maxIndexValue = atoi(post_equals.c_str());
}

View File

@ -1,35 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) Cedric Pinson
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commercial and non commercial
* applications, as long as this copyright notice is maintained.
*
* This application 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.
*
*/
#ifndef TRIANGLE_STRIP_VISITOR_H
#define TRIANGLE_STRIP_VISITOR_H
#include "GeometryUniqueVisitor"
class TriangleStripVisitor : public GeometryUniqueVisitor {
public:
TriangleStripVisitor(unsigned int cacheSize, unsigned int minSize, bool merge):
GeometryUniqueVisitor("TriangleStripVisitor"),
_cacheSize(cacheSize), _minSize(minSize), _merge(merge)
{}
void process(osg::Geometry& geometry);
protected:
void mergeTrianglesStrip(osg::Geometry& geometry);
unsigned int _cacheSize;
unsigned int _minSize;
bool _merge;
};
#endif

View File

@ -1,98 +0,0 @@
#include <osgUtil/TriStripVisitor>
#include "TriangleStripVisitor"
void TriangleStripVisitor::process(osg::Geometry& geometry) {
osgUtil::TriStripVisitor tristrip;
tristrip.setCacheSize(_cacheSize);
tristrip.setMinStripSize(_minSize);
tristrip.setIndexMesh(false);
tristrip.stripify(geometry);
// merge stritrip to one using degenerated triangles as glue
if (_merge) {
mergeTrianglesStrip(geometry);
}
}
void TriangleStripVisitor::mergeTrianglesStrip(osg::Geometry& geometry)
{
int nbtristrip = 0;
int nbtristripVertexes = 0;
for (unsigned int i = 0; i < geometry.getNumPrimitiveSets(); i++) {
osg::PrimitiveSet* ps = geometry.getPrimitiveSet(i);
osg::DrawElements* de = ps->getDrawElements();
if (de && de->getMode() == osg::PrimitiveSet::TRIANGLE_STRIP) {
nbtristrip++;
nbtristripVertexes += de->getNumIndices();
}
}
if (nbtristrip > 0) {
osg::notify(osg::NOTICE) << "found " << nbtristrip << " tristrip, "
<< "total vertexes " << nbtristripVertexes
<< " should result to " << nbtristripVertexes + nbtristrip*2
<< " after connection" << std::endl;
osg::DrawElementsUShort* ndw = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP);
for (unsigned int i = 0 ; i < geometry.getNumPrimitiveSets() ; ++ i) {
osg::PrimitiveSet* ps = geometry.getPrimitiveSet(i);
if (ps && ps->getMode() == osg::PrimitiveSet::TRIANGLE_STRIP) {
osg::DrawElements* de = ps->getDrawElements();
if (de) {
// if connection needed insert degenerate triangles
if (ndw->getNumIndices() != 0 && ndw->back() != de->getElement(0)) {
// duplicate last vertex
ndw->addElement(ndw->back());
// insert first vertex of next strip
ndw->addElement(de->getElement(0));
}
if (ndw->getNumIndices() % 2 != 0 ) {
// add a dummy vertex to reverse the strip
ndw->addElement(de->getElement(0));
}
for (unsigned int j = 0; j < de->getNumIndices(); j++) {
ndw->addElement(de->getElement(j));
}
}
else if (ps->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) {
// trip strip can generate drawarray of 5 elements we want to merge them too
osg::DrawArrays* da = dynamic_cast<osg::DrawArrays*> (ps);
if (da)
{
// if connection needed insert degenerate triangles
if (ndw->getNumIndices() != 0 && ndw->back() != da->getFirst()) {
// duplicate last vertex
ndw->addElement(ndw->back());
// insert first vertex of next strip
ndw->addElement(da->getFirst());
}
if (ndw->getNumIndices() % 2 != 0 ) {
// add a dummy vertex to reverse the strip
ndw->addElement(da->getFirst());
}
for (unsigned int j = 0; j < da->getNumIndices(); j++) {
ndw->addElement(da->getFirst() + j);
}
}
}
}
}
for (int i = geometry.getNumPrimitiveSets() - 1 ; i >= 0 ; -- i) {
osg::PrimitiveSet* ps = geometry.getPrimitiveSet(i);
// remove null primitive sets and all primitives that have been merged
// (i.e. all TRIANGLE_STRIP DrawElements and DrawArrays)
if (!ps || (ps && ps->getMode() == osg::PrimitiveSet::TRIANGLE_STRIP)) {
geometry.getPrimitiveSetList().erase(geometry.getPrimitiveSetList().begin() + i);
}
}
geometry.getPrimitiveSetList().insert(geometry.getPrimitiveSetList().begin(), ndw);
}
}

View File

@ -159,7 +159,7 @@ namespace glesUtil {
};
// Compact the vertex attribute arrays. Also stolen from TriStripVisitor
// Compact the vertex attribute arrays.
class RemapArray : public osg::ArrayVisitor
{
public:
@ -229,7 +229,7 @@ namespace glesUtil {
// Compare vertices in a mesh using all their attributes. The vertices
// are identified by their index. Extracted from TriStripVisitor.cpp
// are identified by their index.
struct VertexAttribComparitor : public GeometryArrayGatherer
{
VertexAttribComparitor(osg::Geometry& geometry) : GeometryArrayGatherer(geometry)
@ -259,8 +259,7 @@ namespace glesUtil {
// Move the values in an array to new positions, based on the
// remapping table. remapping[i] contains element i's new position, if
// any. Unlike RemapArray in TriStripVisitor, this code doesn't
// assume that elements only move downward in the array.
// any.
class Remapper : public osg::ArrayVisitor
{
public:

View File

@ -42,7 +42,6 @@
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osgUtil/TriStripVisitor>
#include <osgUtil/MeshOptimizers>
#include <osgUtil/SmoothingVisitor>
#include <osgUtil/Tessellator>
@ -798,14 +797,7 @@ osg::Node* ReaderWriterOBJ::convertModelToSceneGraph(obj::Model& model, ObjOptio
// tri strip polygons to improve graphics peformance
if (!localOptions.noTriStripPolygons)
{
osgUtil::IndexMeshVisitor imv;
imv.makeMesh(*geometry);
osgUtil::VertexCacheVisitor vcv;
vcv.optimizeVertices(*geometry);
osgUtil::VertexAccessOrderVisitor vaov;
vaov.optimizeOrder(*geometry);
osgUtil::optimizeMesh(geometry);
}
// if no normals present add them.

View File

@ -32,7 +32,7 @@
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgUtil/TriStripVisitor>
#include <osgUtil/MeshOptimizers>
#include <osgUtil/SmoothingVisitor>
#include <osg/TriangleFunctor>
@ -182,8 +182,7 @@ private:
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, _numFacets * 3));
if(!_noTriStripPolygons) {
osgUtil::TriStripVisitor tristripper;
tristripper.stripify(*geom);
osgUtil::optimizeMesh(geom);
}
return geom;

View File

@ -16,7 +16,7 @@
#include <osgUtil/Simplifier>
#include <osgUtil/SmoothingVisitor>
#include <osgUtil/TriStripVisitor>
#include <osgUtil/MeshOptimizers>
#include <set>
#include <list>
@ -1802,8 +1802,7 @@ void Simplifier::simplify(osg::Geometry& geometry, const IndexList& protectedPoi
if (_triStrip)
{
osgUtil::TriStripVisitor stripper;
stripper.stripify(geometry);
osgUtil::optimizeMesh(&geometry);
}
}