1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdrattributecreator3d.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
33 #include <svx/svx3ditems.hxx>
34 #include <svtools/itemset.hxx>
35 #include <com/sun/star/drawing/NormalsKind.hpp>
36 #include <com/sun/star/drawing/TextureProjectionMode.hpp>
37 #include <drawinglayer/attribute/sdrattribute3d.hxx>
38 #include <svx/xflclit.hxx>
40 //////////////////////////////////////////////////////////////////////////////
42 namespace drawinglayer
46 attribute::Sdr3DObjectAttribute
* createNewSdr3DObjectAttribute(const SfxItemSet
& rSet
)
49 ::com::sun::star::drawing::NormalsKind
aNormalsKind(::com::sun::star::drawing::NormalsKind_SPECIFIC
);
50 const sal_uInt16
nNormalsValue(((const Svx3DNormalsKindItem
&)rSet
.Get(SDRATTR_3DOBJ_NORMALS_KIND
)).GetValue());
52 if(1L == nNormalsValue
)
54 aNormalsKind
= ::com::sun::star::drawing::NormalsKind_FLAT
;
56 else if(2L == nNormalsValue
)
58 aNormalsKind
= ::com::sun::star::drawing::NormalsKind_SPHERE
;
61 // get NoermalsInvert flag
62 const bool bInvertNormals(((const Svx3DNormalsInvertItem
&)rSet
.Get(SDRATTR_3DOBJ_NORMALS_INVERT
)).GetValue());
64 // get TextureProjectionX
65 ::com::sun::star::drawing::TextureProjectionMode
aTextureProjectionX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC
);
66 const sal_uInt16
nTextureValueX(((const Svx3DTextureProjectionXItem
&)rSet
.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_X
)).GetValue());
68 if(1L == nTextureValueX
)
70 aTextureProjectionX
= ::com::sun::star::drawing::TextureProjectionMode_PARALLEL
;
72 else if(2L == nTextureValueX
)
74 aTextureProjectionX
= ::com::sun::star::drawing::TextureProjectionMode_SPHERE
;
77 // get TextureProjectionY
78 ::com::sun::star::drawing::TextureProjectionMode
aTextureProjectionY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC
);
79 const sal_uInt16
nTextureValueY(((const Svx3DTextureProjectionYItem
&)rSet
.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_Y
)).GetValue());
81 if(1L == nTextureValueY
)
83 aTextureProjectionY
= ::com::sun::star::drawing::TextureProjectionMode_PARALLEL
;
85 else if(2L == nTextureValueY
)
87 aTextureProjectionY
= ::com::sun::star::drawing::TextureProjectionMode_SPHERE
;
90 // get DoubleSided flag
91 const bool bDoubleSided(((const Svx3DDoubleSidedItem
&)rSet
.Get(SDRATTR_3DOBJ_DOUBLE_SIDED
)).GetValue());
94 const bool bShadow3D(((const Svx3DShadow3DItem
&)rSet
.Get(SDRATTR_3DOBJ_SHADOW_3D
)).GetValue());
96 // get TextureFilter flag
97 const bool bTextureFilter(((const Svx3DTextureFilterItem
&)rSet
.Get(SDRATTR_3DOBJ_TEXTURE_FILTER
)).GetValue());
100 // TextureKind: 1 == Base3DTextureLuminance, 2 == Base3DTextureIntensity, 3 == Base3DTextureColor
101 ::com::sun::star::drawing::TextureKind2
aTextureKind(::com::sun::star::drawing::TextureKind2_LUMINANCE
);
102 const sal_uInt16
nTextureKind(((const Svx3DTextureKindItem
&)rSet
.Get(SDRATTR_3DOBJ_TEXTURE_KIND
)).GetValue());
104 if(2 == nTextureKind
)
106 aTextureKind
= ::com::sun::star::drawing::TextureKind2_INTENSITY
;
108 else if(3 == nTextureKind
)
110 aTextureKind
= ::com::sun::star::drawing::TextureKind2_COLOR
;
114 // TextureMode: 1 == Base3DTextureReplace, 2 == Base3DTextureModulate, 3 == Base3DTextureBlend
115 ::com::sun::star::drawing::TextureMode
aTextureMode(::com::sun::star::drawing::TextureMode_REPLACE
);
116 const sal_uInt16
nTextureMode(((const Svx3DTextureModeItem
&)rSet
.Get(SDRATTR_3DOBJ_TEXTURE_MODE
)).GetValue());
118 if(2 == nTextureMode
)
120 aTextureMode
= ::com::sun::star::drawing::TextureMode_MODULATE
;
122 else if(3 == nTextureMode
)
124 aTextureMode
= ::com::sun::star::drawing::TextureMode_BLEND
;
128 const ::basegfx::BColor
aObjectColor(((const XFillColorItem
&)rSet
.Get(XATTR_FILLCOLOR
)).GetColorValue().getBColor());
130 // get specular color
131 const ::basegfx::BColor
aSpecular(((const Svx3DMaterialSpecularItem
&)rSet
.Get(SDRATTR_3DOBJ_MAT_SPECULAR
)).GetValue().getBColor());
133 // get emissive color
134 const ::basegfx::BColor
aEmission(((const Svx3DMaterialEmissionItem
&)rSet
.Get(SDRATTR_3DOBJ_MAT_EMISSION
)).GetValue().getBColor());
136 // get specular intensity
137 sal_uInt16
nSpecularIntensity(((const Svx3DMaterialSpecularIntensityItem
&)rSet
.Get(SDRATTR_3DOBJ_MAT_SPECULAR_INTENSITY
)).GetValue());
139 if(nSpecularIntensity
> 128)
141 nSpecularIntensity
= 128;
144 // get reduced line geometry
145 const bool bReducedLineGeometry(((const Svx3DReducedLineGeometryItem
&)rSet
.Get(SDRATTR_3DOBJ_REDUCED_LINE_GEOMETRY
)).GetValue());
148 attribute::MaterialAttribute3D
aMaterial(aObjectColor
, aSpecular
, aEmission
, nSpecularIntensity
);
150 return new attribute::Sdr3DObjectAttribute(
151 aNormalsKind
, aTextureProjectionX
, aTextureProjectionY
,
152 aTextureKind
, aTextureMode
, aMaterial
,
153 bInvertNormals
, bDoubleSided
, bShadow3D
, bTextureFilter
, bReducedLineGeometry
);
155 } // end of namespace primitive2d
156 } // end of namespace sdr
158 //////////////////////////////////////////////////////////////////////////////