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 <primitive3d/sdrdecompositiontools3d.hxx>
25 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
26 #include <drawinglayer/attribute/sdrfillattribute.hxx>
27 #include <drawinglayer/attribute/sdrlineattribute.hxx>
28 #include <drawinglayer/attribute/sdrshadowattribute.hxx>
31 using namespace com::sun::star
;
34 namespace drawinglayer::primitive3d
36 Primitive3DContainer
SdrCubePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D
& /*rViewInformation*/) const
38 const basegfx::B3DRange
aUnitRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
39 Primitive3DContainer aRetval
;
40 basegfx::B3DPolyPolygon
aFill(basegfx::utils::createCubeFillPolyPolygonFromB3DRange(aUnitRange
));
43 if(!getSdrLFSAttribute().getFill().isDefault())
45 if(css::drawing::NormalsKind_SPECIFIC
== getSdr3DObjectAttribute().getNormalsKind()
46 || css::drawing::NormalsKind_SPHERE
== getSdr3DObjectAttribute().getNormalsKind())
48 // create sphere normals
49 const basegfx::B3DPoint
aCenter(basegfx::utils::getRange(aFill
).getCenter());
50 aFill
= basegfx::utils::applyDefaultNormalsSphere(aFill
, aCenter
);
53 if(getSdr3DObjectAttribute().getNormalsInvert())
56 aFill
= basegfx::utils::invertNormals(aFill
);
60 // texture coordinates
61 if(!getSdrLFSAttribute().getFill().isDefault())
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()));
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()));
73 if(bParallelX
|| bParallelY
)
75 // apply parallel texture coordinates in X and/or Y
76 const basegfx::B3DRange
aRange(basegfx::utils::getRange(aFill
));
77 aFill
= basegfx::utils::applyDefaultTextureCoordinatesParallel(aFill
, aRange
, bParallelX
, bParallelY
);
80 if(bSphereX
|| bSphereY
)
82 // apply spherical texture coordinates in X and/or Y
83 const basegfx::B3DRange
aRange(basegfx::utils::getRange(aFill
));
84 const basegfx::B3DPoint
aCenter(aRange
.getCenter());
85 aFill
= basegfx::utils::applyDefaultTextureCoordinatesSphere(aFill
, aCenter
, bSphereX
, bSphereY
);
88 if(bObjectSpecificX
|| bObjectSpecificY
)
91 for(sal_uInt32
a(0); a
< aFill
.count(); a
++)
93 basegfx::B3DPolygon
aTmpPoly(aFill
.getB3DPolygon(a
));
95 if(aTmpPoly
.count() >= 4)
97 for(sal_uInt32
b(0); b
< 4; b
++)
99 basegfx::B2DPoint
aPoint(aTmpPoly
.getTextureCoordinate(b
));
103 aPoint
.setX((1 == b
|| 2 == b
) ? 1.0 : 0.0);
108 aPoint
.setY((2 == b
|| 3 == b
) ? 1.0 : 0.0);
111 aTmpPoly
.setTextureCoordinate(b
, aPoint
);
114 aFill
.setB3DPolygon(a
, aTmpPoly
);
119 // transform texture coordinates to texture size
120 basegfx::B2DHomMatrix aTexMatrix
;
121 aTexMatrix
.scale(getTextureSize().getX(), getTextureSize().getY());
122 aFill
.transformTextureCoordinates(aTexMatrix
);
125 // build vector of PolyPolygons
126 std::vector
< basegfx::B3DPolyPolygon
> a3DPolyPolygonVector
;
128 for(sal_uInt32
a(0); a
< aFill
.count(); a
++)
130 a3DPolyPolygonVector
.emplace_back(aFill
.getB3DPolygon(a
));
133 if(!getSdrLFSAttribute().getFill().isDefault())
136 aRetval
= create3DPolyPolygonFillPrimitives(
137 a3DPolyPolygonVector
,
140 getSdr3DObjectAttribute(),
141 getSdrLFSAttribute().getFill(),
142 getSdrLFSAttribute().getFillFloatTransGradient());
146 // create simplified 3d hit test geometry
147 aRetval
= createHiddenGeometryPrimitives3D(
148 a3DPolyPolygonVector
,
151 getSdr3DObjectAttribute());
155 if(!getSdrLFSAttribute().getLine().isDefault())
157 basegfx::B3DPolyPolygon
aLine(basegfx::utils::createCubePolyPolygonFromB3DRange(aUnitRange
));
158 const Primitive3DContainer
aLines(create3DPolyPolygonLinePrimitives(
159 aLine
, getTransform(), getSdrLFSAttribute().getLine()));
160 aRetval
.append(aLines
);
164 if(!getSdrLFSAttribute().getShadow().isDefault() && !aRetval
.empty())
166 const Primitive3DContainer
aShadow(createShadowPrimitive3D(
167 aRetval
, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
168 aRetval
.append(aShadow
);
174 SdrCubePrimitive3D::SdrCubePrimitive3D(
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
)
183 basegfx::B3DRange
SdrCubePrimitive3D::getB3DRange(const geometry::ViewInformation3D
& /*rViewInformation*/) const
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();
195 ImplPrimitive3DIDBlock(SdrCubePrimitive3D
, PRIMITIVE3D_ID_SDRCUBEPRIMITIVE3D
)
197 } // end of namespace
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */