1464702f4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3464702f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4464702f4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5464702f4SAndrew Rist * distributed with this work for additional information 6464702f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7464702f4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8464702f4SAndrew Rist * "License"); you may not use this file except in compliance 9464702f4SAndrew Rist * with the License. You may obtain a copy of the License at 10464702f4SAndrew Rist * 11464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12464702f4SAndrew Rist * 13464702f4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14464702f4SAndrew Rist * software distributed under the License is distributed on an 15464702f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16464702f4SAndrew Rist * KIND, either express or implied. See the License for the 17464702f4SAndrew Rist * specific language governing permissions and limitations 18464702f4SAndrew Rist * under the License. 19464702f4SAndrew Rist * 20464702f4SAndrew Rist *************************************************************/ 21464702f4SAndrew Rist 22464702f4SAndrew 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 impScalePolyPolygonOnCenter(const basegfx::B2DPolyPolygon & rSource,double fScale)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 impGetOuterPolyPolygon(basegfx::B2DPolyPolygon & rPolygon,basegfx::B2DPolyPolygon & rOuterPolyPolygon,double fOffset,bool bCharacterMode)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 impAddInBetweenFill(basegfx::B3DPolyPolygon & rTarget,const basegfx::B3DPolyPolygon & rPolA,const basegfx::B3DPolyPolygon & rPolB,double fTexVerStart,double fTexVerStop,bool bCreateNormals,bool bCreateTextureCoordinates)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 (!)"); 119*080bd379SArmin Le Grand const sal_uInt32 nPolygonCount(::std::min(rPolA.count(), rPolB.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 (!)"); 126*080bd379SArmin Le Grand const sal_uInt32 nPointCount(::std::min(aSubA.count(), aSubB.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 impSetNormal(basegfx::B3DPolyPolygon & rCandidate,const basegfx::B3DVector & rNormal)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 impCreateInBetweenNormals(basegfx::B3DPolyPolygon & rPolA,basegfx::B3DPolyPolygon & rPolB,bool bSmoothHorizontalNormals)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 (!)"); 216*080bd379SArmin Le Grand const sal_uInt32 nPolygonCount(::std::min(rPolA.count(), rPolB.count())); 217cdf0e10cSrcweir 218*080bd379SArmin Le Grand for(sal_uInt32 a(0L); a < nPolygonCount; a++) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir basegfx::B3DPolygon aSubA(rPolA.getB3DPolygon(a)); 221cdf0e10cSrcweir basegfx::B3DPolygon aSubB(rPolB.getB3DPolygon(a)); 222cdf0e10cSrcweir OSL_ENSURE(aSubA.count() == aSubB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)"); 223*080bd379SArmin Le Grand const sal_uInt32 nPointCount(::std::min(aSubA.count(), aSubB.count())); 224cdf0e10cSrcweir 225cdf0e10cSrcweir if(nPointCount) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir basegfx::B3DPoint aPrevA(aSubA.getB3DPoint(nPointCount - 1L)); 228cdf0e10cSrcweir basegfx::B3DPoint aCurrA(aSubA.getB3DPoint(0L)); 229cdf0e10cSrcweir const bool bClosed(aSubA.isClosed()); 230cdf0e10cSrcweir 231cdf0e10cSrcweir for(sal_uInt32 b(0L); b < nPointCount; b++) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir const sal_uInt32 nIndNext((b + 1L) % nPointCount); 234cdf0e10cSrcweir const basegfx::B3DPoint aNextA(aSubA.getB3DPoint(nIndNext)); 235cdf0e10cSrcweir const basegfx::B3DPoint aCurrB(aSubB.getB3DPoint(b)); 236cdf0e10cSrcweir 237cdf0e10cSrcweir // vector to back 238cdf0e10cSrcweir basegfx::B3DVector aDepth(aCurrB - aCurrA); 239cdf0e10cSrcweir aDepth.normalize(); 240cdf0e10cSrcweir 241cdf0e10cSrcweir if(aDepth.equalZero()) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir // no difference, try to get depth from next point 244cdf0e10cSrcweir const basegfx::B3DPoint aNextB(aSubB.getB3DPoint(nIndNext)); 245cdf0e10cSrcweir aDepth = aNextB - aNextA; 246cdf0e10cSrcweir aDepth.normalize(); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir // vector to left (correct for non-closed lines) 250cdf0e10cSrcweir const bool bFirstAndNotClosed(!bClosed && 0L == b); 251cdf0e10cSrcweir basegfx::B3DVector aLeft(bFirstAndNotClosed ? aCurrA - aNextA : aPrevA - aCurrA); 252cdf0e10cSrcweir aLeft.normalize(); 253cdf0e10cSrcweir 254cdf0e10cSrcweir // create left normal 255cdf0e10cSrcweir const basegfx::B3DVector aNormalLeft(aDepth.getPerpendicular(aLeft)); 256cdf0e10cSrcweir 257cdf0e10cSrcweir if(bSmoothHorizontalNormals) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir // vector to right (correct for non-closed lines) 260cdf0e10cSrcweir const bool bLastAndNotClosed(!bClosed && b + 1L == nPointCount); 261cdf0e10cSrcweir basegfx::B3DVector aRight(bLastAndNotClosed ? aCurrA - aPrevA : aNextA - aCurrA); 262cdf0e10cSrcweir aRight.normalize(); 263cdf0e10cSrcweir 264cdf0e10cSrcweir // create right normal 265cdf0e10cSrcweir const basegfx::B3DVector aNormalRight(aRight.getPerpendicular(aDepth)); 266cdf0e10cSrcweir 267cdf0e10cSrcweir // create smoothed in-between normal 268cdf0e10cSrcweir basegfx::B3DVector aNewNormal(aNormalLeft + aNormalRight); 269cdf0e10cSrcweir aNewNormal.normalize(); 270cdf0e10cSrcweir 271cdf0e10cSrcweir // set as new normal at polygons 272cdf0e10cSrcweir aSubA.setNormal(b, aNewNormal); 273cdf0e10cSrcweir aSubB.setNormal(b, aNewNormal); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir else 276cdf0e10cSrcweir { 277cdf0e10cSrcweir // set aNormalLeft as new normal at polygons 278cdf0e10cSrcweir aSubA.setNormal(b, aNormalLeft); 279cdf0e10cSrcweir aSubB.setNormal(b, aNormalLeft); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir // prepare next step 283cdf0e10cSrcweir aPrevA = aCurrA; 284cdf0e10cSrcweir aCurrA = aNextA; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir rPolA.setB3DPolygon(a, aSubA); 288cdf0e10cSrcweir rPolB.setB3DPolygon(a, aSubB); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir } 292cdf0e10cSrcweir impMixNormals(basegfx::B3DPolyPolygon & rPolA,const basegfx::B3DPolyPolygon & rPolB,double fWeightA)293cdf0e10cSrcweir void impMixNormals( 294cdf0e10cSrcweir basegfx::B3DPolyPolygon& rPolA, 295cdf0e10cSrcweir const basegfx::B3DPolyPolygon& rPolB, 296cdf0e10cSrcweir double fWeightA) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir const double fWeightB(1.0 - fWeightA); 299cdf0e10cSrcweir OSL_ENSURE(rPolA.count() == rPolB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)"); 300*080bd379SArmin Le Grand const sal_uInt32 nPolygonCount(::std::min(rPolA.count(), rPolB.count())); 301cdf0e10cSrcweir 302*080bd379SArmin Le Grand for(sal_uInt32 a(0L); a < nPolygonCount; a++) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir basegfx::B3DPolygon aSubA(rPolA.getB3DPolygon(a)); 305cdf0e10cSrcweir const basegfx::B3DPolygon aSubB(rPolB.getB3DPolygon(a)); 306cdf0e10cSrcweir OSL_ENSURE(aSubA.count() == aSubB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)"); 307*080bd379SArmin Le Grand const sal_uInt32 nPointCount(::std::min(aSubA.count(), aSubB.count())); 308cdf0e10cSrcweir 309cdf0e10cSrcweir for(sal_uInt32 b(0L); b < nPointCount; b++) 310cdf0e10cSrcweir { 311cdf0e10cSrcweir const basegfx::B3DVector aVA(aSubA.getNormal(b) * fWeightA); 312cdf0e10cSrcweir const basegfx::B3DVector aVB(aSubB.getNormal(b) * fWeightB); 313cdf0e10cSrcweir basegfx::B3DVector aVNew(aVA + aVB); 314cdf0e10cSrcweir aVNew.normalize(); 315cdf0e10cSrcweir aSubA.setNormal(b, aVNew); 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir rPolA.setB3DPolygon(a, aSubA); 319cdf0e10cSrcweir } 320cdf0e10cSrcweir } 321cdf0e10cSrcweir impHasCutWith(const basegfx::B2DPolygon & rPoly,const basegfx::B2DPoint & rStart,const basegfx::B2DPoint & rEnd)322cdf0e10cSrcweir bool impHasCutWith(const basegfx::B2DPolygon& rPoly, const basegfx::B2DPoint& rStart, const basegfx::B2DPoint& rEnd) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir // polygon is closed, one of the points is a member 325cdf0e10cSrcweir const sal_uInt32 nPointCount(rPoly.count()); 326cdf0e10cSrcweir 327cdf0e10cSrcweir if(nPointCount) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir basegfx::B2DPoint aCurrent(rPoly.getB2DPoint(0)); 330cdf0e10cSrcweir const basegfx::B2DVector aVector(rEnd - rStart); 331cdf0e10cSrcweir 332cdf0e10cSrcweir for(sal_uInt32 a(0); a < nPointCount; a++) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir const sal_uInt32 nNextIndex((a + 1) % nPointCount); 335cdf0e10cSrcweir const basegfx::B2DPoint aNext(rPoly.getB2DPoint(nNextIndex)); 336cdf0e10cSrcweir const basegfx::B2DVector aEdgeVector(aNext - aCurrent); 337cdf0e10cSrcweir 338cdf0e10cSrcweir if(basegfx::tools::findCut( 339cdf0e10cSrcweir rStart, aVector, 340cdf0e10cSrcweir aCurrent, aEdgeVector)) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir return true; 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir aCurrent = aNext; 346cdf0e10cSrcweir } 347cdf0e10cSrcweir } 348cdf0e10cSrcweir 349cdf0e10cSrcweir return false; 350cdf0e10cSrcweir } 351cdf0e10cSrcweir } // end of anonymous namespace 352cdf0e10cSrcweir 353cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 354cdf0e10cSrcweir 355cdf0e10cSrcweir namespace drawinglayer 356cdf0e10cSrcweir { 357cdf0e10cSrcweir namespace primitive3d 358cdf0e10cSrcweir { createLatheSlices(Slice3DVector & rSliceVector,const basegfx::B2DPolyPolygon & rSource,double fBackScale,double fDiagonal,double fRotation,sal_uInt32 nSteps,bool bCharacterMode,bool bCloseFront,bool bCloseBack)359cdf0e10cSrcweir void createLatheSlices( 360cdf0e10cSrcweir Slice3DVector& rSliceVector, 361cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rSource, 362cdf0e10cSrcweir double fBackScale, 363cdf0e10cSrcweir double fDiagonal, 364cdf0e10cSrcweir double fRotation, 365cdf0e10cSrcweir sal_uInt32 nSteps, 366cdf0e10cSrcweir bool bCharacterMode, 367cdf0e10cSrcweir bool bCloseFront, 368cdf0e10cSrcweir bool bCloseBack) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir if(basegfx::fTools::equalZero(fRotation) || 0L == nSteps) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir // no rotation or no steps, just one plane 373cdf0e10cSrcweir rSliceVector.push_back(Slice3D(rSource, basegfx::B3DHomMatrix())); 374cdf0e10cSrcweir } 375cdf0e10cSrcweir else 376cdf0e10cSrcweir { 377cdf0e10cSrcweir const bool bBackScale(!basegfx::fTools::equal(fBackScale, 1.0)); 378cdf0e10cSrcweir const bool bClosedRotation(!bBackScale && basegfx::fTools::equal(fRotation, F_2PI)); 379cdf0e10cSrcweir basegfx::B2DPolyPolygon aFront(rSource); 380cdf0e10cSrcweir basegfx::B2DPolyPolygon aBack(rSource); 381cdf0e10cSrcweir basegfx::B3DHomMatrix aTransformBack; 382cdf0e10cSrcweir basegfx::B2DPolyPolygon aOuterBack; 383cdf0e10cSrcweir 384cdf0e10cSrcweir if(bClosedRotation) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir bCloseFront = bCloseBack = false; 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir if(bBackScale) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir // avoid null zoom 392cdf0e10cSrcweir if(basegfx::fTools::equalZero(fBackScale)) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir fBackScale = 0.000001; 395cdf0e10cSrcweir } 396cdf0e10cSrcweir 397cdf0e10cSrcweir // back is scaled compared to front, create scaled version 398cdf0e10cSrcweir aBack = impScalePolyPolygonOnCenter(aBack, fBackScale); 399cdf0e10cSrcweir } 400cdf0e10cSrcweir 401cdf0e10cSrcweir if(bCloseFront || bCloseBack) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir const basegfx::B2DRange aBaseRange(basegfx::tools::getRange(aFront)); 404cdf0e10cSrcweir const double fOuterLength(aBaseRange.getMaxX() * fRotation); 405cdf0e10cSrcweir const double fInnerLength(aBaseRange.getMinX() * fRotation); 406cdf0e10cSrcweir const double fAverageLength((fOuterLength + fInnerLength) * 0.5); 407cdf0e10cSrcweir 408cdf0e10cSrcweir if(bCloseFront) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir const double fOffsetLen((fAverageLength / 12.0) * fDiagonal); 411cdf0e10cSrcweir basegfx::B2DPolyPolygon aOuterFront; 412cdf0e10cSrcweir impGetOuterPolyPolygon(aFront, aOuterFront, fOffsetLen, bCharacterMode); 413cdf0e10cSrcweir basegfx::B3DHomMatrix aTransform; 414cdf0e10cSrcweir aTransform.translate(0.0, 0.0, fOffsetLen); 415cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aOuterFront, aTransform, SLICETYPE3D_FRONTCAP)); 416cdf0e10cSrcweir } 417cdf0e10cSrcweir 418cdf0e10cSrcweir if(bCloseBack) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir const double fOffsetLen((fAverageLength / 12.0) * fDiagonal); 421cdf0e10cSrcweir impGetOuterPolyPolygon(aBack, aOuterBack, fOffsetLen, bCharacterMode); 422cdf0e10cSrcweir aTransformBack.translate(0.0, 0.0, -fOffsetLen); 423cdf0e10cSrcweir aTransformBack.rotate(0.0, fRotation, 0.0); 424cdf0e10cSrcweir } 425cdf0e10cSrcweir } 426cdf0e10cSrcweir 427cdf0e10cSrcweir // add start polygon (a = 0L) 428cdf0e10cSrcweir if(!bClosedRotation) 429cdf0e10cSrcweir { 430cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aFront, basegfx::B3DHomMatrix())); 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir // create segments (a + 1 .. nSteps) 434cdf0e10cSrcweir const double fStepSize(1.0 / (double)nSteps); 435cdf0e10cSrcweir 436cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nSteps; a++) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir const double fStep((double)(a + 1L) * fStepSize); 439cdf0e10cSrcweir basegfx::B2DPolyPolygon aNewPoly(bBackScale ? basegfx::tools::interpolate(aFront, aBack, fStep) : aFront); 440cdf0e10cSrcweir basegfx::B3DHomMatrix aNewMat; 441cdf0e10cSrcweir aNewMat.rotate(0.0, fRotation * fStep, 0.0); 442cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aNewPoly, aNewMat)); 443cdf0e10cSrcweir } 444cdf0e10cSrcweir 445cdf0e10cSrcweir if(bCloseBack) 446cdf0e10cSrcweir { 447cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aOuterBack, aTransformBack, SLICETYPE3D_BACKCAP)); 448cdf0e10cSrcweir } 449cdf0e10cSrcweir } 450cdf0e10cSrcweir } 451cdf0e10cSrcweir createExtrudeSlices(Slice3DVector & rSliceVector,const basegfx::B2DPolyPolygon & rSource,double fBackScale,double fDiagonal,double fDepth,bool bCharacterMode,bool bCloseFront,bool bCloseBack)452cdf0e10cSrcweir void createExtrudeSlices( 453cdf0e10cSrcweir Slice3DVector& rSliceVector, 454cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rSource, 455cdf0e10cSrcweir double fBackScale, 456cdf0e10cSrcweir double fDiagonal, 457cdf0e10cSrcweir double fDepth, 458cdf0e10cSrcweir bool bCharacterMode, 459cdf0e10cSrcweir bool bCloseFront, 460cdf0e10cSrcweir bool bCloseBack) 461cdf0e10cSrcweir { 462cdf0e10cSrcweir if(basegfx::fTools::equalZero(fDepth)) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir // no depth, just one plane 465cdf0e10cSrcweir rSliceVector.push_back(Slice3D(rSource, basegfx::B3DHomMatrix())); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir else 468cdf0e10cSrcweir { 469cdf0e10cSrcweir // there is depth, create Polygons for front,back and their default depth positions 470cdf0e10cSrcweir basegfx::B2DPolyPolygon aFront(rSource); 471cdf0e10cSrcweir basegfx::B2DPolyPolygon aBack(rSource); 472cdf0e10cSrcweir const bool bBackScale(!basegfx::fTools::equal(fBackScale, 1.0)); 473cdf0e10cSrcweir double fZFront(fDepth); // default depth for aFront 474cdf0e10cSrcweir double fZBack(0.0); // default depth for aBack 475cdf0e10cSrcweir basegfx::B2DPolyPolygon aOuterBack; 476cdf0e10cSrcweir 477cdf0e10cSrcweir if(bBackScale) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir // avoid null zoom 480cdf0e10cSrcweir if(basegfx::fTools::equalZero(fBackScale)) 481cdf0e10cSrcweir { 482cdf0e10cSrcweir fBackScale = 0.000001; 483cdf0e10cSrcweir } 484cdf0e10cSrcweir 485cdf0e10cSrcweir // aFront is scaled compared to aBack, create scaled version 486cdf0e10cSrcweir aFront = impScalePolyPolygonOnCenter(aFront, fBackScale); 487cdf0e10cSrcweir } 488cdf0e10cSrcweir 489cdf0e10cSrcweir if(bCloseFront) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir const double fOffset(fDepth * fDiagonal * 0.5); 492cdf0e10cSrcweir fZFront = fDepth - fOffset; 493cdf0e10cSrcweir basegfx::B2DPolyPolygon aOuterFront; 494cdf0e10cSrcweir impGetOuterPolyPolygon(aFront, aOuterFront, fOffset, bCharacterMode); 495cdf0e10cSrcweir basegfx::B3DHomMatrix aTransformFront; 496cdf0e10cSrcweir aTransformFront.translate(0.0, 0.0, fDepth); 497cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aOuterFront, aTransformFront, SLICETYPE3D_FRONTCAP)); 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir if(bCloseBack) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir const double fOffset(fDepth * fDiagonal * 0.5); 503cdf0e10cSrcweir fZBack = fOffset; 504cdf0e10cSrcweir impGetOuterPolyPolygon(aBack, aOuterBack, fOffset, bCharacterMode); 505cdf0e10cSrcweir } 506cdf0e10cSrcweir 507cdf0e10cSrcweir // add front and back polygons at evtl. changed depths 508cdf0e10cSrcweir { 509cdf0e10cSrcweir basegfx::B3DHomMatrix aTransformA, aTransformB; 510cdf0e10cSrcweir 511cdf0e10cSrcweir aTransformA.translate(0.0, 0.0, fZFront); 512cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aFront, aTransformA)); 513cdf0e10cSrcweir 514cdf0e10cSrcweir aTransformB.translate(0.0, 0.0, fZBack); 515cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aBack, aTransformB)); 516cdf0e10cSrcweir } 517cdf0e10cSrcweir 518cdf0e10cSrcweir if(bCloseBack) 519cdf0e10cSrcweir { 520cdf0e10cSrcweir rSliceVector.push_back(Slice3D(aOuterBack, basegfx::B3DHomMatrix(), SLICETYPE3D_BACKCAP)); 521cdf0e10cSrcweir } 522cdf0e10cSrcweir } 523cdf0e10cSrcweir } 524cdf0e10cSrcweir extractHorizontalLinesFromSlice(const Slice3DVector & rSliceVector,bool bCloseHorLines)525cdf0e10cSrcweir basegfx::B3DPolyPolygon extractHorizontalLinesFromSlice(const Slice3DVector& rSliceVector, bool bCloseHorLines) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir basegfx::B3DPolyPolygon aRetval; 528cdf0e10cSrcweir const sal_uInt32 nNumSlices(rSliceVector.size()); 529cdf0e10cSrcweir 530cdf0e10cSrcweir if(nNumSlices) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir const sal_uInt32 nSlideSubPolygonCount(rSliceVector[0].getB3DPolyPolygon().count()); 533cdf0e10cSrcweir 534cdf0e10cSrcweir for(sal_uInt32 b(0); b < nSlideSubPolygonCount; b++) 535cdf0e10cSrcweir { 536cdf0e10cSrcweir const sal_uInt32 nSubPolygonPointCount(rSliceVector[0].getB3DPolyPolygon().getB3DPolygon(b).count()); 537cdf0e10cSrcweir 538cdf0e10cSrcweir for(sal_uInt32 c(0); c < nSubPolygonPointCount; c++) 539cdf0e10cSrcweir { 540cdf0e10cSrcweir basegfx::B3DPolygon aNew; 541cdf0e10cSrcweir 542cdf0e10cSrcweir for(sal_uInt32 d(0); d < nNumSlices; d++) 543cdf0e10cSrcweir { 544*080bd379SArmin Le Grand const bool bSamePolygonCount(nSlideSubPolygonCount == rSliceVector[d].getB3DPolyPolygon().count()); 545*080bd379SArmin Le Grand const bool bSamePointCount(nSubPolygonPointCount == rSliceVector[d].getB3DPolyPolygon().getB3DPolygon(b).count()); 546*080bd379SArmin Le Grand 547*080bd379SArmin Le Grand if(bSamePolygonCount && bSamePointCount) 548*080bd379SArmin Le Grand { 549*080bd379SArmin Le Grand aNew.append(rSliceVector[d].getB3DPolyPolygon().getB3DPolygon(b).getB3DPoint(c)); 550*080bd379SArmin Le Grand } 551*080bd379SArmin Le Grand else 552*080bd379SArmin Le Grand { 553*080bd379SArmin Le Grand OSL_ENSURE(bSamePolygonCount, "Slice PolyPolygon with different Polygon count (!)"); 554*080bd379SArmin Le Grand OSL_ENSURE(bSamePointCount, "Slice Polygon with different point count (!)"); 555*080bd379SArmin Le Grand } 556*080bd379SArmin Le Grand } 557cdf0e10cSrcweir 558cdf0e10cSrcweir aNew.setClosed(bCloseHorLines); 559cdf0e10cSrcweir aRetval.append(aNew); 560cdf0e10cSrcweir } 561cdf0e10cSrcweir } 562cdf0e10cSrcweir } 563cdf0e10cSrcweir 564cdf0e10cSrcweir return aRetval; 565cdf0e10cSrcweir } 566cdf0e10cSrcweir extractVerticalLinesFromSlice(const Slice3DVector & rSliceVector)567cdf0e10cSrcweir basegfx::B3DPolyPolygon extractVerticalLinesFromSlice(const Slice3DVector& rSliceVector) 568cdf0e10cSrcweir { 569cdf0e10cSrcweir basegfx::B3DPolyPolygon aRetval; 570cdf0e10cSrcweir const sal_uInt32 nNumSlices(rSliceVector.size()); 571cdf0e10cSrcweir 572cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nNumSlices; a++) 573cdf0e10cSrcweir { 574cdf0e10cSrcweir aRetval.append(rSliceVector[a].getB3DPolyPolygon()); 575cdf0e10cSrcweir } 576cdf0e10cSrcweir 577cdf0e10cSrcweir return aRetval; 578cdf0e10cSrcweir } 579cdf0e10cSrcweir extractPlanesFromSlice(::std::vector<basegfx::B3DPolyPolygon> & rFill,const Slice3DVector & rSliceVector,bool bCreateNormals,bool bSmoothHorizontalNormals,bool bSmoothNormals,bool bSmoothLids,bool bClosed,double fSmoothNormalsMix,double fSmoothLidsMix,bool bCreateTextureCoordinates,const basegfx::B2DHomMatrix & rTexTransform)580cdf0e10cSrcweir void extractPlanesFromSlice( 581cdf0e10cSrcweir ::std::vector< basegfx::B3DPolyPolygon >& rFill, 582cdf0e10cSrcweir const Slice3DVector& rSliceVector, 583cdf0e10cSrcweir bool bCreateNormals, 584cdf0e10cSrcweir bool bSmoothHorizontalNormals, 585cdf0e10cSrcweir bool bSmoothNormals, 586cdf0e10cSrcweir bool bSmoothLids, 587cdf0e10cSrcweir bool bClosed, 588cdf0e10cSrcweir double fSmoothNormalsMix, 589cdf0e10cSrcweir double fSmoothLidsMix, 590cdf0e10cSrcweir bool bCreateTextureCoordinates, 591cdf0e10cSrcweir const basegfx::B2DHomMatrix& rTexTransform) 592cdf0e10cSrcweir { 593cdf0e10cSrcweir const sal_uInt32 nNumSlices(rSliceVector.size()); 594cdf0e10cSrcweir 595cdf0e10cSrcweir if(nNumSlices) 596cdf0e10cSrcweir { 597cdf0e10cSrcweir // common parameters 598cdf0e10cSrcweir const sal_uInt32 nLoopCount(bClosed ? nNumSlices : nNumSlices - 1L); 599cdf0e10cSrcweir basegfx::B3DPolyPolygon aEdgeRounding; 600cdf0e10cSrcweir sal_uInt32 a; 601cdf0e10cSrcweir 602cdf0e10cSrcweir // tetxture parameters 603cdf0e10cSrcweir double fInvTexHeight(1.0); 604cdf0e10cSrcweir double fTexHeightPos(0.0); 605cdf0e10cSrcweir double fTexStart(0.0); 606cdf0e10cSrcweir double fTexStop(1.0); 607cdf0e10cSrcweir ::std::vector<double> aTexHeightArray; 608cdf0e10cSrcweir basegfx::B3DRange aTexRangeFront; 609cdf0e10cSrcweir basegfx::B3DRange aTexRangeBack; 610cdf0e10cSrcweir 611cdf0e10cSrcweir if(bCreateTextureCoordinates) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir aTexRangeFront = basegfx::tools::getRange(rSliceVector[0L].getB3DPolyPolygon()); 614cdf0e10cSrcweir aTexRangeBack = basegfx::tools::getRange(rSliceVector[nNumSlices - 1L].getB3DPolyPolygon()); 615cdf0e10cSrcweir 616cdf0e10cSrcweir if(aTexRangeBack.getDepth() > aTexRangeBack.getWidth()) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir // last polygon is rotated so that depth is bigger than width, exchange X and Z 619cdf0e10cSrcweir // for making applyDefaultTextureCoordinatesParallel use Z instead of X for 620cdf0e10cSrcweir // horizontal texture coordinate 621cdf0e10cSrcweir aTexRangeBack = basegfx::B3DRange( 622cdf0e10cSrcweir aTexRangeBack.getMinZ(), aTexRangeBack.getMinY(), aTexRangeBack.getMinX(), 623cdf0e10cSrcweir aTexRangeBack.getMaxZ(), aTexRangeBack.getMaxY(), aTexRangeBack.getMaxX()); 624cdf0e10cSrcweir } 625cdf0e10cSrcweir 626cdf0e10cSrcweir basegfx::B3DPoint aCenter(basegfx::tools::getRange(rSliceVector[0L].getB3DPolyPolygon()).getCenter()); 627cdf0e10cSrcweir 628cdf0e10cSrcweir for(a = 0L; a < nLoopCount; a++) 629cdf0e10cSrcweir { 630cdf0e10cSrcweir const basegfx::B3DPoint aNextCenter(basegfx::tools::getRange(rSliceVector[(a + 1L) % nNumSlices].getB3DPolyPolygon()).getCenter()); 631cdf0e10cSrcweir const double fLength(basegfx::B3DVector(aNextCenter - aCenter).getLength()); 632cdf0e10cSrcweir aTexHeightArray.push_back(fLength); 633cdf0e10cSrcweir aCenter = aNextCenter; 634cdf0e10cSrcweir } 635cdf0e10cSrcweir 636cdf0e10cSrcweir const double fTexHeight(::std::accumulate(aTexHeightArray.begin(), aTexHeightArray.end(), 0.0)); 637cdf0e10cSrcweir 638cdf0e10cSrcweir if(!basegfx::fTools::equalZero(fTexHeight)) 639cdf0e10cSrcweir { 640cdf0e10cSrcweir fInvTexHeight = 1.0 / fTexHeight; 641cdf0e10cSrcweir } 642cdf0e10cSrcweir } 643cdf0e10cSrcweir 644cdf0e10cSrcweir if(nLoopCount) 645cdf0e10cSrcweir { 646cdf0e10cSrcweir for(a = 0L; a < nLoopCount; a++) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir const Slice3D& rSliceA(rSliceVector[a]); 649cdf0e10cSrcweir const Slice3D& rSliceB(rSliceVector[(a + 1L) % nNumSlices]); 650cdf0e10cSrcweir const bool bAcceptPair(SLICETYPE3D_REGULAR == rSliceA.getSliceType() && SLICETYPE3D_REGULAR == rSliceB.getSliceType()); 651cdf0e10cSrcweir basegfx::B3DPolyPolygon aPolA(rSliceA.getB3DPolyPolygon()); 652cdf0e10cSrcweir basegfx::B3DPolyPolygon aPolB(rSliceB.getB3DPolyPolygon()); 653cdf0e10cSrcweir 654cdf0e10cSrcweir if(bAcceptPair) 655cdf0e10cSrcweir { 656cdf0e10cSrcweir if(bCreateNormals) 657cdf0e10cSrcweir { 658cdf0e10cSrcweir impCreateInBetweenNormals(aPolB, aPolA, bSmoothHorizontalNormals); 659cdf0e10cSrcweir } 660cdf0e10cSrcweir 661cdf0e10cSrcweir { 662cdf0e10cSrcweir const sal_uInt32 nIndPrev((a + nNumSlices - 1L) % nNumSlices); 663cdf0e10cSrcweir const Slice3D& rSlicePrev(rSliceVector[nIndPrev]); 664cdf0e10cSrcweir basegfx::B3DPolyPolygon aPrev(rSlicePrev.getB3DPolyPolygon()); 665cdf0e10cSrcweir basegfx::B3DPolyPolygon aPolAA(rSliceA.getB3DPolyPolygon()); 666cdf0e10cSrcweir 667cdf0e10cSrcweir if(SLICETYPE3D_FRONTCAP == rSlicePrev.getSliceType()) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir basegfx::B3DPolyPolygon aFront(rSlicePrev.getB3DPolyPolygon()); 670cdf0e10cSrcweir const bool bHasSlant(aPolAA != aPrev); 671cdf0e10cSrcweir 672cdf0e10cSrcweir if(bCreateTextureCoordinates) 673cdf0e10cSrcweir { 674cdf0e10cSrcweir aFront = basegfx::tools::applyDefaultTextureCoordinatesParallel(aFront, aTexRangeFront); 675cdf0e10cSrcweir } 676cdf0e10cSrcweir 677cdf0e10cSrcweir if(bCreateNormals) 678cdf0e10cSrcweir { 679cdf0e10cSrcweir basegfx::B3DVector aNormal(0.0, 0.0, -1.0); 680cdf0e10cSrcweir 681cdf0e10cSrcweir if(aFront.count()) 682cdf0e10cSrcweir { 683cdf0e10cSrcweir aNormal = -aFront.getB3DPolygon(0L).getNormal(); 684cdf0e10cSrcweir } 685cdf0e10cSrcweir 686cdf0e10cSrcweir impSetNormal(aFront, aNormal); 687cdf0e10cSrcweir 688cdf0e10cSrcweir if(bHasSlant) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir impCreateInBetweenNormals(aPolAA, aPrev, bSmoothHorizontalNormals); 691cdf0e10cSrcweir 692cdf0e10cSrcweir if(bSmoothNormals) 693cdf0e10cSrcweir { 694cdf0e10cSrcweir // smooth and copy 695cdf0e10cSrcweir impMixNormals(aPolA, aPolAA, fSmoothNormalsMix); 696cdf0e10cSrcweir aPolAA = aPolA; 697cdf0e10cSrcweir } 698cdf0e10cSrcweir else 699cdf0e10cSrcweir { 700cdf0e10cSrcweir // take over from surface 701cdf0e10cSrcweir aPolAA = aPolA; 702cdf0e10cSrcweir } 703cdf0e10cSrcweir 704cdf0e10cSrcweir if(bSmoothLids) 705cdf0e10cSrcweir { 706cdf0e10cSrcweir // smooth and copy 707cdf0e10cSrcweir impMixNormals(aFront, aPrev, fSmoothLidsMix); 708cdf0e10cSrcweir aPrev = aFront; 709cdf0e10cSrcweir } 710cdf0e10cSrcweir else 711cdf0e10cSrcweir { 712cdf0e10cSrcweir // take over from front 713cdf0e10cSrcweir aPrev = aFront; 714cdf0e10cSrcweir } 715cdf0e10cSrcweir } 716cdf0e10cSrcweir else 717cdf0e10cSrcweir { 718cdf0e10cSrcweir if(bSmoothNormals) 719cdf0e10cSrcweir { 720cdf0e10cSrcweir // smooth 721cdf0e10cSrcweir impMixNormals(aPolA, aFront, fSmoothNormalsMix); 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir if(bSmoothLids) 725cdf0e10cSrcweir { 726cdf0e10cSrcweir // smooth and copy 727cdf0e10cSrcweir impMixNormals(aFront, aPolA, fSmoothLidsMix); 728cdf0e10cSrcweir aPolA = aFront; 729cdf0e10cSrcweir } 730cdf0e10cSrcweir } 731cdf0e10cSrcweir } 732cdf0e10cSrcweir 733cdf0e10cSrcweir if(bHasSlant) 734cdf0e10cSrcweir { 735cdf0e10cSrcweir if(bCreateTextureCoordinates) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir fTexStart = fTexHeightPos * fInvTexHeight; 738cdf0e10cSrcweir fTexStop = (fTexHeightPos - aTexHeightArray[(a + nLoopCount - 1L) % nLoopCount]) * fInvTexHeight; 739cdf0e10cSrcweir } 740cdf0e10cSrcweir 741cdf0e10cSrcweir impAddInBetweenFill(aEdgeRounding, aPolAA, aPrev, fTexStart, fTexStop, bCreateNormals, bCreateTextureCoordinates); 742cdf0e10cSrcweir } 743cdf0e10cSrcweir 744cdf0e10cSrcweir aFront.flip(); 745cdf0e10cSrcweir rFill.push_back(aFront); 746cdf0e10cSrcweir } 747cdf0e10cSrcweir else 748cdf0e10cSrcweir { 749cdf0e10cSrcweir if(bCreateNormals && bSmoothNormals && (nIndPrev != a + 1L)) 750cdf0e10cSrcweir { 751cdf0e10cSrcweir impCreateInBetweenNormals(aPolAA, aPrev, bSmoothHorizontalNormals); 752cdf0e10cSrcweir impMixNormals(aPolA, aPolAA, 0.5); 753cdf0e10cSrcweir } 754cdf0e10cSrcweir } 755cdf0e10cSrcweir } 756cdf0e10cSrcweir 757cdf0e10cSrcweir { 758cdf0e10cSrcweir const sal_uInt32 nIndNext((a + 2L) % nNumSlices); 759cdf0e10cSrcweir const Slice3D& rSliceNext(rSliceVector[nIndNext]); 760cdf0e10cSrcweir basegfx::B3DPolyPolygon aNext(rSliceNext.getB3DPolyPolygon()); 761cdf0e10cSrcweir basegfx::B3DPolyPolygon aPolBB(rSliceB.getB3DPolyPolygon()); 762cdf0e10cSrcweir 763cdf0e10cSrcweir if(SLICETYPE3D_BACKCAP == rSliceNext.getSliceType()) 764cdf0e10cSrcweir { 765cdf0e10cSrcweir basegfx::B3DPolyPolygon aBack(rSliceNext.getB3DPolyPolygon()); 766cdf0e10cSrcweir const bool bHasSlant(aPolBB != aNext); 767cdf0e10cSrcweir 768cdf0e10cSrcweir if(bCreateTextureCoordinates) 769cdf0e10cSrcweir { 770cdf0e10cSrcweir aBack = basegfx::tools::applyDefaultTextureCoordinatesParallel(aBack, aTexRangeBack); 771cdf0e10cSrcweir } 772cdf0e10cSrcweir 773cdf0e10cSrcweir if(bCreateNormals) 774cdf0e10cSrcweir { 775cdf0e10cSrcweir const basegfx::B3DVector aNormal(aBack.count() ? aBack.getB3DPolygon(0L).getNormal() : basegfx::B3DVector(0.0, 0.0, 1.0)); 776cdf0e10cSrcweir impSetNormal(aBack, aNormal); 777cdf0e10cSrcweir 778cdf0e10cSrcweir if(bHasSlant) 779cdf0e10cSrcweir { 780cdf0e10cSrcweir impCreateInBetweenNormals(aNext, aPolBB, bSmoothHorizontalNormals); 781cdf0e10cSrcweir 782cdf0e10cSrcweir if(bSmoothNormals) 783cdf0e10cSrcweir { 784cdf0e10cSrcweir // smooth and copy 785cdf0e10cSrcweir impMixNormals(aPolB, aPolBB, fSmoothNormalsMix); 786cdf0e10cSrcweir aPolBB = aPolB; 787cdf0e10cSrcweir } 788cdf0e10cSrcweir else 789cdf0e10cSrcweir { 790cdf0e10cSrcweir // take over from surface 791cdf0e10cSrcweir aPolBB = aPolB; 792cdf0e10cSrcweir } 793cdf0e10cSrcweir 794cdf0e10cSrcweir if(bSmoothLids) 795cdf0e10cSrcweir { 796cdf0e10cSrcweir // smooth and copy 797cdf0e10cSrcweir impMixNormals(aBack, aNext, fSmoothLidsMix); 798cdf0e10cSrcweir aNext = aBack; 799cdf0e10cSrcweir } 800cdf0e10cSrcweir else 801cdf0e10cSrcweir { 802cdf0e10cSrcweir // take over from back 803cdf0e10cSrcweir aNext = aBack; 804cdf0e10cSrcweir } 805cdf0e10cSrcweir } 806cdf0e10cSrcweir else 807cdf0e10cSrcweir { 808cdf0e10cSrcweir if(bSmoothNormals) 809cdf0e10cSrcweir { 810cdf0e10cSrcweir // smooth 811cdf0e10cSrcweir impMixNormals(aPolB, aBack, fSmoothNormalsMix); 812cdf0e10cSrcweir } 813cdf0e10cSrcweir 814cdf0e10cSrcweir if(bSmoothLids) 815cdf0e10cSrcweir { 816cdf0e10cSrcweir // smooth and copy 817cdf0e10cSrcweir impMixNormals(aBack, aPolB, fSmoothLidsMix); 818cdf0e10cSrcweir aPolB = aBack; 819cdf0e10cSrcweir } 820cdf0e10cSrcweir } 821cdf0e10cSrcweir } 822cdf0e10cSrcweir 823cdf0e10cSrcweir if(bHasSlant) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir if(bCreateTextureCoordinates) 826cdf0e10cSrcweir { 827cdf0e10cSrcweir fTexStart = (fTexHeightPos + aTexHeightArray[a] + aTexHeightArray[(a + 1L) % nLoopCount]) * fInvTexHeight; 828cdf0e10cSrcweir fTexStop = (fTexHeightPos + aTexHeightArray[a]) * fInvTexHeight; 829cdf0e10cSrcweir } 830cdf0e10cSrcweir 831cdf0e10cSrcweir impAddInBetweenFill(aEdgeRounding, aNext, aPolBB, fTexStart, fTexStop, bCreateNormals, bCreateTextureCoordinates); 832cdf0e10cSrcweir } 833cdf0e10cSrcweir 834cdf0e10cSrcweir rFill.push_back(aBack); 835cdf0e10cSrcweir } 836cdf0e10cSrcweir else 837cdf0e10cSrcweir { 838cdf0e10cSrcweir if(bCreateNormals && bSmoothNormals && (nIndNext != a)) 839cdf0e10cSrcweir { 840cdf0e10cSrcweir impCreateInBetweenNormals(aNext, aPolBB, bSmoothHorizontalNormals); 841cdf0e10cSrcweir impMixNormals(aPolB, aPolBB, 0.5); 842cdf0e10cSrcweir } 843cdf0e10cSrcweir } 844cdf0e10cSrcweir } 845cdf0e10cSrcweir 846cdf0e10cSrcweir if(bCreateTextureCoordinates) 847cdf0e10cSrcweir { 848cdf0e10cSrcweir fTexStart = (fTexHeightPos + aTexHeightArray[a]) * fInvTexHeight; 849cdf0e10cSrcweir fTexStop = fTexHeightPos * fInvTexHeight; 850cdf0e10cSrcweir } 851cdf0e10cSrcweir 852cdf0e10cSrcweir impAddInBetweenFill(aEdgeRounding, aPolB, aPolA, fTexStart, fTexStop, bCreateNormals, bCreateTextureCoordinates); 853cdf0e10cSrcweir } 854cdf0e10cSrcweir 855cdf0e10cSrcweir if(bCreateTextureCoordinates) 856cdf0e10cSrcweir { 857cdf0e10cSrcweir fTexHeightPos += aTexHeightArray[a]; 858cdf0e10cSrcweir } 859cdf0e10cSrcweir } 860cdf0e10cSrcweir } 861cdf0e10cSrcweir else 862cdf0e10cSrcweir { 863cdf0e10cSrcweir // no loop, but a single slice (1 == nNumSlices), create a filling from the single 864cdf0e10cSrcweir // front plane 865cdf0e10cSrcweir const Slice3D& rSlice(rSliceVector[0]); 866cdf0e10cSrcweir basegfx::B3DPolyPolygon aFront(rSlice.getB3DPolyPolygon()); 867cdf0e10cSrcweir 868cdf0e10cSrcweir if(bCreateTextureCoordinates) 869cdf0e10cSrcweir { 870cdf0e10cSrcweir aFront = basegfx::tools::applyDefaultTextureCoordinatesParallel(aFront, aTexRangeFront); 871cdf0e10cSrcweir } 872cdf0e10cSrcweir 873cdf0e10cSrcweir if(bCreateNormals) 874cdf0e10cSrcweir { 875cdf0e10cSrcweir basegfx::B3DVector aNormal(0.0, 0.0, -1.0); 876cdf0e10cSrcweir 877cdf0e10cSrcweir if(aFront.count()) 878cdf0e10cSrcweir { 879cdf0e10cSrcweir aNormal = -aFront.getB3DPolygon(0L).getNormal(); 880cdf0e10cSrcweir } 881cdf0e10cSrcweir 882cdf0e10cSrcweir impSetNormal(aFront, aNormal); 883cdf0e10cSrcweir } 884cdf0e10cSrcweir 885cdf0e10cSrcweir aFront.flip(); 886cdf0e10cSrcweir rFill.push_back(aFront); 887cdf0e10cSrcweir } 888cdf0e10cSrcweir 889cdf0e10cSrcweir if(bCreateTextureCoordinates) 890cdf0e10cSrcweir { 891cdf0e10cSrcweir aEdgeRounding.transformTextureCoordiantes(rTexTransform); 892cdf0e10cSrcweir } 893cdf0e10cSrcweir 894cdf0e10cSrcweir for(a = 0L; a < aEdgeRounding.count(); a++) 895cdf0e10cSrcweir { 896cdf0e10cSrcweir rFill.push_back(basegfx::B3DPolyPolygon(aEdgeRounding.getB3DPolygon(a))); 897cdf0e10cSrcweir } 898cdf0e10cSrcweir } 899cdf0e10cSrcweir } 900cdf0e10cSrcweir createReducedOutlines(const geometry::ViewInformation3D & rViewInformation,const basegfx::B3DHomMatrix & rObjectTransform,const basegfx::B3DPolygon & rLoopA,const basegfx::B3DPolygon & rLoopB,basegfx::B3DPolyPolygon & rTarget)901cdf0e10cSrcweir void createReducedOutlines( 902cdf0e10cSrcweir const geometry::ViewInformation3D& rViewInformation, 903cdf0e10cSrcweir const basegfx::B3DHomMatrix& rObjectTransform, 904cdf0e10cSrcweir const basegfx::B3DPolygon& rLoopA, 905cdf0e10cSrcweir const basegfx::B3DPolygon& rLoopB, 906cdf0e10cSrcweir basegfx::B3DPolyPolygon& rTarget) 907cdf0e10cSrcweir { 908cdf0e10cSrcweir const sal_uInt32 nPointCount(rLoopA.count()); 909cdf0e10cSrcweir 910cdf0e10cSrcweir // with idetic polygons there are no outlines 911cdf0e10cSrcweir if(rLoopA != rLoopB) 912cdf0e10cSrcweir { 913cdf0e10cSrcweir if(nPointCount && nPointCount == rLoopB.count()) 914cdf0e10cSrcweir { 915cdf0e10cSrcweir const basegfx::B3DHomMatrix aObjectTransform(rViewInformation.getObjectToView() * rObjectTransform); 916cdf0e10cSrcweir const basegfx::B2DPolygon a2DLoopA(basegfx::tools::createB2DPolygonFromB3DPolygon(rLoopA, aObjectTransform)); 917cdf0e10cSrcweir const basegfx::B2DPolygon a2DLoopB(basegfx::tools::createB2DPolygonFromB3DPolygon(rLoopB, aObjectTransform)); 918cdf0e10cSrcweir const basegfx::B2DPoint a2DCenterA(a2DLoopA.getB2DRange().getCenter()); 919cdf0e10cSrcweir const basegfx::B2DPoint a2DCenterB(a2DLoopB.getB2DRange().getCenter()); 920cdf0e10cSrcweir 921cdf0e10cSrcweir // without detectable Y-Axis there are no outlines 922cdf0e10cSrcweir if(!a2DCenterA.equal(a2DCenterB)) 923cdf0e10cSrcweir { 924cdf0e10cSrcweir // search for outmost left and right inter-loop-edges which do not cut the loops 925cdf0e10cSrcweir const basegfx::B2DPoint aCommonCenter(basegfx::average(a2DCenterA, a2DCenterB)); 926cdf0e10cSrcweir const basegfx::B2DVector aAxisVector(a2DCenterA - a2DCenterB); 927cdf0e10cSrcweir double fMaxLeft(0.0); 928cdf0e10cSrcweir double fMaxRight(0.0); 929cdf0e10cSrcweir sal_uInt32 nIndexLeft(0); 930cdf0e10cSrcweir sal_uInt32 nIndexRight(0); 931cdf0e10cSrcweir 932cdf0e10cSrcweir for(sal_uInt32 a(0); a < nPointCount; a++) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir const basegfx::B2DPoint aStart(a2DLoopA.getB2DPoint(a)); 935cdf0e10cSrcweir const basegfx::B2DPoint aEnd(a2DLoopB.getB2DPoint(a)); 936cdf0e10cSrcweir const basegfx::B2DPoint aMiddle(basegfx::average(aStart, aEnd)); 937cdf0e10cSrcweir 938cdf0e10cSrcweir if(!basegfx::tools::isInside(a2DLoopA, aMiddle)) 939cdf0e10cSrcweir { 940cdf0e10cSrcweir if(!basegfx::tools::isInside(a2DLoopB, aMiddle)) 941cdf0e10cSrcweir { 942cdf0e10cSrcweir if(!impHasCutWith(a2DLoopA, aStart, aEnd)) 943cdf0e10cSrcweir { 944cdf0e10cSrcweir if(!impHasCutWith(a2DLoopB, aStart, aEnd)) 945cdf0e10cSrcweir { 946cdf0e10cSrcweir const basegfx::B2DVector aCandidateVector(aMiddle - aCommonCenter); 947cdf0e10cSrcweir const double fCross(aCandidateVector.cross(aAxisVector)); 948cdf0e10cSrcweir const double fDistance(aCandidateVector.getLength()); 949cdf0e10cSrcweir 950cdf0e10cSrcweir if(fCross > 0.0) 951cdf0e10cSrcweir { 952cdf0e10cSrcweir if(fDistance > fMaxLeft) 953cdf0e10cSrcweir { 954cdf0e10cSrcweir fMaxLeft = fDistance; 955cdf0e10cSrcweir nIndexLeft = a; 956cdf0e10cSrcweir } 957cdf0e10cSrcweir } 958cdf0e10cSrcweir else if(fCross < 0.0) 959cdf0e10cSrcweir { 960cdf0e10cSrcweir if(fDistance > fMaxRight) 961cdf0e10cSrcweir { 962cdf0e10cSrcweir fMaxRight = fDistance; 963cdf0e10cSrcweir nIndexRight = a; 964cdf0e10cSrcweir } 965cdf0e10cSrcweir } 966cdf0e10cSrcweir } 967cdf0e10cSrcweir } 968cdf0e10cSrcweir } 969cdf0e10cSrcweir } 970cdf0e10cSrcweir } 971cdf0e10cSrcweir 972cdf0e10cSrcweir if(fMaxLeft != 0.0) 973cdf0e10cSrcweir { 974cdf0e10cSrcweir basegfx::B3DPolygon aToBeAdded; 975cdf0e10cSrcweir aToBeAdded.append(rLoopA.getB3DPoint(nIndexLeft)); 976cdf0e10cSrcweir aToBeAdded.append(rLoopB.getB3DPoint(nIndexLeft)); 977cdf0e10cSrcweir rTarget.append(aToBeAdded); 978cdf0e10cSrcweir } 979cdf0e10cSrcweir 980cdf0e10cSrcweir if(fMaxRight != 0.0) 981cdf0e10cSrcweir { 982cdf0e10cSrcweir basegfx::B3DPolygon aToBeAdded; 983cdf0e10cSrcweir aToBeAdded.append(rLoopA.getB3DPoint(nIndexRight)); 984cdf0e10cSrcweir aToBeAdded.append(rLoopB.getB3DPoint(nIndexRight)); 985cdf0e10cSrcweir rTarget.append(aToBeAdded); 986cdf0e10cSrcweir } 987cdf0e10cSrcweir } 988cdf0e10cSrcweir } 989cdf0e10cSrcweir } 990cdf0e10cSrcweir } 991cdf0e10cSrcweir 992cdf0e10cSrcweir } // end of namespace primitive3d 993cdf0e10cSrcweir } // end of namespace drawinglayer 994cdf0e10cSrcweir 995cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 996cdf0e10cSrcweir // eof 997