1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
25cdf0e10cSrcweir #include <svx/svx3ditems.hxx>
26cdf0e10cSrcweir #include <svl/itemset.hxx>
27cdf0e10cSrcweir #include <com/sun/star/drawing/NormalsKind.hpp>
28cdf0e10cSrcweir #include <com/sun/star/drawing/TextureProjectionMode.hpp>
29cdf0e10cSrcweir #include <com/sun/star/drawing/TextureKind2.hpp>
30cdf0e10cSrcweir #include <com/sun/star/drawing/TextureMode.hpp>
31cdf0e10cSrcweir #include <svx/xflclit.hxx>
32cdf0e10cSrcweir #include <drawinglayer/attribute/materialattribute3d.hxx>
33cdf0e10cSrcweir #include <drawinglayer/attribute/sdrobjectattribute3d.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace drawinglayer
38cdf0e10cSrcweir {
39cdf0e10cSrcweir 	namespace primitive2d
40cdf0e10cSrcweir 	{
createNewSdr3DObjectAttribute(const SfxItemSet & rSet)41cdf0e10cSrcweir 		attribute::Sdr3DObjectAttribute* createNewSdr3DObjectAttribute(const SfxItemSet& rSet)
42cdf0e10cSrcweir 		{
43cdf0e10cSrcweir 			// get NormalsKind
44cdf0e10cSrcweir 			::com::sun::star::drawing::NormalsKind aNormalsKind(::com::sun::star::drawing::NormalsKind_SPECIFIC);
45cdf0e10cSrcweir 			const sal_uInt16 nNormalsValue(((const Svx3DNormalsKindItem&)rSet.Get(SDRATTR_3DOBJ_NORMALS_KIND)).GetValue());
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 			if(1L == nNormalsValue)
48cdf0e10cSrcweir 			{
49cdf0e10cSrcweir 				aNormalsKind = ::com::sun::star::drawing::NormalsKind_FLAT;
50cdf0e10cSrcweir 			}
51cdf0e10cSrcweir 			else if(2L == nNormalsValue)
52cdf0e10cSrcweir 			{
53cdf0e10cSrcweir 				aNormalsKind = ::com::sun::star::drawing::NormalsKind_SPHERE;
54cdf0e10cSrcweir 			}
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 			// get NoermalsInvert flag
57cdf0e10cSrcweir 			const bool bInvertNormals(((const Svx3DNormalsInvertItem&)rSet.Get(SDRATTR_3DOBJ_NORMALS_INVERT)).GetValue());
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 			// get TextureProjectionX
60cdf0e10cSrcweir 			::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC);
61cdf0e10cSrcweir 			const sal_uInt16 nTextureValueX(((const Svx3DTextureProjectionXItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_X)).GetValue());
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 			if(1L == nTextureValueX)
64cdf0e10cSrcweir 			{
65cdf0e10cSrcweir 				aTextureProjectionX = ::com::sun::star::drawing::TextureProjectionMode_PARALLEL;
66cdf0e10cSrcweir 			}
67cdf0e10cSrcweir 			else if(2L == nTextureValueX)
68cdf0e10cSrcweir 			{
69cdf0e10cSrcweir 				aTextureProjectionX = ::com::sun::star::drawing::TextureProjectionMode_SPHERE;
70cdf0e10cSrcweir 			}
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 			// get TextureProjectionY
73cdf0e10cSrcweir 			::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC);
74cdf0e10cSrcweir 			const sal_uInt16 nTextureValueY(((const Svx3DTextureProjectionYItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_Y)).GetValue());
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 			if(1L == nTextureValueY)
77cdf0e10cSrcweir 			{
78cdf0e10cSrcweir 				aTextureProjectionY = ::com::sun::star::drawing::TextureProjectionMode_PARALLEL;
79cdf0e10cSrcweir 			}
80cdf0e10cSrcweir 			else if(2L == nTextureValueY)
81cdf0e10cSrcweir 			{
82cdf0e10cSrcweir 				aTextureProjectionY = ::com::sun::star::drawing::TextureProjectionMode_SPHERE;
83cdf0e10cSrcweir 			}
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 			// get DoubleSided flag
86cdf0e10cSrcweir 			const bool bDoubleSided(((const Svx3DDoubleSidedItem&)rSet.Get(SDRATTR_3DOBJ_DOUBLE_SIDED)).GetValue());
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 			// get Shadow3D flag
89cdf0e10cSrcweir 			const bool bShadow3D(((const Svx3DShadow3DItem&)rSet.Get(SDRATTR_3DOBJ_SHADOW_3D)).GetValue());
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 			// get TextureFilter flag
92cdf0e10cSrcweir 			const bool bTextureFilter(((const Svx3DTextureFilterItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_FILTER)).GetValue());
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 			// get texture kind
95cdf0e10cSrcweir 			// TextureKind: 1 == Base3DTextureLuminance, 2 == Base3DTextureIntensity, 3 == Base3DTextureColor
96cdf0e10cSrcweir 			::com::sun::star::drawing::TextureKind2 aTextureKind(::com::sun::star::drawing::TextureKind2_LUMINANCE);
97cdf0e10cSrcweir 			const sal_uInt16 nTextureKind(((const Svx3DTextureKindItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_KIND)).GetValue());
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 			if(2 == nTextureKind)
100cdf0e10cSrcweir 			{
101cdf0e10cSrcweir 				aTextureKind = ::com::sun::star::drawing::TextureKind2_INTENSITY;
102cdf0e10cSrcweir 			}
103cdf0e10cSrcweir 			else if(3 == nTextureKind)
104cdf0e10cSrcweir 			{
105cdf0e10cSrcweir 				aTextureKind = ::com::sun::star::drawing::TextureKind2_COLOR;
106cdf0e10cSrcweir 			}
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 			// get texture mode
109cdf0e10cSrcweir 			// TextureMode: 1 == Base3DTextureReplace, 2 == Base3DTextureModulate, 3 == Base3DTextureBlend
110cdf0e10cSrcweir 			::com::sun::star::drawing::TextureMode aTextureMode(::com::sun::star::drawing::TextureMode_REPLACE);
111cdf0e10cSrcweir 			const sal_uInt16 nTextureMode(((const Svx3DTextureModeItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_MODE)).GetValue());
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 			if(2 == nTextureMode)
114cdf0e10cSrcweir 			{
115cdf0e10cSrcweir 				aTextureMode = ::com::sun::star::drawing::TextureMode_MODULATE;
116cdf0e10cSrcweir 			}
117cdf0e10cSrcweir 			else if(3 == nTextureMode)
118cdf0e10cSrcweir 			{
119cdf0e10cSrcweir 				aTextureMode = ::com::sun::star::drawing::TextureMode_BLEND;
120cdf0e10cSrcweir 			}
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 			// get object color
123cdf0e10cSrcweir 			const ::basegfx::BColor aObjectColor(((const XFillColorItem&)rSet.Get(XATTR_FILLCOLOR)).GetColorValue().getBColor());
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 			// get specular color
126cdf0e10cSrcweir 			const ::basegfx::BColor aSpecular(((const Svx3DMaterialSpecularItem&)rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR)).GetValue().getBColor());
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 			// get emissive color
129cdf0e10cSrcweir 			const ::basegfx::BColor aEmission(((const Svx3DMaterialEmissionItem&)rSet.Get(SDRATTR_3DOBJ_MAT_EMISSION)).GetValue().getBColor());
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 			// get specular intensity
132cdf0e10cSrcweir 			sal_uInt16 nSpecularIntensity(((const Svx3DMaterialSpecularIntensityItem&)rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR_INTENSITY)).GetValue());
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 			if(nSpecularIntensity > 128)
135cdf0e10cSrcweir 			{
136cdf0e10cSrcweir 				nSpecularIntensity = 128;
137cdf0e10cSrcweir 			}
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 			// get reduced line geometry
140cdf0e10cSrcweir 			const bool bReducedLineGeometry(((const Svx3DReducedLineGeometryItem&)rSet.Get(SDRATTR_3DOBJ_REDUCED_LINE_GEOMETRY)).GetValue());
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 			// prepare material
143cdf0e10cSrcweir 			attribute::MaterialAttribute3D aMaterial(aObjectColor, aSpecular, aEmission, nSpecularIntensity);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 			return new attribute::Sdr3DObjectAttribute(
146cdf0e10cSrcweir 				aNormalsKind, aTextureProjectionX, aTextureProjectionY,
147cdf0e10cSrcweir 				aTextureKind, aTextureMode, aMaterial,
148cdf0e10cSrcweir 				bInvertNormals, bDoubleSided, bShadow3D, bTextureFilter, bReducedLineGeometry);
149cdf0e10cSrcweir 		}
150cdf0e10cSrcweir 	} // end of namespace primitive2d
151cdf0e10cSrcweir } // end of namespace sdr
152cdf0e10cSrcweir 
153cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
154cdf0e10cSrcweir // eof
155