Bump version to 6.4-15
[LibreOffice.git] / svx / source / sdr / primitive3d / sdrattributecreator3d.cxx
blob5fe17f59dbadd380f38b9749e1799fddad90fa9d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sdr/primitive3d/sdrattributecreator3d.hxx>
21 #include <svx/svx3ditems.hxx>
22 #include <svl/itemset.hxx>
23 #include <com/sun/star/drawing/NormalsKind.hpp>
24 #include <com/sun/star/drawing/TextureProjectionMode.hpp>
25 #include <com/sun/star/drawing/TextureKind2.hpp>
26 #include <com/sun/star/drawing/TextureMode.hpp>
27 #include <svx/xflclit.hxx>
28 #include <drawinglayer/attribute/materialattribute3d.hxx>
29 #include <drawinglayer/attribute/sdrobjectattribute3d.hxx>
32 namespace drawinglayer
34 namespace primitive2d
36 attribute::Sdr3DObjectAttribute* createNewSdr3DObjectAttribute(const SfxItemSet& rSet)
38 // get NormalsKind
39 css::drawing::NormalsKind aNormalsKind(css::drawing::NormalsKind_SPECIFIC);
40 const sal_uInt16 nNormalsValue(rSet.Get(SDRATTR_3DOBJ_NORMALS_KIND).GetValue());
42 if(1 == nNormalsValue)
44 aNormalsKind = css::drawing::NormalsKind_FLAT;
46 else if(2 == nNormalsValue)
48 aNormalsKind = css::drawing::NormalsKind_SPHERE;
51 // get NormalsInvert flag
52 const bool bInvertNormals(rSet.Get(SDRATTR_3DOBJ_NORMALS_INVERT).GetValue());
54 // get TextureProjectionX
55 css::drawing::TextureProjectionMode aTextureProjectionX(css::drawing::TextureProjectionMode_OBJECTSPECIFIC);
56 const sal_uInt16 nTextureValueX(rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_X).GetValue());
58 if(1 == nTextureValueX)
60 aTextureProjectionX = css::drawing::TextureProjectionMode_PARALLEL;
62 else if(2 == nTextureValueX)
64 aTextureProjectionX = css::drawing::TextureProjectionMode_SPHERE;
67 // get TextureProjectionY
68 css::drawing::TextureProjectionMode aTextureProjectionY(css::drawing::TextureProjectionMode_OBJECTSPECIFIC);
69 const sal_uInt16 nTextureValueY(rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_Y).GetValue());
71 if(1 == nTextureValueY)
73 aTextureProjectionY = css::drawing::TextureProjectionMode_PARALLEL;
75 else if(2 == nTextureValueY)
77 aTextureProjectionY = css::drawing::TextureProjectionMode_SPHERE;
80 // get DoubleSided flag
81 const bool bDoubleSided(rSet.Get(SDRATTR_3DOBJ_DOUBLE_SIDED).GetValue());
83 // get Shadow3D flag
84 const bool bShadow3D(rSet.Get(SDRATTR_3DOBJ_SHADOW_3D).GetValue());
86 // get TextureFilter flag
87 const bool bTextureFilter(rSet.Get(SDRATTR_3DOBJ_TEXTURE_FILTER).GetValue());
89 // get texture kind
90 // TextureKind: 1 == Base3DTextureLuminance, 2 == Base3DTextureIntensity, 3 == Base3DTextureColor
91 css::drawing::TextureKind2 aTextureKind(css::drawing::TextureKind2_LUMINANCE);
92 const sal_uInt16 nTextureKind(rSet.Get(SDRATTR_3DOBJ_TEXTURE_KIND).GetValue());
94 if(2 == nTextureKind)
96 aTextureKind = css::drawing::TextureKind2_INTENSITY;
98 else if(3 == nTextureKind)
100 aTextureKind = css::drawing::TextureKind2_COLOR;
103 // get texture mode
104 // TextureMode: 1 == Base3DTextureReplace, 2 == Base3DTextureModulate, 3 == Base3DTextureBlend
105 css::drawing::TextureMode aTextureMode(css::drawing::TextureMode_REPLACE);
106 const sal_uInt16 nTextureMode(rSet.Get(SDRATTR_3DOBJ_TEXTURE_MODE).GetValue());
108 if(2 == nTextureMode)
110 aTextureMode = css::drawing::TextureMode_MODULATE;
112 else if(3 == nTextureMode)
114 aTextureMode = css::drawing::TextureMode_BLEND;
117 // get object color
118 const ::basegfx::BColor aObjectColor(rSet.Get(XATTR_FILLCOLOR).GetColorValue().getBColor());
120 // get specular color
121 const ::basegfx::BColor aSpecular(rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR).GetValue().getBColor());
123 // get emissive color
124 const ::basegfx::BColor aEmission(rSet.Get(SDRATTR_3DOBJ_MAT_EMISSION).GetValue().getBColor());
126 // get specular intensity
127 sal_uInt16 nSpecularIntensity(rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR_INTENSITY).GetValue());
129 if(nSpecularIntensity > 128)
131 nSpecularIntensity = 128;
134 // get reduced line geometry
135 const bool bReducedLineGeometry(rSet.Get(SDRATTR_3DOBJ_REDUCED_LINE_GEOMETRY).GetValue());
137 // prepare material
138 attribute::MaterialAttribute3D aMaterial(aObjectColor, aSpecular, aEmission, nSpecularIntensity);
140 return new attribute::Sdr3DObjectAttribute(
141 aNormalsKind, aTextureProjectionX, aTextureProjectionY,
142 aTextureKind, aTextureMode, aMaterial,
143 bInvertNormals, bDoubleSided, bShadow3D, bTextureFilter, bReducedLineGeometry);
145 } // end of namespace primitive2d
146 } // end of namespace sdr
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */