1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <drawinglayer/primitive3d/sdrcubeprimitive3d.hxx>
21 #include <basegfx/polygon/b3dpolypolygontools.hxx>
22 #include <basegfx/polygon/b3dpolygon.hxx>
23 #include <basegfx/matrix/b2dhommatrix.hxx>
24 #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx>
25 #include <basegfx/utils/canvastools.hxx>
26 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
27 #include <drawinglayer/attribute/sdrfillattribute.hxx>
28 #include <drawinglayer/attribute/sdrlineattribute.hxx>
29 #include <drawinglayer/attribute/sdrshadowattribute.hxx>
32 using namespace com::sun::star
;
35 namespace drawinglayer
39 Primitive3DContainer
SdrCubePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D
& /*rViewInformation*/) const
41 const basegfx::B3DRange
aUnitRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
42 Primitive3DContainer aRetval
;
43 basegfx::B3DPolyPolygon
aFill(basegfx::utils::createCubeFillPolyPolygonFromB3DRange(aUnitRange
));
46 if(!getSdrLFSAttribute().getFill().isDefault())
48 if(css::drawing::NormalsKind_SPECIFIC
== getSdr3DObjectAttribute().getNormalsKind()
49 || css::drawing::NormalsKind_SPHERE
== getSdr3DObjectAttribute().getNormalsKind())
51 // create sphere normals
52 const basegfx::B3DPoint
aCenter(basegfx::utils::getRange(aFill
).getCenter());
53 aFill
= basegfx::utils::applyDefaultNormalsSphere(aFill
, aCenter
);
56 if(getSdr3DObjectAttribute().getNormalsInvert())
59 aFill
= basegfx::utils::invertNormals(aFill
);
63 // texture coordinates
64 if(!getSdrLFSAttribute().getFill().isDefault())
66 // handle texture coordinates X
67 const bool bParallelX(css::drawing::TextureProjectionMode_PARALLEL
== getSdr3DObjectAttribute().getTextureProjectionX());
68 const bool bObjectSpecificX(css::drawing::TextureProjectionMode_OBJECTSPECIFIC
== getSdr3DObjectAttribute().getTextureProjectionX());
69 const bool bSphereX(!bParallelX
&& (css::drawing::TextureProjectionMode_SPHERE
== getSdr3DObjectAttribute().getTextureProjectionX()));
71 // handle texture coordinates Y
72 const bool bParallelY(css::drawing::TextureProjectionMode_PARALLEL
== getSdr3DObjectAttribute().getTextureProjectionY());
73 const bool bObjectSpecificY(css::drawing::TextureProjectionMode_OBJECTSPECIFIC
== getSdr3DObjectAttribute().getTextureProjectionY());
74 const bool bSphereY(!bParallelY
&& (css::drawing::TextureProjectionMode_SPHERE
== getSdr3DObjectAttribute().getTextureProjectionY()));
76 if(bParallelX
|| bParallelY
)
78 // apply parallel texture coordinates in X and/or Y
79 const basegfx::B3DRange
aRange(basegfx::utils::getRange(aFill
));
80 aFill
= basegfx::utils::applyDefaultTextureCoordinatesParallel(aFill
, aRange
, bParallelX
, bParallelY
);
83 if(bSphereX
|| bSphereY
)
85 // apply spherical texture coordinates in X and/or Y
86 const basegfx::B3DRange
aRange(basegfx::utils::getRange(aFill
));
87 const basegfx::B3DPoint
aCenter(aRange
.getCenter());
88 aFill
= basegfx::utils::applyDefaultTextureCoordinatesSphere(aFill
, aCenter
, bSphereX
, bSphereY
);
91 if(bObjectSpecificX
|| bObjectSpecificY
)
94 for(sal_uInt32
a(0); a
< aFill
.count(); a
++)
96 basegfx::B3DPolygon
aTmpPoly(aFill
.getB3DPolygon(a
));
98 if(aTmpPoly
.count() >= 4)
100 for(sal_uInt32
b(0); b
< 4; b
++)
102 basegfx::B2DPoint
aPoint(aTmpPoly
.getTextureCoordinate(b
));
106 aPoint
.setX((1 == b
|| 2 == b
) ? 1.0 : 0.0);
111 aPoint
.setY((2 == b
|| 3 == b
) ? 1.0 : 0.0);
114 aTmpPoly
.setTextureCoordinate(b
, aPoint
);
117 aFill
.setB3DPolygon(a
, aTmpPoly
);
122 // transform texture coordinates to texture size
123 basegfx::B2DHomMatrix aTexMatrix
;
124 aTexMatrix
.scale(getTextureSize().getX(), getTextureSize().getY());
125 aFill
.transformTextureCoordinates(aTexMatrix
);
128 // build vector of PolyPolygons
129 std::vector
< basegfx::B3DPolyPolygon
> a3DPolyPolygonVector
;
131 for(sal_uInt32
a(0); a
< aFill
.count(); a
++)
133 a3DPolyPolygonVector
.emplace_back(aFill
.getB3DPolygon(a
));
136 if(!getSdrLFSAttribute().getFill().isDefault())
139 aRetval
= create3DPolyPolygonFillPrimitives(
140 a3DPolyPolygonVector
,
143 getSdr3DObjectAttribute(),
144 getSdrLFSAttribute().getFill(),
145 getSdrLFSAttribute().getFillFloatTransGradient());
149 // create simplified 3d hit test geometry
150 aRetval
= createHiddenGeometryPrimitives3D(
151 a3DPolyPolygonVector
,
154 getSdr3DObjectAttribute());
158 if(!getSdrLFSAttribute().getLine().isDefault())
160 basegfx::B3DPolyPolygon
aLine(basegfx::utils::createCubePolyPolygonFromB3DRange(aUnitRange
));
161 const Primitive3DContainer
aLines(create3DPolyPolygonLinePrimitives(
162 aLine
, getTransform(), getSdrLFSAttribute().getLine()));
163 aRetval
.append(aLines
);
167 if(!getSdrLFSAttribute().getShadow().isDefault() && !aRetval
.empty())
169 const Primitive3DContainer
aShadow(createShadowPrimitive3D(
170 aRetval
, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
171 aRetval
.append(aShadow
);
177 SdrCubePrimitive3D::SdrCubePrimitive3D(
178 const basegfx::B3DHomMatrix
& rTransform
,
179 const basegfx::B2DVector
& rTextureSize
,
180 const attribute::SdrLineFillShadowAttribute3D
& rSdrLFSAttribute
,
181 const attribute::Sdr3DObjectAttribute
& rSdr3DObjectAttribute
)
182 : SdrPrimitive3D(rTransform
, rTextureSize
, rSdrLFSAttribute
, rSdr3DObjectAttribute
)
186 basegfx::B3DRange
SdrCubePrimitive3D::getB3DRange(const geometry::ViewInformation3D
& /*rViewInformation*/) const
188 // use default from sdrPrimitive3D which uses transformation expanded by line width/2.
189 // The parent implementation which uses the ranges of the decomposition would be more
190 // correct, but for historical reasons it is necessary to do the old method: To get
191 // the range of the non-transformed geometry and transform it then. This leads to different
192 // ranges where the new method is more correct, but the need to keep the old behaviour
193 // has priority here.
194 return getStandard3DRange();
198 ImplPrimitive3DIDBlock(SdrCubePrimitive3D
, PRIMITIVE3D_ID_SDRCUBEPRIMITIVE3D
)
200 } // end of namespace primitive3d
201 } // end of namespace drawinglayer
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */