LibreOffice Module drawinglayer (master) 1
sdrdecompositiontools3d.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
39#include <rtl/ref.hxx>
40
41
43{
44 basegfx::B3DRange getRangeFrom3DGeometry(std::vector< basegfx::B3DPolyPolygon >& rFill)
45 {
46 basegfx::B3DRange aRetval;
47
48 for(const basegfx::B3DPolyPolygon & a : rFill)
49 {
51 }
52
53 return aRetval;
54 }
55
56 void applyNormalsKindSphereTo3DGeometry(std::vector< basegfx::B3DPolyPolygon >& rFill, const basegfx::B3DRange& rRange)
57 {
58 // create sphere normals
59 const basegfx::B3DPoint aCenter(rRange.getCenter());
60
61 for(basegfx::B3DPolyPolygon & a : rFill)
62 {
64 }
65 }
66
67 void applyNormalsKindFlatTo3DGeometry(std::vector< basegfx::B3DPolyPolygon >& rFill)
68 {
69 for(basegfx::B3DPolyPolygon & a : rFill)
70 {
71 a.clearNormals();
72 }
73 }
74
75 void applyNormalsInvertTo3DGeometry(std::vector< basegfx::B3DPolyPolygon >& rFill)
76 {
77 // invert normals
78 for(basegfx::B3DPolyPolygon & a : rFill)
79 {
81 }
82 }
83
85 css::drawing::TextureProjectionMode eModeX,
86 css::drawing::TextureProjectionMode eModeY,
87 std::vector< basegfx::B3DPolyPolygon >& rFill,
88 const basegfx::B3DRange& rRange,
89 const basegfx::B2DVector& rTextureSize)
90 {
91 // handle texture coordinates X
92 const bool bParallelX(css::drawing::TextureProjectionMode_PARALLEL == eModeX);
93 const bool bSphereX(!bParallelX && (css::drawing::TextureProjectionMode_SPHERE == eModeX));
94
95 // handle texture coordinates Y
96 const bool bParallelY(css::drawing::TextureProjectionMode_PARALLEL == eModeY);
97 const bool bSphereY(!bParallelY && (css::drawing::TextureProjectionMode_SPHERE == eModeY));
98
99 if(bParallelX || bParallelY)
100 {
101 // apply parallel texture coordinates in X and/or Y
102 for(auto & a: rFill)
103 {
104 a = basegfx::utils::applyDefaultTextureCoordinatesParallel(a, rRange, bParallelX, bParallelY);
105 }
106 }
107
108 if(bSphereX || bSphereY)
109 {
110 // apply spherical texture coordinates in X and/or Y
111 const basegfx::B3DPoint aCenter(rRange.getCenter());
112
113 for(auto & a: rFill)
114 {
115 a = basegfx::utils::applyDefaultTextureCoordinatesSphere(a, aCenter, bSphereX, bSphereY);
116 }
117 }
118
119 // transform texture coordinates to texture size
120 basegfx::B2DHomMatrix aTexMatrix;
121 aTexMatrix.scale(rTextureSize.getX(), rTextureSize.getY());
122
123 for(auto & a: rFill)
124 {
125 a.transformTextureCoordinates(aTexMatrix);
126 }
127 }
128
130 const basegfx::B3DPolyPolygon& rUnitPolyPolygon,
131 const basegfx::B3DHomMatrix& rObjectTransform,
132 const attribute::SdrLineAttribute& rLine)
133 {
134 // prepare fully scaled polyPolygon
135 basegfx::B3DPolyPolygon aScaledPolyPolygon(rUnitPolyPolygon);
136 aScaledPolyPolygon.transform(rObjectTransform);
137
138 // create line and stroke attribute
139 const attribute::LineAttribute aLineAttribute(rLine.getColor(), rLine.getWidth(), rLine.getJoin(), rLine.getCap());
140 const attribute::StrokeAttribute aStrokeAttribute(std::vector(rLine.getDotDashArray()), rLine.getFullDotDashLen());
141
142 // create primitives
143 Primitive3DContainer aRetval(aScaledPolyPolygon.count());
144
145 for(sal_uInt32 a(0); a < aScaledPolyPolygon.count(); a++)
146 {
147 aRetval[a] = new PolygonStrokePrimitive3D(aScaledPolyPolygon.getB3DPolygon(a), aLineAttribute, aStrokeAttribute);
148 }
149
150 if(0.0 != rLine.getTransparence())
151 {
152 // create UnifiedTransparenceTexturePrimitive3D, add created primitives and exchange
154 aRetval = { xRef };
155 }
156
157 return aRetval;
158 }
159
161 const std::vector< basegfx::B3DPolyPolygon >& r3DPolyPolygonVector,
162 const basegfx::B3DHomMatrix& rObjectTransform,
163 const basegfx::B2DVector& rTextureSize,
164 const attribute::Sdr3DObjectAttribute& aSdr3DObjectAttribute,
165 const attribute::SdrFillAttribute& rFill,
166 const attribute::FillGradientAttribute& rFillGradient)
167 {
168 Primitive3DContainer aRetval;
169
170 if(!r3DPolyPolygonVector.empty())
171 {
172 // create list of simple fill primitives
173 aRetval.resize(r3DPolyPolygonVector.size());
174
175 for(size_t a(0); a < r3DPolyPolygonVector.size(); a++)
176 {
177 // get scaled PolyPolygon
178 basegfx::B3DPolyPolygon aScaledPolyPolygon(r3DPolyPolygonVector[a]);
179 aScaledPolyPolygon.transform(rObjectTransform);
180
181 if(aScaledPolyPolygon.areNormalsUsed())
182 {
183 aScaledPolyPolygon.transformNormals(rObjectTransform);
184 }
185
187 std::move(aScaledPolyPolygon),
188 aSdr3DObjectAttribute.getMaterial(),
189 aSdr3DObjectAttribute.getDoubleSided()));
190 aRetval[a] = xRef;
191 }
192
193 // look for and evtl. build texture sub-group primitive
194 if(!rFill.getGradient().isDefault()
195 || !rFill.getHatch().isDefault()
196 || !rFill.getFillGraphic().isDefault())
197 {
198 bool bModulate(css::drawing::TextureMode_MODULATE == aSdr3DObjectAttribute.getTextureMode());
199 bool bFilter(aSdr3DObjectAttribute.getTextureFilter());
200 rtl::Reference<BasePrimitive3D> pNewTexturePrimitive3D;
201
202 if(!rFill.getGradient().isDefault())
203 {
204 // create gradientTexture3D with sublist, add to local aRetval
205 pNewTexturePrimitive3D = new GradientTexturePrimitive3D(
206 rFill.getGradient(),
207 aRetval,
208 rTextureSize,
209 bModulate,
210 bFilter);
211 }
212 else if(!rFill.getHatch().isDefault())
213 {
214 // create hatchTexture3D with sublist, add to local aRetval
215 pNewTexturePrimitive3D = new HatchTexturePrimitive3D(
216 rFill.getHatch(),
217 aRetval,
218 rTextureSize,
219 bModulate,
220 bFilter);
221 }
222 else // if(!rFill.getFillGraphic().isDefault())
223 {
224 // create bitmapTexture3D with sublist, add to local aRetval
225 const basegfx::B2DRange aTexRange(0.0, 0.0, rTextureSize.getX(), rTextureSize.getY());
226
227 pNewTexturePrimitive3D = new BitmapTexturePrimitive3D(
229 aRetval,
230 rTextureSize,
231 bModulate,
232 bFilter);
233 }
234
235 // exchange aRetval content with texture group
236 const Primitive3DReference xRef(pNewTexturePrimitive3D);
237 aRetval = { xRef };
238
239 if(css::drawing::TextureKind2_LUMINANCE == aSdr3DObjectAttribute.getTextureKind())
240 {
241 // use modified color primitive to force textures to gray
242 const basegfx::BColorModifierSharedPtr aBColorModifier =
243 std::make_shared<basegfx::BColorModifier_gray>();
244 const Primitive3DReference xRef2(
246 aRetval,
247 aBColorModifier));
248
249 aRetval = { xRef2 };
250 }
251 }
252
253 if(0.0 != rFill.getTransparence())
254 {
255 // create UnifiedTransparenceTexturePrimitive3D with sublist and exchange
257 aRetval = { xRef };
258 }
259 else if(!rFillGradient.isDefault())
260 {
261 // create TransparenceTexturePrimitive3D with sublist and exchange
262 const Primitive3DReference xRef(new TransparenceTexturePrimitive3D(rFillGradient, aRetval, rTextureSize));
263 aRetval = { xRef };
264 }
265 }
266
267 return aRetval;
268 }
269
271 const Primitive3DContainer& rSource,
272 const attribute::SdrShadowAttribute& rShadow,
273 bool bShadow3D)
274 {
275 // create Shadow primitives. Uses already created primitives
276 if(!rSource.empty() && !basegfx::fTools::moreOrEqual(rShadow.getTransparence(), 1.0))
277 {
278 // prepare new list for shadow geometry
279 basegfx::B2DHomMatrix aShadowOffset;
280 aShadowOffset.set(0, 2, rShadow.getOffset().getX());
281 aShadowOffset.set(1, 2, rShadow.getOffset().getY());
282
283 // create shadow primitive and add primitives
284 const Primitive3DReference xRef(new ShadowPrimitive3D(aShadowOffset, rShadow.getColor(), rShadow.getTransparence(), bShadow3D, rSource));
285 return { xRef };
286 }
287 else
288 {
289 return Primitive3DContainer();
290 }
291 }
292
294 const std::vector< basegfx::B3DPolyPolygon >& r3DPolyPolygonVector,
295 const basegfx::B3DHomMatrix& rObjectTransform,
296 const basegfx::B2DVector& rTextureSize,
297 const attribute::Sdr3DObjectAttribute& aSdr3DObjectAttribute)
298 {
299 // create hidden sub-geometry which can be used for HitTest
300 // and BoundRect calculations, but will not be visualized
301 const attribute::SdrFillAttribute aSimplifiedFillAttribute(
302 0.0,
307
308 const Primitive3DReference aHidden(
311 r3DPolyPolygonVector,
312 rObjectTransform,
313 rTextureSize,
314 aSdr3DObjectAttribute,
315 aSimplifiedFillAttribute,
317
318 return { aHidden };
319 }
320
321} // end of namespace
322
323/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
void scale(double fX, double fY)
void transformNormals(const B3DHomMatrix &rMatrix)
sal_uInt32 count() const
void transform(const basegfx::B3DHomMatrix &rMatrix)
bool areNormalsUsed() const
B3DPolygon const & getB3DPolygon(sal_uInt32 nIndex) const
void expand(const B3DTuple &rTuple)
B3DPoint getCenter() const
TYPE getX() const
TYPE getY() const
css::drawing::TextureMode getTextureMode() const
css::drawing::TextureKind2 getTextureKind() const
const MaterialAttribute3D & getMaterial() const
const FillHatchAttribute & getHatch() const
const FillGradientAttribute & getGradient() const
const SdrFillGraphicAttribute & getFillGraphic() const
FillGraphicAttribute createFillGraphicAttribute(const basegfx::B2DRange &rRange) const
const ::std::vector< double > & getDotDashArray() const
const basegfx::BColor & getColor() const
const basegfx::B2DVector & getOffset() const
uno_Any a
bool moreOrEqual(const T &rfValA, const T &rfValB)
B3DPolygon applyDefaultTextureCoordinatesSphere(const B3DPolygon &rCandidate, const B3DPoint &rCenter, bool bChangeX, bool bChangeY)
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)
std::shared_ptr< BColorModifier > BColorModifierSharedPtr
SdrPrimitive3D class.
void applyNormalsInvertTo3DGeometry(std::vector< basegfx::B3DPolyPolygon > &rFill)
css::uno::Reference< css::graphic::XPrimitive3D > Primitive3DReference
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)
void applyNormalsKindSphereTo3DGeometry(std::vector< basegfx::B3DPolyPolygon > &rFill, const basegfx::B3DRange &rRange)
basegfx::B3DRange getRangeFrom3DGeometry(std::vector< basegfx::B3DPolyPolygon > &rFill)
void applyTextureTo3DGeometry(css::drawing::TextureProjectionMode eModeX, css::drawing::TextureProjectionMode eModeY, std::vector< basegfx::B3DPolyPolygon > &rFill, const basegfx::B3DRange &rRange, const basegfx::B2DVector &rTextureSize)
void applyNormalsKindFlatTo3DGeometry(std::vector< basegfx::B3DPolyPolygon > &rFill)
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)