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/tools/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>
31 //////////////////////////////////////////////////////////////////////////////
33 using namespace com::sun::star
;
35 //////////////////////////////////////////////////////////////////////////////
37 namespace drawinglayer
41 Primitive3DSequence
SdrCubePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D
& /*rViewInformation*/) const
43 const basegfx::B3DRange
aUnitRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
44 Primitive3DSequence aRetval
;
45 basegfx::B3DPolyPolygon
aFill(basegfx::tools::createCubeFillPolyPolygonFromB3DRange(aUnitRange
));
48 if(!getSdrLFSAttribute().getFill().isDefault())
50 if(::com::sun::star::drawing::NormalsKind_SPECIFIC
== getSdr3DObjectAttribute().getNormalsKind()
51 || ::com::sun::star::drawing::NormalsKind_SPHERE
== getSdr3DObjectAttribute().getNormalsKind())
53 // create sphere normals
54 const basegfx::B3DPoint
aCenter(basegfx::tools::getRange(aFill
).getCenter());
55 aFill
= basegfx::tools::applyDefaultNormalsSphere(aFill
, aCenter
);
58 if(getSdr3DObjectAttribute().getNormalsInvert())
61 aFill
= basegfx::tools::invertNormals(aFill
);
65 // texture coordinates
66 if(!getSdrLFSAttribute().getFill().isDefault())
68 // handle texture coordinates X
69 const bool bParallelX(::com::sun::star::drawing::TextureProjectionMode_PARALLEL
== getSdr3DObjectAttribute().getTextureProjectionX());
70 const bool bObjectSpecificX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC
== getSdr3DObjectAttribute().getTextureProjectionX());
71 const bool bSphereX(!bParallelX
&& (::com::sun::star::drawing::TextureProjectionMode_SPHERE
== getSdr3DObjectAttribute().getTextureProjectionX()));
73 // handle texture coordinates Y
74 const bool bParallelY(::com::sun::star::drawing::TextureProjectionMode_PARALLEL
== getSdr3DObjectAttribute().getTextureProjectionY());
75 const bool bObjectSpecificY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC
== getSdr3DObjectAttribute().getTextureProjectionY());
76 const bool bSphereY(!bParallelY
&& (::com::sun::star::drawing::TextureProjectionMode_SPHERE
== getSdr3DObjectAttribute().getTextureProjectionY()));
78 if(bParallelX
|| bParallelY
)
80 // apply parallel texture coordinates in X and/or Y
81 const basegfx::B3DRange
aRange(basegfx::tools::getRange(aFill
));
82 aFill
= basegfx::tools::applyDefaultTextureCoordinatesParallel(aFill
, aRange
, bParallelX
, bParallelY
);
85 if(bSphereX
|| bSphereY
)
87 // apply spherical texture coordinates in X and/or Y
88 const basegfx::B3DRange
aRange(basegfx::tools::getRange(aFill
));
89 const basegfx::B3DPoint
aCenter(aRange
.getCenter());
90 aFill
= basegfx::tools::applyDefaultTextureCoordinatesSphere(aFill
, aCenter
, bSphereX
, bSphereY
);
93 if(bObjectSpecificX
|| bObjectSpecificY
)
96 for(sal_uInt32
a(0L); a
< aFill
.count(); a
++)
98 basegfx::B3DPolygon
aTmpPoly(aFill
.getB3DPolygon(a
));
100 if(aTmpPoly
.count() >= 4L)
102 for(sal_uInt32
b(0L); b
< 4L; b
++)
104 basegfx::B2DPoint
aPoint(aTmpPoly
.getTextureCoordinate(b
));
108 aPoint
.setX((1L == b
|| 2L == b
) ? 1.0 : 0.0);
113 aPoint
.setY((2L == b
|| 3L == b
) ? 1.0 : 0.0);
116 aTmpPoly
.setTextureCoordinate(b
, aPoint
);
119 aFill
.setB3DPolygon(a
, aTmpPoly
);
124 // transform texture coordinates to texture size
125 basegfx::B2DHomMatrix aTexMatrix
;
126 aTexMatrix
.scale(getTextureSize().getX(), getTextureSize().getY());
127 aFill
.transformTextureCoordiantes(aTexMatrix
);
130 // build vector of PolyPolygons
131 ::std::vector
< basegfx::B3DPolyPolygon
> a3DPolyPolygonVector
;
133 for(sal_uInt32
a(0L); a
< aFill
.count(); a
++)
135 a3DPolyPolygonVector
.push_back(basegfx::B3DPolyPolygon(aFill
.getB3DPolygon(a
)));
138 if(!getSdrLFSAttribute().getFill().isDefault())
141 aRetval
= create3DPolyPolygonFillPrimitives(
142 a3DPolyPolygonVector
,
145 getSdr3DObjectAttribute(),
146 getSdrLFSAttribute().getFill(),
147 getSdrLFSAttribute().getFillFloatTransGradient());
151 // create simplified 3d hit test geometry
152 aRetval
= createHiddenGeometryPrimitives3D(
153 a3DPolyPolygonVector
,
156 getSdr3DObjectAttribute());
160 if(!getSdrLFSAttribute().getLine().isDefault())
162 basegfx::B3DPolyPolygon
aLine(basegfx::tools::createCubePolyPolygonFromB3DRange(aUnitRange
));
163 const Primitive3DSequence
aLines(create3DPolyPolygonLinePrimitives(
164 aLine
, getTransform(), getSdrLFSAttribute().getLine()));
165 appendPrimitive3DSequenceToPrimitive3DSequence(aRetval
, aLines
);
169 if(!getSdrLFSAttribute().getShadow().isDefault() && aRetval
.hasElements())
171 const Primitive3DSequence
aShadow(createShadowPrimitive3D(
172 aRetval
, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
173 appendPrimitive3DSequenceToPrimitive3DSequence(aRetval
, aShadow
);
179 SdrCubePrimitive3D::SdrCubePrimitive3D(
180 const basegfx::B3DHomMatrix
& rTransform
,
181 const basegfx::B2DVector
& rTextureSize
,
182 const attribute::SdrLineFillShadowAttribute3D
& rSdrLFSAttribute
,
183 const attribute::Sdr3DObjectAttribute
& rSdr3DObjectAttribute
)
184 : SdrPrimitive3D(rTransform
, rTextureSize
, rSdrLFSAttribute
, rSdr3DObjectAttribute
)
188 bool SdrCubePrimitive3D::operator==(const BasePrimitive3D
& rPrimitive
) const
190 return SdrPrimitive3D::operator==(rPrimitive
);
193 basegfx::B3DRange
SdrCubePrimitive3D::getB3DRange(const geometry::ViewInformation3D
& /*rViewInformation*/) const
195 // use defaut from sdrPrimitive3D which uses transformation expanded by line width/2.
196 // The parent implementation which uses the ranges of the decomposition would be more
197 // corrcet, but for historical reasons it is necessary to do the old method: To get
198 // the range of the non-transformed geometry and transform it then. This leads to different
199 // ranges where the new method is more correct, but the need to keep the old behaviour
200 // has priority here.
201 return getStandard3DRange();
205 ImplPrimitive3DIDBlock(SdrCubePrimitive3D
, PRIMITIVE3D_ID_SDRCUBEPRIMITIVE3D
)
207 } // end of namespace primitive3d
208 } // end of namespace drawinglayer
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */