00001 /* 00002 This file is part of the Virtual Object System of 00003 the Interreality project (http://interreality.org). 00004 00005 Copyright (C) 2001, 2002 Peter Amstutz 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 Peter Amstutz <tetron@interreality.org> 00022 */ 00023 #ifndef _MATERIAL_HH_ 00024 #define _MATERIAL_HH_ 00025 00026 #if defined(_WIN32) && defined(_MSC_VER) 00027 # ifdef A3DL_EXPORTS 00028 # define A3DL_API __declspec(dllexport) 00029 # else 00030 # define A3DL_API __declspec(dllimport) 00031 # endif 00032 #else 00033 # define A3DL_API 00034 #endif 00035 00036 #include <vos/corelibs/vos/vos.hh> 00037 #include <vos/metaobjects/property/property.hh> 00038 #include "texture.hh" 00039 00040 namespace A3DL 00041 { 00042 /** Contains material (appearence) information for a 3D object. 00043 * @todo Need to add functions for setting shading (CS mixmode |= 00044 * CS_FX_GORAUD), keycolor (CS mixmode |= CS_FX_KEYCOLOR), tiling (CS 00045 * mixmode |= CS_FX_TILING) 00046 */ 00047 class A3DL_API Material : public virtual MetaObject 00048 { 00049 protected: 00050 PropertyAccessControl* accesscontrol; 00051 public: 00052 Material(MetaObject* superobject); 00053 virtual ~Material(); 00054 00055 static MetaObject* new_Material(MetaObject* superobject, const string& type); 00056 static void registerExtenders(); 00057 virtual const string getType(); 00058 00059 void setPropertyAccessControl(PropertyAccessControl* pac) { accesscontrol = pac; } 00060 PropertyAccessControl* getPropertyAccessControl(){ return accesscontrol; } 00061 00062 /** Insert a new texture layer into this material at the given index, 00063 * using the given file as the image backend source (using FileProperty) 00064 * @see FileProperty 00065 * @throw FileAccessError if there is an error opening the file 00066 */ 00067 virtual Texture* insertTextureLayerFromFile(int idx, const string& filename, const string& datatype); 00068 00069 /** Add and remove texture layers. */ 00070 //@{ 00071 virtual vector<Texture*> getTextureLayers(); 00072 virtual Texture* getTextureLayer(int idx); ///< Use a vRef or call release on the returned object. @return 0 if idx is greater than the number of texture layers. 00073 virtual void insertTextureLayer(int idx, Texture& t); 00074 virtual void insertTextureLayer(int idx, Texture* t) { 00075 assert(t); 00076 insertTextureLayer(idx, *t); 00077 } 00078 virtual void replaceTextureLayer(int idx, Texture& t); 00079 virtual void replaceTextureLayer(int idx, Texture* t) { 00080 assert(t); 00081 replaceTextureLayer(idx, *t); 00082 } 00083 virtual void removeTextureLayer(int idx); 00084 //@} 00085 00086 /** The "base" color of the material: a color to use if there are no 00087 * texture layers. 00088 */ 00089 //@{ 00090 virtual void setColor(float r, float g, float b); 00091 virtual void getColor(float& r, float& g, float& b); 00092 //@} 00093 00094 /** Convert an HTML-style hex triplet ("#RRGGBB") to three normalized 00095 * (0.0-1.0) floating-point values. 00096 * @todo Move this out into just the A3DL namespace? 00097 * */ 00098 static void hexStringToFloats(const string& str, float& r, float& g, float& b); 00099 00100 /** Convert three normalized floats (0.0-1.0) to an HTML-style hex 00101 * tripplet ("#RRGGBB). If any input parameter is less than 0.0, 00102 * it is considered to be 0. If any parameter is greater than 1.0, 00103 * it is considered to be 1. 00104 * @todo Move this out into just the A3DL namespace? 00105 */ 00106 static void floatsToHexString(float r, float g, float b, string& str); 00107 00108 /** Set transparency of the object. 00109 @param t A value between 0 (no transparency) and 1 (fully 00110 transparent). Some renderers may round to certain 00111 values (e.g. 1.0, 0.75, 0.5, 0.25, 0.0) 00112 If t is > 1, 1 will be used. If t < 0, 0 will be 00113 used. 00114 */ 00115 virtual void setTransparency(double t, PropertyAccessControl* ac = 00116 &NoPropertyAccessControl::static_); 00117 00118 /** Get transparency. Will be between 0 (no transparency) and 00119 1 (fully transparent). 00120 @throws Vobject:NoSuchObjectError if there is no "a3dl:transparency" object. 00121 */ 00122 virtual double getTransparency(); 00123 00124 /** Get transparency property. */ 00125 virtual Property* getTransparencyObj(); 00126 00127 /** Set transparency property object */ 00128 virtual void setTransparencyObj(Property* obj); 00129 00130 /** Set special blend mode. Must be one of the following: 00131 * MeshBase::BLEND_ADD 00132 * MeshBase::BLEND_MULTIPLY 00133 * MeshBase::BLEND_DOUBLE_MULTIPLY 00134 * MeshBase::BLEND_NORMAL 00135 * These blend modes determine how the background 00136 * affects the object's material. 00137 */ 00138 virtual void setBlendMode(short mode); 00139 00140 /** Get special blend mode. Will be one of the following: 00141 * MeshBase::BLEND_ADD 00142 * MeshBase::BLEND_MULTIPLY 00143 * MeshBase::BLEND_DOUBLE_MULTIPLY 00144 * MeshBase::BLEND_NORMAL 00145 * These blend modes determine how the background affects the 00146 * object's material. 00147 * @throws Vobject::NoSuchObjectError if there is no "a3dl:blend-mode" 00148 * property. 00149 */ 00150 virtual short getBlendMode(); 00151 00152 /** Get blend mode property object. */ 00153 virtual Property* getBlendModeObj(); 00154 00155 /** Set blend mode property object. */ 00156 virtual void setBlendModeObj(Property* obj); 00157 00158 /** Special blend modes for setBlendMode() and getBlendMode() */ 00159 //@{ 00160 enum BlendModes {BLEND_ADD, BLEND_MULTIPLY, BLEND_DOUBLE_MULTIPLY, BLEND_NORMAL}; 00161 //@} 00162 00163 00164 /** Set blend color: this color modifies the blending of this object 00165 * against its background. 00166 */ 00167 virtual void setBlendColor(double r, double g, double b); 00168 00169 /** Get blend color 00170 * @throws Vobject::NoSuchObjectError if there is no "a3dl:blend-mode" 00171 * property. 00172 */ 00173 virtual void getBlendColor(double& r, double& g, double& b); 00174 00175 virtual void setBlendColorObj(Property* obj); 00176 virtual Property* getBlendColorObj(); 00177 }; 00178 } 00179 00180 #endif