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