1*464702f4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*464702f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*464702f4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*464702f4SAndrew Rist * distributed with this work for additional information 6*464702f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*464702f4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*464702f4SAndrew Rist * "License"); you may not use this file except in compliance 9*464702f4SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*464702f4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*464702f4SAndrew Rist * software distributed under the License is distributed on an 15*464702f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*464702f4SAndrew Rist * KIND, either express or implied. See the License for the 17*464702f4SAndrew Rist * specific language governing permissions and limitations 18*464702f4SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*464702f4SAndrew Rist *************************************************************/ 21*464702f4SAndrew Rist 22*464702f4SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <drawinglayer/primitive3d/sdrextrudelathetools3d.hxx> 28cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx> 29cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx> 30cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 31cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 32cdf0e10cSrcweir #include <basegfx/point/b3dpoint.hxx> 33cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygon.hxx> 34cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygontools.hxx> 35cdf0e10cSrcweir #include <basegfx/polygon/b3dpolypolygontools.hxx> 36cdf0e10cSrcweir #include <basegfx/range/b3drange.hxx> 37cdf0e10cSrcweir #include <basegfx/matrix/b3dhommatrix.hxx> 38cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 39cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation3d.hxx> 40cdf0e10cSrcweir #include <numeric> 41cdf0e10cSrcweir 42cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 43cdf0e10cSrcweir // decompositon helpers for extrude/lathe (rotation) objects 44cdf0e10cSrcweir 45cdf0e10cSrcweir namespace 46cdf0e10cSrcweir { 47cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 48cdf0e10cSrcweir // common helpers 49cdf0e10cSrcweir 50cdf0e10cSrcweir basegfx::B2DPolyPolygon impScalePolyPolygonOnCenter( 51cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rSource, 52cdf0e10cSrcweir double fScale) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir basegfx::B2DPolyPolygon aRetval(rSource); 55cdf0e10cSrcweir 56cdf0e10cSrcweir if(!basegfx::fTools::equalZero(fScale)) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir const basegfx::B2DRange aRange(basegfx::tools::getRange(rSource)); 59cdf0e10cSrcweir const basegfx::B2DPoint aCenter(aRange.getCenter()); 60cdf0e10cSrcweir basegfx::B2DHomMatrix aTrans; 61cdf0e10cSrcweir 62cdf0e10cSrcweir aTrans.translate(-aCenter.getX(), -aCenter.getY()); 63cdf0e10cSrcweir aTrans.scale(fScale, fScale); 64cdf0e10cSrcweir aTrans.translate(aCenter.getX(), aCenter.getY()); 65cdf0e10cSrcweir aRetval.transform(aTrans); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir return aRetval; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir void impGetOuterPolyPolygon( 72cdf0e10cSrcweir basegfx::B2DPolyPolygon& rPolygon, 73cdf0e10cSrcweir basegfx::B2DPolyPolygon& rOuterPolyPolygon, 74cdf0e10cSrcweir double fOffset, 75cdf0e10cSrcweir bool bCharacterMode) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir rOuterPolyPolygon = rPolygon; 78cdf0e10cSrcweir 79cdf0e10cSrcweir if(basegfx::fTools::more(fOffset, 0.0)) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir if(bCharacterMode) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir // grow the outside polygon and scale all polygons to original size. This is done 84cdf0e10cSrcweir // to avoid a shrink which potentially would lead to self-intersections, but changes 85cdf0e10cSrcweir // the original polygon -> not a precision step, so e.g. not usable for charts 86cdf0e10cSrcweir const basegfx::B2DRange aRange(basegfx::tools::getRange(rPolygon)); 87cdf0e10cSrcweir rPolygon = basegfx::tools::growInNormalDirection(rPolygon, fOffset); 88cdf0e10cSrcweir const basegfx::B2DRange aGrownRange(basegfx::tools::getRange(rPolygon)); 89cdf0e10cSrcweir const double fScaleX(basegfx::fTools::equalZero(aGrownRange.getWidth()) ? 1.0 : aRange.getWidth() / aGrownRange.getWidth()); 90cdf0e10cSrcweir const double fScaleY(basegfx::fTools::equalZero(aGrownRange.getHeight())? 1.0 : aRange.getHeight() / aGrownRange.getHeight()); 91cdf0e10cSrcweir basegfx::B2DHomMatrix aScaleTrans; 92cdf0e10cSrcweir 93cdf0e10cSrcweir aScaleTrans.translate(-aGrownRange.getMinX(), -aGrownRange.getMinY()); 94cdf0e10cSrcweir aScaleTrans.scale(fScaleX, fScaleY); 95cdf0e10cSrcweir aScaleTrans.translate(aRange.getMinX(), aRange.getMinY()); 96cdf0e10cSrcweir rPolygon.transform(aScaleTrans); 97cdf0e10cSrcweir rOuterPolyPolygon.transform(aScaleTrans); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir else 100cdf0e10cSrcweir { 101cdf0e10cSrcweir // use more precision, shrink the outer polygons. Since this may lead to self-intersections, 102cdf0e10cSrcweir // some kind of correction should be applied here after that step 103cdf0e10cSrcweir rOuterPolyPolygon = basegfx::tools::growInNormalDirection(rPolygon, -fOffset); 104cdf0e10cSrcweir basegfx::tools::correctGrowShrinkPolygonPair(rPolygon, rOuterPolyPolygon); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir } 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir void impAddInBetweenFill( 110cdf0e10cSrcweir basegfx::B3DPolyPolygon& rTarget, 111cdf0e10cSrcweir const basegfx::B3DPolyPolygon& rPolA, 112cdf0e10cSrcweir const basegfx::B3DPolyPolygon& rPolB, 113cdf0e10cSrcweir double fTexVerStart, 114cdf0e10cSrcweir double fTexVerStop, 115cdf0e10cSrcweir bool bCreateNormals, 116cdf0e10cSrcweir bool bCreateTextureCoordinates) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir OSL_ENSURE(rPolA.count() == rPolB.count(), "impAddInBetweenFill: unequally sized polygons (!)"); 119cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rPolA.count()); 120cdf0e10cSrcweir 121cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir const basegfx::B3DPolygon aSubA(rPolA.getB3DPolygon(a)); 124cdf0e10cSrcweir const basegfx::B3DPolygon aSubB(rPolB.getB3DPolygon(a)); 125cdf0e10cSrcweir OSL_ENSURE(aSubA.count() == aSubB.count(), "impAddInBetweenFill: unequally sized polygons (!)"); 126cdf0e10cSrcweir const sal_uInt32 nPointCount(aSubA.count()); 127cdf0e10cSrcweir 128cdf0e10cSrcweir if(nPointCount) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir const sal_uInt32 nEdgeCount(aSubA.isClosed() ? nPointCount : nPointCount - 1L); 131cdf0e10cSrcweir double fTexHorMultiplicatorA(0.0), fTexHorMultiplicatorB(0.0); 132cdf0e10cSrcweir double fPolygonPosA(0.0), fPolygonPosB(0.0); 133cdf0e10cSrcweir 134cdf0e10cSrcweir if(bCreateTextureCoordinates) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir const double fPolygonLengthA(basegfx::tools::getLength(aSubA)); 137cdf0e10cSrcweir fTexHorMultiplicatorA = basegfx::fTools::equalZero(fPolygonLengthA) ? 1.0 : 1.0 / fPolygonLengthA; 138cdf0e10cSrcweir 139cdf0e10cSrcweir const double fPolygonLengthB(basegfx::tools::getLength(aSubB)); 140cdf0e10cSrcweir fTexHorMultiplicatorB = basegfx::fTools::equalZero(fPolygonLengthB) ? 1.0 : 1.0 / fPolygonLengthB; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir for(sal_uInt32 b(0L); b < nEdgeCount; b++) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir const sal_uInt32 nIndexA(b); 146cdf0e10cSrcweir const sal_uInt32 nIndexB((b + 1L) % nPointCount); 147cdf0e10cSrcweir 148cdf0e10cSrcweir const basegfx::B3DPoint aStartA(aSubA.getB3DPoint(nIndexA)); 149cdf0e10cSrcweir const basegfx::B3DPoint aEndA(aSubA.getB3DPoint(nIndexB)); 150cdf0e10cSrcweir const basegfx::B3DPoint aStartB(aSubB.getB3DPoint(nIndexA)); 151cdf0e10cSrcweir const basegfx::B3DPoint aEndB(aSubB.getB3DPoint(nIndexB)); 152cdf0e10cSrcweir 153cdf0e10cSrcweir basegfx::B3DPolygon aNew; 154cdf0e10cSrcweir aNew.setClosed(true); 155cdf0e10cSrcweir 156cdf0e10cSrcweir aNew.append(aStartA); 157cdf0e10cSrcweir aNew.append(aStartB); 158cdf0e10cSrcweir aNew.append(aEndB); 159cdf0e10cSrcweir aNew.append(aEndA); 160cdf0e10cSrcweir 161cdf0e10cSrcweir if(bCreateNormals) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir aNew.setNormal(0L, aSubA.getNormal(nIndexA)); 164cdf0e10cSrcweir aNew.setNormal(1L, aSubB.getNormal(nIndexA)); 165cdf0e10cSrcweir aNew.setNormal(2L, aSubB.getNormal(nIndexB)); 166cdf0e10cSrcweir aNew.setNormal(3L, aSubA.getNormal(nIndexB)); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir if(bCreateTextureCoordinates) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir const double fRelTexAL(fPolygonPosA * fTexHorMultiplicatorA); 172cdf0e10cSrcweir const double fEdgeLengthA(basegfx::B3DVector(aEndA - aStartA).getLength()); 173cdf0e10cSrcweir fPolygonPosA += fEdgeLengthA; 174cdf0e10cSrcweir const double fRelTexAR(fPolygonPosA * fTexHorMultiplicatorA); 175cdf0e10cSrcweir 176cdf0e10cSrcweir const double fRelTexBL(fPolygonPosB * fTexHorMultiplicatorB); 177cdf0e10cSrcweir const double fEdgeLengthB(basegfx::B3DVector(aEndB - aStartB).getLength()); 178cdf0e10cSrcweir fPolygonPosB += fEdgeLengthB; 179cdf0e10cSrcweir const double fRelTexBR(fPolygonPosB * fTexHorMultiplicatorB); 180cdf0e10cSrcweir 181cdf0e10cSrcweir aNew.setTextureCoordinate(0L, basegfx::B2DPoint(fRelTexAL, fTexVerStart)); 182cdf0e10cSrcweir aNew.setTextureCoordinate(1L, basegfx::B2DPoint(fRelTexBL, fTexVerStop)); 183cdf0e10cSrcweir aNew.setTextureCoordinate(2L, basegfx::B2DPoint(fRelTexBR, fTexVerStop)); 184cdf0e10cSrcweir aNew.setTextureCoordinate(3L, basegfx::B2DPoint(fRelTexAR, fTexVerStart)); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir rTarget.append(aNew); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir void impSetNormal( 194cdf0e10cSrcweir basegfx::B3DPolyPolygon& rCandidate, 195cdf0e10cSrcweir const basegfx::B3DVector& rNormal) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir basegfx::B3DPolygon aSub(rCandidate.getB3DPolygon(a)); 200cdf0e10cSrcweir 201cdf0e10cSrcweir for(sal_uInt32 b(0L); b < aSub.count(); b++) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir aSub.setNormal(b, rNormal); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir rCandidate.setB3DPolygon(a, aSub); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir void impCreateInBetweenNormals( 211cdf0e10cSrcweir basegfx::B3DPolyPolygon& rPolA, 212cdf0e10cSrcweir basegfx::B3DPolyPolygon& rPolB, 213cdf0e10cSrcweir bool bSmoothHorizontalNormals) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir OSL_ENSURE(rPolA.count() == rPolB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)"); 216cdf0e10cSrcweir 217cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rPolA.count(); a++) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir basegfx::B3DPolygon aSubA(rPolA.getB3DPolygon(a)); 220cdf0e10cSrcweir basegfx::B3DPolygon aSubB(rPolB.getB3DPolygon(a)); 221cdf0e10cSrcweir OSL_ENSURE(aSubA.count() == aSubB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)"); 222cdf0e10cSrcweir const sal_uInt32 nPointCount(aSubA.count()); 223cdf0e10cSrcweir 224cdf0e10cSrcweir if(nPointCount) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir basegfx::B3DPoint aPrevA(aSubA.getB3DPoint(nPointCount - 1L)); 227cdf0e10cSrcweir basegfx::B3DPoint aCurrA(aSubA.getB3DPoint(0L)); 228cdf0e10cSrcweir const bool bClosed(aSubA.isClosed()); 229cdf0e10cSrcweir 230cdf0e10cSrcweir for(sal_uInt32 b(0L); b < nPointCount; b++) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir const sal_uInt32 nIndNext((b + 1L) % nPointCount); 233cdf0e10cSrcweir const basegfx::B3DPoint aNextA(aSubA.getB3DPoint(nIndNext)); 234cdf0e10cSrcweir const basegfx::B3DPoint aCurrB(aSubB.getB3DPoint(b)); 235cdf0e10cSrcweir 236cdf0e10cSrcweir // vector to back 237cdf0e10cSrcweir basegfx::B3DVector aDepth(aCurrB - aCurrA); 238cdf0e10cSrcweir aDepth.normalize(); 239cdf0e10cSrcweir 240cdf0e10cSrcweir if(aDepth.equalZero()) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir // no difference, try to get depth from next point 243cdf0e10cSrcweir const basegfx::B3DPoint aNextB(aSubB.getB3DPoint(nIndNext)); 244cdf0e10cSrcweir aDepth = aNextB - aNextA; 245cdf0e10cSrcweir aDepth.normalize(); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir // vector to left (correct for non-closed lines) 249cdf0e10cSrcweir const bool bFirstAndNotClosed(!bClosed && 0L == b); 250cdf0e10cSrcweir basegfx::B3DVector aLeft(bFirstAndNotClosed ? aCurrA - aNextA : aPrevA - aCurrA); 251cdf0e10cSrcweir aLeft.normalize(); 252cdf0e10cSrcweir 253cdf0e10cSrcweir // create left normal 254cdf0e10cSrcweir const basegfx::B3DVector aNormalLeft(aDepth.getPerpendicular(aLeft)); 255cdf0e10cSrcweir 256cdf0e10cSrcweir if(bSmoothHorizontalNormals) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir // vector to right (correct for non-closed lines) 259cdf0e10cSrcweir const bool bLastAndNotClosed(!bClosed && b + 1L == nPointCount); 260cdf0e10cSrcweir basegfx::B3DVector aRight(bLastAndNotClosed ? aCurrA - aPrevA : aNextA - aCurrA); 261cdf0e10cSrcweir aRight.normalize(); 262cdf0e10cSrcweir 263cdf0e10cSrcweir // create right normal 264cdf0e10cSrcweir const basegfx::B3DVector aNormalRight(aRight.getPerpendicular(aDepth)); 265cdf0e10cSrcweir 266cdf0e10cSrcweir // create smoothed in-between normal 267cdf0e10cSrcweir basegfx::B3DVector aNewNormal(aNormalLeft + aNormalRight); 268cdf0e10cSrcweir aNewNormal.normalize(); 269cdf0e10cSrcweir 270cdf0e10cSrcweir // set as new normal at polygons 271cdf0e10cSrcweir aSubA.setNormal(b, aNewNormal); 272cdf0e10cSrcweir aSubB.setNormal(b, aNewNormal); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir else 275cdf0e10cSrcweir { 276cdf0e10cSrcweir // set aNormalLeft as new normal at polygons 277cdf0e10cSrcweir aSubA.setNormal(b, aNormalLeft); 278cdf0e10cSrcweir aSubB.setNormal(b, aNormalLeft); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir // prepare next step 282cdf0e10cSrcweir aPrevA = aCurrA; 283cdf0e10cSrcweir aCurrA = aNextA; 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir rPolA.setB3DPolygon(a, aSubA); 287cdf0e10cSrcweir rPolB.setB3DPolygon(a, aSubB); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir void impMixNormals( 293cdf0e10cSrcweir basegfx::B3DPolyPolygon& rPolA, 294cdf0e10cSrcweir const basegfx::B3DPolyPolygon& rPolB, 295cdf0e10cSrcweir double fWeightA) 296cdf0e10cSrcweir { 297cdf0e10cSrcweir const double fWeightB(1.0 - fWeightA); 298cdf0e10cSrcweir OSL_ENSURE(rPolA.count() == rPolB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)"); 299cdf0e10cSrcweir 300cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rPolA.count(); a++) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir basegfx::B3DPolygon aSubA(rPolA.getB3DPolygon(a)); 303cdf0e10cSrcweir const basegfx::B3DPolygon aSubB(rPolB.getB3DPolygon(a)); 304cdf0e10cSrcweir OSL_ENSURE(aSubA.count() == aSubB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)"); 305cdf0e10cSrcweir const sal_uInt32 nPointCount(aSubA.count()); 306cdf0e10cSrcweir 307cdf0e10cSrcweir for(sal_uInt32 b(0L); b < nPointCount; b++) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir const basegfx::B3DVector aVA(aSubA.getNormal(b) * fWeightA); 310cdf0e10cSrcweir const basegfx::B3DVector aVB(aSubB.getNormal(b) * fWeightB); 311cdf0e10cSrcweir basegfx::B3DVector aVNew(aVA + aVB); 312cdf0e10cSrcweir aVNew.normalize(); 313cdf0e10cSrcweir aSubA.setNormal(b, aVNew); 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir rPolA.setB3DPolygon(a, aSubA); 317cdf0e10cSrcweir } 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir bool impHasCutWith(const basegfx::B2DPolygon& rPoly, const basegfx::B2DPoint& rStart, const basegfx::B2DPoint& rEnd) 321cdf0e10cSrcweir { 322cdf0e10cSrcweir // polygon is closed, one of the points is a member 323cdf0e10cSrcweir const sal_uInt32 nPointCount(rPoly.count()); 324cdf0e10cSrcweir 325cdf0e10cSrcweir if(nPointCount) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir basegfx::B2DPoint aCurrent(rPoly.getB2DPoint(0)); 328cdf0e10cSrcweir const basegfx::B2DVector aVector(rEnd - rStart); 329cdf0e10cSrcweir 330cdf0e10cSrcweir for(sal_uInt32 a(0); a < nPointCount; a++) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir const sal_uInt32 nNextIndex((a + 1) % nPointCount); 333cdf0e10cSrcweir const basegfx::B2DPoint aNext(rPoly.getB2DPoint(nNextIndex)); 334cdf0e10cSrcweir const basegfx::B2DVector aEdgeVector(aNext - aCurrent); 335cdf0e10cSrcweir 336cdf0e10cSrcweir if(basegfx::tools::findCut( 337cdf0e10cSrcweir rStart, aVector, 338cdf0e10cSrcweir aCurrent, aEdgeVector)) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir return true; 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir aCurrent = aNext; 344cdf0e10cSrcweir } 345cdf0e10cSrcweir } 346cdf0e10cSrcweir 347cdf0e10cSrcweir return false; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir } // end of anonymous namespace 350cdf0e10cSrcweir 351cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 352cdf0e10cSrcweir 353cdf0e10cSrcweir namespace drawinglayer 354cdf0e10cSrcweir { 355cdf0e10cSrcweir namespace primitive3d 356cdf0e10cSrcweir { 357cdf0e10cSrcweir void createLatheSlices( 358cdf0e10cSrcweir Slice3DVector& rSliceVector, 359cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rSource, 360cdf0e10cSrcweir double fBackScale, 361cdf0e10cSrcweir double fDiagonal, 362cdf0e10cSrcweir double fRotation, 363cdf0e10cSrcweir sal_uInt32 nSteps, 364cdf0e10cSrcweir bool bCharacterMode, 365cdf0e10cSrcweir bool bCloseFront, 366cdf0e10cSrcweir bool bCloseBack) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir if(basegfx::fTools::equalZero(fRotation) || 0L == nSteps) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir // no rotation or no steps, just one plane 371cdf0e10cSrcweir rSliceVector.push_back(Slice3D(rSource, basegfx::B3DHomMatrix())); 372cdf0e10cSrcweir } 373cdf0e10cSrcweir else 374cdf0e10cSrcweir { 375cdf0e10cSrcweir const bool bBackScale(!basegfx::fTools::equal(fBackScale, 1.0)); 376cdf0e10cSrcweir const bool bClosedRotation(!bBackScale && basegfx::fTools::equal(fRotation, F_2PI)); 377cdf0e10cSrcweir basegfx::B2DPolyPolygon aFront(rSource); 378cdf0e10cSrcweir basegfx::B2DPolyPolygon aBack(rSource); 379cdf0e10cSrcweir basegfx::B3DHomMatrix aTransformBack; 380cdf0e10cSrcweir basegfx::B2DPolyPolygon aOuterBack; 381cdf0e10cSrcweir 382cdf0e10cSrcweir if(bClosedRotation) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir bCloseFront = bCloseBack = false; 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir if(bBackScale) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir // avoid null zoom 390cdf0e10cSrcweir if(basegfx::fTools::equalZero(fBackScale)) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir fBackScale = 0.000001; 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir // back is scaled compared to front, create scaled version 396cdf0e10cSrcweir aBack = impScalePolyPolygonOnCenter(aBack, fBackScale); 397cdf0e10cSrcweir } 398cdf0e10cSrcweir 399cdf0e10cSrcweir if(bCloseFront || bCloseBack) 400cdf0e10cSrcweir { 401cdf0e10cSrcweir const basegfx::B2DRange aBaseRange(basegfx::tools::getRange(aFront)); 402cdf0e10cSrcweir const double fOuterLength(aBaseRange.getMaxX() * fRotation); 403cdf0e10cSrcweir const double fInnerLength(aBaseRange.getMinX() * fRotation); 404cdf0e10cSrcweir const double fAverageLength((fOuterLength + fInnerLength) * 0.5); 405cdf0e10cSrcweir 406cdf0e10cSrcweir if(bCloseFront) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir const double fOffsetLen((fAverageLength / 12.0) * fDiagonal); 409cdf0e10cSrcweir basegfx::B2DPolyPolygon aOuterFront; 410cdf0e10cSrcweir impGetOuterPolyPolygon(aFront, aOuterFront, fOffsetLen, bCharacterMode); 411cdf0e10cSrcweir basegfx::B3DHomMatrix aTransform; 412cdf0e10cSrcweir aTransform.translate(0.0, 0.0, fOffsetLen); 413cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aOuterFront, aTransform, SLICETYPE3D_FRONTCAP)); 414cdf0e10cSrcweir } 415cdf0e10cSrcweir 416cdf0e10cSrcweir if(bCloseBack) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir const double fOffsetLen((fAverageLength / 12.0) * fDiagonal); 419cdf0e10cSrcweir impGetOuterPolyPolygon(aBack, aOuterBack, fOffsetLen, bCharacterMode); 420cdf0e10cSrcweir aTransformBack.translate(0.0, 0.0, -fOffsetLen); 421cdf0e10cSrcweir aTransformBack.rotate(0.0, fRotation, 0.0); 422cdf0e10cSrcweir } 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir // add start polygon (a = 0L) 426cdf0e10cSrcweir if(!bClosedRotation) 427cdf0e10cSrcweir { 428cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aFront, basegfx::B3DHomMatrix())); 429cdf0e10cSrcweir } 430cdf0e10cSrcweir 431cdf0e10cSrcweir // create segments (a + 1 .. nSteps) 432cdf0e10cSrcweir const double fStepSize(1.0 / (double)nSteps); 433cdf0e10cSrcweir 434cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nSteps; a++) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir const double fStep((double)(a + 1L) * fStepSize); 437cdf0e10cSrcweir basegfx::B2DPolyPolygon aNewPoly(bBackScale ? basegfx::tools::interpolate(aFront, aBack, fStep) : aFront); 438cdf0e10cSrcweir basegfx::B3DHomMatrix aNewMat; 439cdf0e10cSrcweir aNewMat.rotate(0.0, fRotation * fStep, 0.0); 440cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aNewPoly, aNewMat)); 441cdf0e10cSrcweir } 442cdf0e10cSrcweir 443cdf0e10cSrcweir if(bCloseBack) 444cdf0e10cSrcweir { 445cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aOuterBack, aTransformBack, SLICETYPE3D_BACKCAP)); 446cdf0e10cSrcweir } 447cdf0e10cSrcweir } 448cdf0e10cSrcweir } 449cdf0e10cSrcweir 450cdf0e10cSrcweir void createExtrudeSlices( 451cdf0e10cSrcweir Slice3DVector& rSliceVector, 452cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rSource, 453cdf0e10cSrcweir double fBackScale, 454cdf0e10cSrcweir double fDiagonal, 455cdf0e10cSrcweir double fDepth, 456cdf0e10cSrcweir bool bCharacterMode, 457cdf0e10cSrcweir bool bCloseFront, 458cdf0e10cSrcweir bool bCloseBack) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir if(basegfx::fTools::equalZero(fDepth)) 461cdf0e10cSrcweir { 462cdf0e10cSrcweir // no depth, just one plane 463cdf0e10cSrcweir rSliceVector.push_back(Slice3D(rSource, basegfx::B3DHomMatrix())); 464cdf0e10cSrcweir } 465cdf0e10cSrcweir else 466cdf0e10cSrcweir { 467cdf0e10cSrcweir // there is depth, create Polygons for front,back and their default depth positions 468cdf0e10cSrcweir basegfx::B2DPolyPolygon aFront(rSource); 469cdf0e10cSrcweir basegfx::B2DPolyPolygon aBack(rSource); 470cdf0e10cSrcweir const bool bBackScale(!basegfx::fTools::equal(fBackScale, 1.0)); 471cdf0e10cSrcweir double fZFront(fDepth); // default depth for aFront 472cdf0e10cSrcweir double fZBack(0.0); // default depth for aBack 473cdf0e10cSrcweir basegfx::B2DPolyPolygon aOuterBack; 474cdf0e10cSrcweir 475cdf0e10cSrcweir if(bBackScale) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir // avoid null zoom 478cdf0e10cSrcweir if(basegfx::fTools::equalZero(fBackScale)) 479cdf0e10cSrcweir { 480cdf0e10cSrcweir fBackScale = 0.000001; 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir // aFront is scaled compared to aBack, create scaled version 484cdf0e10cSrcweir aFront = impScalePolyPolygonOnCenter(aFront, fBackScale); 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir if(bCloseFront) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir const double fOffset(fDepth * fDiagonal * 0.5); 490cdf0e10cSrcweir fZFront = fDepth - fOffset; 491cdf0e10cSrcweir basegfx::B2DPolyPolygon aOuterFront; 492cdf0e10cSrcweir impGetOuterPolyPolygon(aFront, aOuterFront, fOffset, bCharacterMode); 493cdf0e10cSrcweir basegfx::B3DHomMatrix aTransformFront; 494cdf0e10cSrcweir aTransformFront.translate(0.0, 0.0, fDepth); 495cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aOuterFront, aTransformFront, SLICETYPE3D_FRONTCAP)); 496cdf0e10cSrcweir } 497cdf0e10cSrcweir 498cdf0e10cSrcweir if(bCloseBack) 499cdf0e10cSrcweir { 500cdf0e10cSrcweir const double fOffset(fDepth * fDiagonal * 0.5); 501cdf0e10cSrcweir fZBack = fOffset; 502cdf0e10cSrcweir impGetOuterPolyPolygon(aBack, aOuterBack, fOffset, bCharacterMode); 503cdf0e10cSrcweir } 504cdf0e10cSrcweir 505cdf0e10cSrcweir // add front and back polygons at evtl. changed depths 506cdf0e10cSrcweir { 507cdf0e10cSrcweir basegfx::B3DHomMatrix aTransformA, aTransformB; 508cdf0e10cSrcweir 509cdf0e10cSrcweir aTransformA.translate(0.0, 0.0, fZFront); 510cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aFront, aTransformA)); 511cdf0e10cSrcweir 512cdf0e10cSrcweir aTransformB.translate(0.0, 0.0, fZBack); 513cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aBack, aTransformB)); 514cdf0e10cSrcweir } 515cdf0e10cSrcweir 516cdf0e10cSrcweir if(bCloseBack) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aOuterBack, basegfx::B3DHomMatrix(), SLICETYPE3D_BACKCAP)); 519cdf0e10cSrcweir } 520cdf0e10cSrcweir } 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir basegfx::B3DPolyPolygon extractHorizontalLinesFromSlice(const Slice3DVector& rSliceVector, bool bCloseHorLines) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir basegfx::B3DPolyPolygon aRetval; 526cdf0e10cSrcweir const sal_uInt32 nNumSlices(rSliceVector.size()); 527cdf0e10cSrcweir 528cdf0e10cSrcweir if(nNumSlices) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir const sal_uInt32 nSlideSubPolygonCount(rSliceVector[0].getB3DPolyPolygon().count()); 531cdf0e10cSrcweir 532cdf0e10cSrcweir for(sal_uInt32 b(0); b < nSlideSubPolygonCount; b++) 533cdf0e10cSrcweir { 534cdf0e10cSrcweir const sal_uInt32 nSubPolygonPointCount(rSliceVector[0].getB3DPolyPolygon().getB3DPolygon(b).count()); 535cdf0e10cSrcweir 536cdf0e10cSrcweir for(sal_uInt32 c(0); c < nSubPolygonPointCount; c++) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir basegfx::B3DPolygon aNew; 539cdf0e10cSrcweir 540cdf0e10cSrcweir for(sal_uInt32 d(0); d < nNumSlices; d++) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir OSL_ENSURE(nSlideSubPolygonCount == rSliceVector[d].getB3DPolyPolygon().count(), 543cdf0e10cSrcweir "Slice PolyPolygon with different Polygon count (!)"); 544cdf0e10cSrcweir OSL_ENSURE(nSubPolygonPointCount == rSliceVector[d].getB3DPolyPolygon().getB3DPolygon(b).count(), 545cdf0e10cSrcweir "Slice Polygon with different point count (!)"); 546cdf0e10cSrcweir aNew.append(rSliceVector[d].getB3DPolyPolygon().getB3DPolygon(b).getB3DPoint(c)); 547cdf0e10cSrcweir } 548cdf0e10cSrcweir 549cdf0e10cSrcweir aNew.setClosed(bCloseHorLines); 550cdf0e10cSrcweir aRetval.append(aNew); 551cdf0e10cSrcweir } 552cdf0e10cSrcweir } 553cdf0e10cSrcweir } 554cdf0e10cSrcweir 555cdf0e10cSrcweir return aRetval; 556cdf0e10cSrcweir } 557cdf0e10cSrcweir 558cdf0e10cSrcweir basegfx::B3DPolyPolygon extractVerticalLinesFromSlice(const Slice3DVector& rSliceVector) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir basegfx::B3DPolyPolygon aRetval; 561cdf0e10cSrcweir const sal_uInt32 nNumSlices(rSliceVector.size()); 562cdf0e10cSrcweir 563cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nNumSlices; a++) 564cdf0e10cSrcweir { 565cdf0e10cSrcweir aRetval.append(rSliceVector[a].getB3DPolyPolygon()); 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir return aRetval; 569cdf0e10cSrcweir } 570cdf0e10cSrcweir 571cdf0e10cSrcweir void extractPlanesFromSlice( 572cdf0e10cSrcweir ::std::vector< basegfx::B3DPolyPolygon >& rFill, 573cdf0e10cSrcweir const Slice3DVector& rSliceVector, 574cdf0e10cSrcweir bool bCreateNormals, 575cdf0e10cSrcweir bool bSmoothHorizontalNormals, 576cdf0e10cSrcweir bool bSmoothNormals, 577cdf0e10cSrcweir bool bSmoothLids, 578cdf0e10cSrcweir bool bClosed, 579cdf0e10cSrcweir double fSmoothNormalsMix, 580cdf0e10cSrcweir double fSmoothLidsMix, 581cdf0e10cSrcweir bool bCreateTextureCoordinates, 582cdf0e10cSrcweir const basegfx::B2DHomMatrix& rTexTransform) 583cdf0e10cSrcweir { 584cdf0e10cSrcweir const sal_uInt32 nNumSlices(rSliceVector.size()); 585cdf0e10cSrcweir 586cdf0e10cSrcweir if(nNumSlices) 587cdf0e10cSrcweir { 588cdf0e10cSrcweir // common parameters 589cdf0e10cSrcweir const sal_uInt32 nLoopCount(bClosed ? nNumSlices : nNumSlices - 1L); 590cdf0e10cSrcweir basegfx::B3DPolyPolygon aEdgeRounding; 591cdf0e10cSrcweir sal_uInt32 a; 592cdf0e10cSrcweir 593cdf0e10cSrcweir // tetxture parameters 594cdf0e10cSrcweir double fInvTexHeight(1.0); 595cdf0e10cSrcweir double fTexHeightPos(0.0); 596cdf0e10cSrcweir double fTexStart(0.0); 597cdf0e10cSrcweir double fTexStop(1.0); 598cdf0e10cSrcweir ::std::vector<double> aTexHeightArray; 599cdf0e10cSrcweir basegfx::B3DRange aTexRangeFront; 600cdf0e10cSrcweir basegfx::B3DRange aTexRangeBack; 601cdf0e10cSrcweir 602cdf0e10cSrcweir if(bCreateTextureCoordinates) 603cdf0e10cSrcweir { 604cdf0e10cSrcweir aTexRangeFront = basegfx::tools::getRange(rSliceVector[0L].getB3DPolyPolygon()); 605cdf0e10cSrcweir aTexRangeBack = basegfx::tools::getRange(rSliceVector[nNumSlices - 1L].getB3DPolyPolygon()); 606cdf0e10cSrcweir 607cdf0e10cSrcweir if(aTexRangeBack.getDepth() > aTexRangeBack.getWidth()) 608cdf0e10cSrcweir { 609cdf0e10cSrcweir // last polygon is rotated so that depth is bigger than width, exchange X and Z 610cdf0e10cSrcweir // for making applyDefaultTextureCoordinatesParallel use Z instead of X for 611cdf0e10cSrcweir // horizontal texture coordinate 612cdf0e10cSrcweir aTexRangeBack = basegfx::B3DRange( 613cdf0e10cSrcweir aTexRangeBack.getMinZ(), aTexRangeBack.getMinY(), aTexRangeBack.getMinX(), 614cdf0e10cSrcweir aTexRangeBack.getMaxZ(), aTexRangeBack.getMaxY(), aTexRangeBack.getMaxX()); 615cdf0e10cSrcweir } 616cdf0e10cSrcweir 617cdf0e10cSrcweir basegfx::B3DPoint aCenter(basegfx::tools::getRange(rSliceVector[0L].getB3DPolyPolygon()).getCenter()); 618cdf0e10cSrcweir 619cdf0e10cSrcweir for(a = 0L; a < nLoopCount; a++) 620cdf0e10cSrcweir { 621cdf0e10cSrcweir const basegfx::B3DPoint aNextCenter(basegfx::tools::getRange(rSliceVector[(a + 1L) % nNumSlices].getB3DPolyPolygon()).getCenter()); 622cdf0e10cSrcweir const double fLength(basegfx::B3DVector(aNextCenter - aCenter).getLength()); 623cdf0e10cSrcweir aTexHeightArray.push_back(fLength); 624cdf0e10cSrcweir aCenter = aNextCenter; 625cdf0e10cSrcweir } 626cdf0e10cSrcweir 627cdf0e10cSrcweir const double fTexHeight(::std::accumulate(aTexHeightArray.begin(), aTexHeightArray.end(), 0.0)); 628cdf0e10cSrcweir 629cdf0e10cSrcweir if(!basegfx::fTools::equalZero(fTexHeight)) 630cdf0e10cSrcweir { 631cdf0e10cSrcweir fInvTexHeight = 1.0 / fTexHeight; 632cdf0e10cSrcweir } 633cdf0e10cSrcweir } 634cdf0e10cSrcweir 635cdf0e10cSrcweir if(nLoopCount) 636cdf0e10cSrcweir { 637cdf0e10cSrcweir for(a = 0L; a < nLoopCount; a++) 638cdf0e10cSrcweir { 639cdf0e10cSrcweir const Slice3D& rSliceA(rSliceVector[a]); 640cdf0e10cSrcweir const Slice3D& rSliceB(rSliceVector[(a + 1L) % nNumSlices]); 641cdf0e10cSrcweir const bool bAcceptPair(SLICETYPE3D_REGULAR == rSliceA.getSliceType() && SLICETYPE3D_REGULAR == rSliceB.getSliceType()); 642cdf0e10cSrcweir basegfx::B3DPolyPolygon aPolA(rSliceA.getB3DPolyPolygon()); 643cdf0e10cSrcweir basegfx::B3DPolyPolygon aPolB(rSliceB.getB3DPolyPolygon()); 644cdf0e10cSrcweir 645cdf0e10cSrcweir if(bAcceptPair) 646cdf0e10cSrcweir { 647cdf0e10cSrcweir if(bCreateNormals) 648cdf0e10cSrcweir { 649cdf0e10cSrcweir impCreateInBetweenNormals(aPolB, aPolA, bSmoothHorizontalNormals); 650cdf0e10cSrcweir } 651cdf0e10cSrcweir 652cdf0e10cSrcweir { 653cdf0e10cSrcweir const sal_uInt32 nIndPrev((a + nNumSlices - 1L) % nNumSlices); 654cdf0e10cSrcweir const Slice3D& rSlicePrev(rSliceVector[nIndPrev]); 655cdf0e10cSrcweir basegfx::B3DPolyPolygon aPrev(rSlicePrev.getB3DPolyPolygon()); 656cdf0e10cSrcweir basegfx::B3DPolyPolygon aPolAA(rSliceA.getB3DPolyPolygon()); 657cdf0e10cSrcweir 658cdf0e10cSrcweir if(SLICETYPE3D_FRONTCAP == rSlicePrev.getSliceType()) 659cdf0e10cSrcweir { 660cdf0e10cSrcweir basegfx::B3DPolyPolygon aFront(rSlicePrev.getB3DPolyPolygon()); 661cdf0e10cSrcweir const bool bHasSlant(aPolAA != aPrev); 662cdf0e10cSrcweir 663cdf0e10cSrcweir if(bCreateTextureCoordinates) 664cdf0e10cSrcweir { 665cdf0e10cSrcweir aFront = basegfx::tools::applyDefaultTextureCoordinatesParallel(aFront, aTexRangeFront); 666cdf0e10cSrcweir } 667cdf0e10cSrcweir 668cdf0e10cSrcweir if(bCreateNormals) 669cdf0e10cSrcweir { 670cdf0e10cSrcweir basegfx::B3DVector aNormal(0.0, 0.0, -1.0); 671cdf0e10cSrcweir 672cdf0e10cSrcweir if(aFront.count()) 673cdf0e10cSrcweir { 674cdf0e10cSrcweir aNormal = -aFront.getB3DPolygon(0L).getNormal(); 675cdf0e10cSrcweir } 676cdf0e10cSrcweir 677cdf0e10cSrcweir impSetNormal(aFront, aNormal); 678cdf0e10cSrcweir 679cdf0e10cSrcweir if(bHasSlant) 680cdf0e10cSrcweir { 681cdf0e10cSrcweir impCreateInBetweenNormals(aPolAA, aPrev, bSmoothHorizontalNormals); 682cdf0e10cSrcweir 683cdf0e10cSrcweir if(bSmoothNormals) 684cdf0e10cSrcweir { 685cdf0e10cSrcweir // smooth and copy 686cdf0e10cSrcweir impMixNormals(aPolA, aPolAA, fSmoothNormalsMix); 687cdf0e10cSrcweir aPolAA = aPolA; 688cdf0e10cSrcweir } 689cdf0e10cSrcweir else 690cdf0e10cSrcweir { 691cdf0e10cSrcweir // take over from surface 692cdf0e10cSrcweir aPolAA = aPolA; 693cdf0e10cSrcweir } 694cdf0e10cSrcweir 695cdf0e10cSrcweir if(bSmoothLids) 696cdf0e10cSrcweir { 697cdf0e10cSrcweir // smooth and copy 698cdf0e10cSrcweir impMixNormals(aFront, aPrev, fSmoothLidsMix); 699cdf0e10cSrcweir aPrev = aFront; 700cdf0e10cSrcweir } 701cdf0e10cSrcweir else 702cdf0e10cSrcweir { 703cdf0e10cSrcweir // take over from front 704cdf0e10cSrcweir aPrev = aFront; 705cdf0e10cSrcweir } 706cdf0e10cSrcweir } 707cdf0e10cSrcweir else 708cdf0e10cSrcweir { 709cdf0e10cSrcweir if(bSmoothNormals) 710cdf0e10cSrcweir { 711cdf0e10cSrcweir // smooth 712cdf0e10cSrcweir impMixNormals(aPolA, aFront, fSmoothNormalsMix); 713cdf0e10cSrcweir } 714cdf0e10cSrcweir 715cdf0e10cSrcweir if(bSmoothLids) 716cdf0e10cSrcweir { 717cdf0e10cSrcweir // smooth and copy 718cdf0e10cSrcweir impMixNormals(aFront, aPolA, fSmoothLidsMix); 719cdf0e10cSrcweir aPolA = aFront; 720cdf0e10cSrcweir } 721cdf0e10cSrcweir } 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir if(bHasSlant) 725cdf0e10cSrcweir { 726cdf0e10cSrcweir if(bCreateTextureCoordinates) 727cdf0e10cSrcweir { 728cdf0e10cSrcweir fTexStart = fTexHeightPos * fInvTexHeight; 729cdf0e10cSrcweir fTexStop = (fTexHeightPos - aTexHeightArray[(a + nLoopCount - 1L) % nLoopCount]) * fInvTexHeight; 730cdf0e10cSrcweir } 731cdf0e10cSrcweir 732cdf0e10cSrcweir impAddInBetweenFill(aEdgeRounding, aPolAA, aPrev, fTexStart, fTexStop, bCreateNormals, bCreateTextureCoordinates); 733cdf0e10cSrcweir } 734cdf0e10cSrcweir 735cdf0e10cSrcweir aFront.flip(); 736cdf0e10cSrcweir rFill.push_back(aFront); 737cdf0e10cSrcweir } 738cdf0e10cSrcweir else 739cdf0e10cSrcweir { 740cdf0e10cSrcweir if(bCreateNormals && bSmoothNormals && (nIndPrev != a + 1L)) 741cdf0e10cSrcweir { 742cdf0e10cSrcweir impCreateInBetweenNormals(aPolAA, aPrev, bSmoothHorizontalNormals); 743cdf0e10cSrcweir impMixNormals(aPolA, aPolAA, 0.5); 744cdf0e10cSrcweir } 745cdf0e10cSrcweir } 746cdf0e10cSrcweir } 747cdf0e10cSrcweir 748cdf0e10cSrcweir { 749cdf0e10cSrcweir const sal_uInt32 nIndNext((a + 2L) % nNumSlices); 750cdf0e10cSrcweir const Slice3D& rSliceNext(rSliceVector[nIndNext]); 751cdf0e10cSrcweir basegfx::B3DPolyPolygon aNext(rSliceNext.getB3DPolyPolygon()); 752cdf0e10cSrcweir basegfx::B3DPolyPolygon aPolBB(rSliceB.getB3DPolyPolygon()); 753cdf0e10cSrcweir 754cdf0e10cSrcweir if(SLICETYPE3D_BACKCAP == rSliceNext.getSliceType()) 755cdf0e10cSrcweir { 756cdf0e10cSrcweir basegfx::B3DPolyPolygon aBack(rSliceNext.getB3DPolyPolygon()); 757cdf0e10cSrcweir const bool bHasSlant(aPolBB != aNext); 758cdf0e10cSrcweir 759cdf0e10cSrcweir if(bCreateTextureCoordinates) 760cdf0e10cSrcweir { 761cdf0e10cSrcweir aBack = basegfx::tools::applyDefaultTextureCoordinatesParallel(aBack, aTexRangeBack); 762cdf0e10cSrcweir } 763cdf0e10cSrcweir 764cdf0e10cSrcweir if(bCreateNormals) 765cdf0e10cSrcweir { 766cdf0e10cSrcweir const basegfx::B3DVector aNormal(aBack.count() ? aBack.getB3DPolygon(0L).getNormal() : basegfx::B3DVector(0.0, 0.0, 1.0)); 767cdf0e10cSrcweir impSetNormal(aBack, aNormal); 768cdf0e10cSrcweir 769cdf0e10cSrcweir if(bHasSlant) 770cdf0e10cSrcweir { 771cdf0e10cSrcweir impCreateInBetweenNormals(aNext, aPolBB, bSmoothHorizontalNormals); 772cdf0e10cSrcweir 773cdf0e10cSrcweir if(bSmoothNormals) 774cdf0e10cSrcweir { 775cdf0e10cSrcweir // smooth and copy 776cdf0e10cSrcweir impMixNormals(aPolB, aPolBB, fSmoothNormalsMix); 777cdf0e10cSrcweir aPolBB = aPolB; 778cdf0e10cSrcweir } 779cdf0e10cSrcweir else 780cdf0e10cSrcweir { 781cdf0e10cSrcweir // take over from surface 782cdf0e10cSrcweir aPolBB = aPolB; 783cdf0e10cSrcweir } 784cdf0e10cSrcweir 785cdf0e10cSrcweir if(bSmoothLids) 786cdf0e10cSrcweir { 787cdf0e10cSrcweir // smooth and copy 788cdf0e10cSrcweir impMixNormals(aBack, aNext, fSmoothLidsMix); 789cdf0e10cSrcweir aNext = aBack; 790cdf0e10cSrcweir } 791cdf0e10cSrcweir else 792cdf0e10cSrcweir { 793cdf0e10cSrcweir // take over from back 794cdf0e10cSrcweir aNext = aBack; 795cdf0e10cSrcweir } 796cdf0e10cSrcweir } 797cdf0e10cSrcweir else 798cdf0e10cSrcweir { 799cdf0e10cSrcweir if(bSmoothNormals) 800cdf0e10cSrcweir { 801cdf0e10cSrcweir // smooth 802cdf0e10cSrcweir impMixNormals(aPolB, aBack, fSmoothNormalsMix); 803cdf0e10cSrcweir } 804cdf0e10cSrcweir 805cdf0e10cSrcweir if(bSmoothLids) 806cdf0e10cSrcweir { 807cdf0e10cSrcweir // smooth and copy 808cdf0e10cSrcweir impMixNormals(aBack, aPolB, fSmoothLidsMix); 809cdf0e10cSrcweir aPolB = aBack; 810cdf0e10cSrcweir } 811cdf0e10cSrcweir } 812cdf0e10cSrcweir } 813cdf0e10cSrcweir 814cdf0e10cSrcweir if(bHasSlant) 815cdf0e10cSrcweir { 816cdf0e10cSrcweir if(bCreateTextureCoordinates) 817cdf0e10cSrcweir { 818cdf0e10cSrcweir fTexStart = (fTexHeightPos + aTexHeightArray[a] + aTexHeightArray[(a + 1L) % nLoopCount]) * fInvTexHeight; 819cdf0e10cSrcweir fTexStop = (fTexHeightPos + aTexHeightArray[a]) * fInvTexHeight; 820cdf0e10cSrcweir } 821cdf0e10cSrcweir 822cdf0e10cSrcweir impAddInBetweenFill(aEdgeRounding, aNext, aPolBB, fTexStart, fTexStop, bCreateNormals, bCreateTextureCoordinates); 823cdf0e10cSrcweir } 824cdf0e10cSrcweir 825cdf0e10cSrcweir rFill.push_back(aBack); 826cdf0e10cSrcweir } 827cdf0e10cSrcweir else 828cdf0e10cSrcweir { 829cdf0e10cSrcweir if(bCreateNormals && bSmoothNormals && (nIndNext != a)) 830cdf0e10cSrcweir { 831cdf0e10cSrcweir impCreateInBetweenNormals(aNext, aPolBB, bSmoothHorizontalNormals); 832cdf0e10cSrcweir impMixNormals(aPolB, aPolBB, 0.5); 833cdf0e10cSrcweir } 834cdf0e10cSrcweir } 835cdf0e10cSrcweir } 836cdf0e10cSrcweir 837cdf0e10cSrcweir if(bCreateTextureCoordinates) 838cdf0e10cSrcweir { 839cdf0e10cSrcweir fTexStart = (fTexHeightPos + aTexHeightArray[a]) * fInvTexHeight; 840cdf0e10cSrcweir fTexStop = fTexHeightPos * fInvTexHeight; 841cdf0e10cSrcweir } 842cdf0e10cSrcweir 843cdf0e10cSrcweir impAddInBetweenFill(aEdgeRounding, aPolB, aPolA, fTexStart, fTexStop, bCreateNormals, bCreateTextureCoordinates); 844cdf0e10cSrcweir } 845cdf0e10cSrcweir 846cdf0e10cSrcweir if(bCreateTextureCoordinates) 847cdf0e10cSrcweir { 848cdf0e10cSrcweir fTexHeightPos += aTexHeightArray[a]; 849cdf0e10cSrcweir } 850cdf0e10cSrcweir } 851cdf0e10cSrcweir } 852cdf0e10cSrcweir else 853cdf0e10cSrcweir { 854cdf0e10cSrcweir // no loop, but a single slice (1 == nNumSlices), create a filling from the single 855cdf0e10cSrcweir // front plane 856cdf0e10cSrcweir const Slice3D& rSlice(rSliceVector[0]); 857cdf0e10cSrcweir basegfx::B3DPolyPolygon aFront(rSlice.getB3DPolyPolygon()); 858cdf0e10cSrcweir 859cdf0e10cSrcweir if(bCreateTextureCoordinates) 860cdf0e10cSrcweir { 861cdf0e10cSrcweir aFront = basegfx::tools::applyDefaultTextureCoordinatesParallel(aFront, aTexRangeFront); 862cdf0e10cSrcweir } 863cdf0e10cSrcweir 864cdf0e10cSrcweir if(bCreateNormals) 865cdf0e10cSrcweir { 866cdf0e10cSrcweir basegfx::B3DVector aNormal(0.0, 0.0, -1.0); 867cdf0e10cSrcweir 868cdf0e10cSrcweir if(aFront.count()) 869cdf0e10cSrcweir { 870cdf0e10cSrcweir aNormal = -aFront.getB3DPolygon(0L).getNormal(); 871cdf0e10cSrcweir } 872cdf0e10cSrcweir 873cdf0e10cSrcweir impSetNormal(aFront, aNormal); 874cdf0e10cSrcweir } 875cdf0e10cSrcweir 876cdf0e10cSrcweir aFront.flip(); 877cdf0e10cSrcweir rFill.push_back(aFront); 878cdf0e10cSrcweir } 879cdf0e10cSrcweir 880cdf0e10cSrcweir if(bCreateTextureCoordinates) 881cdf0e10cSrcweir { 882cdf0e10cSrcweir aEdgeRounding.transformTextureCoordiantes(rTexTransform); 883cdf0e10cSrcweir } 884cdf0e10cSrcweir 885cdf0e10cSrcweir for(a = 0L; a < aEdgeRounding.count(); a++) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir rFill.push_back(basegfx::B3DPolyPolygon(aEdgeRounding.getB3DPolygon(a))); 888cdf0e10cSrcweir } 889cdf0e10cSrcweir } 890cdf0e10cSrcweir } 891cdf0e10cSrcweir 892cdf0e10cSrcweir void createReducedOutlines( 893cdf0e10cSrcweir const geometry::ViewInformation3D& rViewInformation, 894cdf0e10cSrcweir const basegfx::B3DHomMatrix& rObjectTransform, 895cdf0e10cSrcweir const basegfx::B3DPolygon& rLoopA, 896cdf0e10cSrcweir const basegfx::B3DPolygon& rLoopB, 897cdf0e10cSrcweir basegfx::B3DPolyPolygon& rTarget) 898cdf0e10cSrcweir { 899cdf0e10cSrcweir const sal_uInt32 nPointCount(rLoopA.count()); 900cdf0e10cSrcweir 901cdf0e10cSrcweir // with idetic polygons there are no outlines 902cdf0e10cSrcweir if(rLoopA != rLoopB) 903cdf0e10cSrcweir { 904cdf0e10cSrcweir if(nPointCount && nPointCount == rLoopB.count()) 905cdf0e10cSrcweir { 906cdf0e10cSrcweir const basegfx::B3DHomMatrix aObjectTransform(rViewInformation.getObjectToView() * rObjectTransform); 907cdf0e10cSrcweir const basegfx::B2DPolygon a2DLoopA(basegfx::tools::createB2DPolygonFromB3DPolygon(rLoopA, aObjectTransform)); 908cdf0e10cSrcweir const basegfx::B2DPolygon a2DLoopB(basegfx::tools::createB2DPolygonFromB3DPolygon(rLoopB, aObjectTransform)); 909cdf0e10cSrcweir const basegfx::B2DPoint a2DCenterA(a2DLoopA.getB2DRange().getCenter()); 910cdf0e10cSrcweir const basegfx::B2DPoint a2DCenterB(a2DLoopB.getB2DRange().getCenter()); 911cdf0e10cSrcweir 912cdf0e10cSrcweir // without detectable Y-Axis there are no outlines 913cdf0e10cSrcweir if(!a2DCenterA.equal(a2DCenterB)) 914cdf0e10cSrcweir { 915cdf0e10cSrcweir // search for outmost left and right inter-loop-edges which do not cut the loops 916cdf0e10cSrcweir const basegfx::B2DPoint aCommonCenter(basegfx::average(a2DCenterA, a2DCenterB)); 917cdf0e10cSrcweir const basegfx::B2DVector aAxisVector(a2DCenterA - a2DCenterB); 918cdf0e10cSrcweir double fMaxLeft(0.0); 919cdf0e10cSrcweir double fMaxRight(0.0); 920cdf0e10cSrcweir sal_uInt32 nIndexLeft(0); 921cdf0e10cSrcweir sal_uInt32 nIndexRight(0); 922cdf0e10cSrcweir 923cdf0e10cSrcweir for(sal_uInt32 a(0); a < nPointCount; a++) 924cdf0e10cSrcweir { 925cdf0e10cSrcweir const basegfx::B2DPoint aStart(a2DLoopA.getB2DPoint(a)); 926cdf0e10cSrcweir const basegfx::B2DPoint aEnd(a2DLoopB.getB2DPoint(a)); 927cdf0e10cSrcweir const basegfx::B2DPoint aMiddle(basegfx::average(aStart, aEnd)); 928cdf0e10cSrcweir 929cdf0e10cSrcweir if(!basegfx::tools::isInside(a2DLoopA, aMiddle)) 930cdf0e10cSrcweir { 931cdf0e10cSrcweir if(!basegfx::tools::isInside(a2DLoopB, aMiddle)) 932cdf0e10cSrcweir { 933cdf0e10cSrcweir if(!impHasCutWith(a2DLoopA, aStart, aEnd)) 934cdf0e10cSrcweir { 935cdf0e10cSrcweir if(!impHasCutWith(a2DLoopB, aStart, aEnd)) 936cdf0e10cSrcweir { 937cdf0e10cSrcweir const basegfx::B2DVector aCandidateVector(aMiddle - aCommonCenter); 938cdf0e10cSrcweir const double fCross(aCandidateVector.cross(aAxisVector)); 939cdf0e10cSrcweir const double fDistance(aCandidateVector.getLength()); 940cdf0e10cSrcweir 941cdf0e10cSrcweir if(fCross > 0.0) 942cdf0e10cSrcweir { 943cdf0e10cSrcweir if(fDistance > fMaxLeft) 944cdf0e10cSrcweir { 945cdf0e10cSrcweir fMaxLeft = fDistance; 946cdf0e10cSrcweir nIndexLeft = a; 947cdf0e10cSrcweir } 948cdf0e10cSrcweir } 949cdf0e10cSrcweir else if(fCross < 0.0) 950cdf0e10cSrcweir { 951cdf0e10cSrcweir if(fDistance > fMaxRight) 952cdf0e10cSrcweir { 953cdf0e10cSrcweir fMaxRight = fDistance; 954cdf0e10cSrcweir nIndexRight = a; 955cdf0e10cSrcweir } 956cdf0e10cSrcweir } 957cdf0e10cSrcweir } 958cdf0e10cSrcweir } 959cdf0e10cSrcweir } 960cdf0e10cSrcweir } 961cdf0e10cSrcweir } 962cdf0e10cSrcweir 963cdf0e10cSrcweir if(fMaxLeft != 0.0) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir basegfx::B3DPolygon aToBeAdded; 966cdf0e10cSrcweir aToBeAdded.append(rLoopA.getB3DPoint(nIndexLeft)); 967cdf0e10cSrcweir aToBeAdded.append(rLoopB.getB3DPoint(nIndexLeft)); 968cdf0e10cSrcweir rTarget.append(aToBeAdded); 969cdf0e10cSrcweir } 970cdf0e10cSrcweir 971cdf0e10cSrcweir if(fMaxRight != 0.0) 972cdf0e10cSrcweir { 973cdf0e10cSrcweir basegfx::B3DPolygon aToBeAdded; 974cdf0e10cSrcweir aToBeAdded.append(rLoopA.getB3DPoint(nIndexRight)); 975cdf0e10cSrcweir aToBeAdded.append(rLoopB.getB3DPoint(nIndexRight)); 976cdf0e10cSrcweir rTarget.append(aToBeAdded); 977cdf0e10cSrcweir } 978cdf0e10cSrcweir } 979cdf0e10cSrcweir } 980cdf0e10cSrcweir } 981cdf0e10cSrcweir } 982cdf0e10cSrcweir 983cdf0e10cSrcweir } // end of namespace primitive3d 984cdf0e10cSrcweir } // end of namespace drawinglayer 985cdf0e10cSrcweir 986cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 987cdf0e10cSrcweir // eof 988