From 4f32039f24c0bbdc304de1d537b609c3ed750113 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 19 Dec 2006 17:30:22 +0000 Subject: [PATCH] =?UTF-8?q?From=20Mathias=20Fr=C3=B6hlich,=20"I=20have=20a?= =?UTF-8?q?=20small=20update=20to=20the=20'non=20convex=20polygon=20detect?= =?UTF-8?q?ion'=20in=20the=20ac3d=20loader=20that=20is=20used=20to=20tell?= =?UTF-8?q?=20if=20tesselation=20is=20required=20or=20if=20we=20will=20bet?= =?UTF-8?q?ter=20leave=20a=20polygon=20as=20is.=20It=20is=20still=20not=20?= =?UTF-8?q?perfect=20but=20catches=20some=20more=20cases."?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/osgPlugins/ac3d/ac3d.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/ac3d/ac3d.cpp b/src/osgPlugins/ac3d/ac3d.cpp index bec58b1c1..a0f4f0f63 100644 --- a/src/osgPlugins/ac3d/ac3d.cpp +++ b/src/osgPlugins/ac3d/ac3d.cpp @@ -769,15 +769,34 @@ class SurfaceBin : public PrimitiveBin { // Compute the normal times the enclosed area. // During that check if the surface is convex. If so, put in the surface as such. bool needTesselation = false; + osg::Vec3 prevEdgeNormal; osg::Vec3 weightedNormal(0, 0, 0); osg::Vec3 v0 = _vertexSet->getVertex(_refs[0].index); for (unsigned i = 2; i < nRefs; ++i) { osg::Vec3 side1 = _vertexSet->getVertex(_refs[i-1].index) - v0; osg::Vec3 side2 = _vertexSet->getVertex(_refs[i].index) - v0; osg::Vec3 newNormal = side1^side2; - if (3 < nRefs && newNormal*weightedNormal < 0) + if (!needTesselation) { - needTesselation = true; + if (3 < nRefs && newNormal*weightedNormal < 0) + { + needTesselation = true; + } + if (i < 3) + { + prevEdgeNormal = newNormal; + } + else // if (3 <= i) // due to the for loop + { + osg::Vec3 sideim1 = _vertexSet->getVertex(_refs[i-1].index) - _vertexSet->getVertex(_refs[i-2].index); + osg::Vec3 sidei = _vertexSet->getVertex(_refs[i].index) - _vertexSet->getVertex(_refs[i-2].index); + osg::Vec3 edgeNormal = sideim1^sidei; + if (edgeNormal*prevEdgeNormal < 0) + { + needTesselation = true; + } + prevEdgeNormal = edgeNormal; + } } weightedNormal += newNormal;