LibreOffice Module drawinglayer (master) 1
sdrcubeprimitive3d.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
29
30
31using namespace com::sun::star;
32
33
35{
37 {
38 const basegfx::B3DRange aUnitRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
41
42 // normal creation
43 if(!getSdrLFSAttribute().getFill().isDefault())
44 {
45 if(css::drawing::NormalsKind_SPECIFIC == getSdr3DObjectAttribute().getNormalsKind()
46 || css::drawing::NormalsKind_SPHERE == getSdr3DObjectAttribute().getNormalsKind())
47 {
48 // create sphere normals
49 const basegfx::B3DPoint aCenter(basegfx::utils::getRange(aFill).getCenter());
50 aFill = basegfx::utils::applyDefaultNormalsSphere(aFill, aCenter);
51 }
52
53 if(getSdr3DObjectAttribute().getNormalsInvert())
54 {
55 // invert normals
56 aFill = basegfx::utils::invertNormals(aFill);
57 }
58 }
59
60 // texture coordinates
61 if(!getSdrLFSAttribute().getFill().isDefault())
62 {
63 // handle texture coordinates X
64 const bool bParallelX(css::drawing::TextureProjectionMode_PARALLEL == getSdr3DObjectAttribute().getTextureProjectionX());
65 const bool bObjectSpecificX(css::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionX());
66 const bool bSphereX(!bParallelX && (css::drawing::TextureProjectionMode_SPHERE == getSdr3DObjectAttribute().getTextureProjectionX()));
67
68 // handle texture coordinates Y
69 const bool bParallelY(css::drawing::TextureProjectionMode_PARALLEL == getSdr3DObjectAttribute().getTextureProjectionY());
70 const bool bObjectSpecificY(css::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionY());
71 const bool bSphereY(!bParallelY && (css::drawing::TextureProjectionMode_SPHERE == getSdr3DObjectAttribute().getTextureProjectionY()));
72
73 if(bParallelX || bParallelY)
74 {
75 // apply parallel texture coordinates in X and/or Y
77 aFill = basegfx::utils::applyDefaultTextureCoordinatesParallel(aFill, aRange, bParallelX, bParallelY);
78 }
79
80 if(bSphereX || bSphereY)
81 {
82 // apply spherical texture coordinates in X and/or Y
84 const basegfx::B3DPoint aCenter(aRange.getCenter());
85 aFill = basegfx::utils::applyDefaultTextureCoordinatesSphere(aFill, aCenter, bSphereX, bSphereY);
86 }
87
88 if(bObjectSpecificX || bObjectSpecificY)
89 {
90 // object-specific
91 for(sal_uInt32 a(0); a < aFill.count(); a++)
92 {
93 basegfx::B3DPolygon aTmpPoly(aFill.getB3DPolygon(a));
94
95 if(aTmpPoly.count() >= 4)
96 {
97 for(sal_uInt32 b(0); b < 4; b++)
98 {
99 basegfx::B2DPoint aPoint(aTmpPoly.getTextureCoordinate(b));
100
101 if(bObjectSpecificX)
102 {
103 aPoint.setX((1 == b || 2 == b) ? 1.0 : 0.0);
104 }
105
106 if(bObjectSpecificY)
107 {
108 aPoint.setY((2 == b || 3 == b) ? 1.0 : 0.0);
109 }
110
111 aTmpPoly.setTextureCoordinate(b, aPoint);
112 }
113
114 aFill.setB3DPolygon(a, aTmpPoly);
115 }
116 }
117 }
118
119 // transform texture coordinates to texture size
120 basegfx::B2DHomMatrix aTexMatrix;
121 aTexMatrix.scale(getTextureSize().getX(), getTextureSize().getY());
122 aFill.transformTextureCoordinates(aTexMatrix);
123 }
124
125 // build vector of PolyPolygons
126 std::vector< basegfx::B3DPolyPolygon > a3DPolyPolygonVector;
127
128 for(sal_uInt32 a(0); a < aFill.count(); a++)
129 {
130 a3DPolyPolygonVector.emplace_back(aFill.getB3DPolygon(a));
131 }
132
133 if(!getSdrLFSAttribute().getFill().isDefault())
134 {
135 // add fill
137 a3DPolyPolygonVector,
138 getTransform(),
141 getSdrLFSAttribute().getFill(),
142 getSdrLFSAttribute().getFillFloatTransGradient());
143 }
144 else
145 {
146 // create simplified 3d hit test geometry
148 a3DPolyPolygonVector,
149 getTransform(),
152 }
153
154 // add line
155 if(!getSdrLFSAttribute().getLine().isDefault())
156 {
159 aLine, getTransform(), getSdrLFSAttribute().getLine()));
160 aRetval.append(aLines);
161 }
162
163 // add shadow
164 if(!getSdrLFSAttribute().getShadow().isDefault() && !aRetval.empty())
165 {
167 aRetval, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
168 aRetval.append(aShadow);
169 }
170
171 return aRetval;
172 }
173
175 const basegfx::B3DHomMatrix& rTransform,
176 const basegfx::B2DVector& rTextureSize,
177 const attribute::SdrLineFillShadowAttribute3D& rSdrLFSAttribute,
178 const attribute::Sdr3DObjectAttribute& rSdr3DObjectAttribute)
179 : SdrPrimitive3D(rTransform, rTextureSize, rSdrLFSAttribute, rSdr3DObjectAttribute)
180 {
181 }
182
184 {
185 // use default from sdrPrimitive3D which uses transformation expanded by line width/2.
186 // The parent implementation which uses the ranges of the decomposition would be more
187 // correct, but for historical reasons it is necessary to do the old method: To get
188 // the range of the non-transformed geometry and transform it then. This leads to different
189 // ranges where the new method is more correct, but the need to keep the old behaviour
190 // has priority here.
191 return getStandard3DRange();
192 }
193
194 // provide unique ID
196
197} // end of namespace
198
199/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void scale(double fX, double fY)
void transformTextureCoordinates(const B2DHomMatrix &rMatrix)
sal_uInt32 count() const
void setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon &rPolygon)
B3DPolygon const & getB3DPolygon(sal_uInt32 nIndex) const
void setTextureCoordinate(sal_uInt32 nIndex, const B2DPoint &rValue)
sal_uInt32 count() const
B2DPoint const & getTextureCoordinate(sal_uInt32 nIndex) const
B3DPoint getCenter() const
void setY(TYPE fY)
void setX(TYPE fX)
void append(const Primitive3DContainer &rSource)
virtual Primitive3DContainer create3DDecomposition(const geometry::ViewInformation3D &rViewInformation) const override
local decomposition.
virtual basegfx::B3DRange getB3DRange(const geometry::ViewInformation3D &rViewInformation) const override
get range
SdrCubePrimitive3D(const basegfx::B3DHomMatrix &rTransform, const basegfx::B2DVector &rTextureSize, const attribute::SdrLineFillShadowAttribute3D &rSdrLFSAttribute, const attribute::Sdr3DObjectAttribute &rSdr3DObjectAttribute)
constructor
const basegfx::B3DHomMatrix & getTransform() const
data read access
const basegfx::B2DVector & getTextureSize() const
const attribute::Sdr3DObjectAttribute & getSdr3DObjectAttribute() const
basegfx::B3DRange getStandard3DRange() const
Standard implementation for primitive3D which will use maTransform as range and expand by evtl.
const attribute::SdrLineFillShadowAttribute3D & getSdrLFSAttribute() const
#define PRIMITIVE3D_ID_SDRCUBEPRIMITIVE3D
uno_Any a
B3DPolyPolygon createCubePolyPolygonFromB3DRange(const B3DRange &rRange)
B3DPolygon applyDefaultTextureCoordinatesSphere(const B3DPolygon &rCandidate, const B3DPoint &rCenter, bool bChangeX, bool bChangeY)
B3DPolyPolygon createCubeFillPolyPolygonFromB3DRange(const B3DRange &rRange)
B3DPolygon applyDefaultNormalsSphere(const B3DPolygon &rCandidate, const B3DPoint &rCenter)
B3DPolygon invertNormals(const B3DPolygon &rCandidate)
B3DPolygon applyDefaultTextureCoordinatesParallel(const B3DPolygon &rCandidate, const B3DRange &rRange, bool bChangeX, bool bChangeY)
B2DRange getRange(const B2DPolygon &rCandidate)
SdrPrimitive3D class.
ImplPrimitive3DIDBlock(PolygonHairlinePrimitive3D, PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D) Primitive3DContainer PolygonStrokePrimitive3D
Primitive3DContainer create3DPolyPolygonFillPrimitives(const std::vector< basegfx::B3DPolyPolygon > &r3DPolyPolygonVector, const basegfx::B3DHomMatrix &rObjectTransform, const basegfx::B2DVector &rTextureSize, const attribute::Sdr3DObjectAttribute &aSdr3DObjectAttribute, const attribute::SdrFillAttribute &rFill, const attribute::FillGradientAttribute &rFillGradient)
Primitive3DContainer createHiddenGeometryPrimitives3D(const std::vector< basegfx::B3DPolyPolygon > &r3DPolyPolygonVector, const basegfx::B3DHomMatrix &rObjectTransform, const basegfx::B2DVector &rTextureSize, const attribute::Sdr3DObjectAttribute &aSdr3DObjectAttribute)
Primitive3DContainer createShadowPrimitive3D(const Primitive3DContainer &rSource, const attribute::SdrShadowAttribute &rShadow, bool bShadow3D)
Primitive3DContainer create3DPolyPolygonLinePrimitives(const basegfx::B3DPolyPolygon &rUnitPolyPolygon, const basegfx::B3DHomMatrix &rObjectTransform, const attribute::SdrLineAttribute &rLine)