Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/3D/a3dl/texture.cc

Go to the documentation of this file.
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 
00024 #include "texture.hh"
00025 #include <vos/metaobjects/property/fileproperty.hh>
00026 #include "material.hh"
00027 
00028 using namespace A3DL;
00029 
00030 Texture::Texture(MetaObject* superobject)
00031     : MetaObject(superobject)
00032 {
00033 }
00034 
00035 Texture::~Texture()
00036 {
00037 }
00038 
00039 MetaObject* Texture::new_Texture(MetaObject* superobject, const string& type)
00040 {
00041     return new Texture(superobject);
00042 }
00043 
00044 const string Texture::getType()
00045 {
00046     return "a3dl:texture";
00047 }
00048 
00049 void Texture::registerExtenders()
00050 {
00051     LocalSite::addLocalObjectExtension(typeid(Texture).name(), &Texture::new_Texture);
00052     LocalSite::addLocalObjectExtension("a3dl:texture", &Texture::new_Texture);
00053     RemoteSite::addRemoteObjectExtension(typeid(Texture).name(), &Texture::new_Texture);
00054     RemoteSite::addRemoteObjectExtension("a3dl:texture", &Texture::new_Texture);
00055 }
00056 
00057 void Texture::setImage(Property* p) {
00058     try {
00059         vRef<ParentChildRelation> pcr = findChild("a3dl:image");
00060         setChild(pcr->position, "a3dl:image", p);
00061     } catch(NoSuchObjectError) {
00062         insertChild(-1, "a3dl:image", p);
00063     }
00064 }
00065 
00066 void Texture::setImageData(const string& data, const string& datatype) {
00067     Property::setProperty(*this, "a3dl:image", data, datatype, accesscontrol);
00068 }
00069 
00070 Property* Texture::getImage() {
00071     return meta_cast<Property*>(&findObject("a3dl:image"));
00072 }
00073 
00074 void Texture::setImageToFile(const string& filename, const string& datatype)
00075 {
00076     int i;
00077     for(i = filename.size()-1; i > 0 && filename[i] != '/'; i--);
00078     if(filename[i] == '/') i++;
00079 
00080     vRef<FileProperty> fp = meta_cast<FileProperty*>(Site::getDefaultPeer()->createMetaObject(filename.substr(i).c_str(),
00081                                                                                               typeid(FileProperty).name(), 0));
00082      if(&fp) {
00083          fp->setFileBackend(filename, datatype);
00084          fp->insertPropertyAccessControl(-1, accesscontrol);
00085          int pos = -1;
00086          try {
00087              vRef<ParentChildRelation> pcr = findChild("a3dl:image");
00088              pos = pcr->position;
00089          } catch(NoSuchObjectError) {
00090          } catch(AccessControlError) {
00091          } catch(RemoteError) {
00092          }
00093          if(pos > -1) setChild(pos, "a3dl:image", &fp);
00094          else insertChild(-1, "a3dl:image", &fp);
00095      } else {
00096          LOG("meshbase", 2, "You don't seem to have the FileProperty plugin initialized!");
00097      }
00098 }
00099 
00100 void Texture::setBlendMode(short m) {
00101     string ms("none");
00102     switch(m) {
00103         case Material::BLEND_ADD:
00104             ms = "add";
00105             break;
00106         case Material::BLEND_MULTIPLY:
00107             ms = "multiply";
00108             break;
00109         case Material::BLEND_DOUBLE_MULTIPLY:
00110             ms = "double multiply";
00111             break;
00112     }
00113     Property::setProperty(*this, "a3dl:blend-mode", ms, "text/plain", accesscontrol);
00114 }
00115 
00116 short Texture::getBlendMode() {
00117     string s;
00118     try {
00119     vRef<Property> p = meta_cast<Property*>(&findObject("a3dl:blend-mode"));
00120     if(!&p) return Material::BLEND_NORMAL;
00121     p->read(s);
00122     if(s == "add")
00123         return Material::BLEND_ADD;
00124     if(s == "multiply")
00125         return Material::BLEND_MULTIPLY;
00126     if(s == "double multiply")
00127         return Material::BLEND_DOUBLE_MULTIPLY;
00128     return Material::BLEND_NORMAL;
00129     } catch(...) {
00130         return Material::BLEND_NORMAL;
00131     }
00132 }
00133 
00134 
00135 Property* Texture::getBlendModeObj() {
00136     return meta_cast<Property*>(&findObject("a3dl:blend-mode"));
00137 }
00138 
00139 void Texture::setBlendModeObj(Property* p) {
00140     try {
00141         vRef<ParentChildRelation> pcr = findChild("a3dl:blend-mode");
00142         setChild(pcr->position, "a3dl:blend-mode", p);
00143     } catch(NoSuchObjectError) {
00144         insertChild(-1, "a3dl:blend-mode", p);
00145     }
00146 }
00147 
00148 void Texture::setTransparency(double t, PropertyAccessControl* ac) {
00149     Property::setFloatProperty(*this, "a3dl:transparency", t, 0.0, 1.0, ac);
00150 }
00151 
00152 double Texture::getTransparency() {
00153     return Property::getFloatProperty(*this, "a3dl:transparency", 0.0, 1.0);
00154 }
00155 
00156 Property* Texture::getTransparencyObj() {
00157     return meta_cast<Property*>(&findObject("a3dl:transparency"));
00158 }
00159 
00160 void Texture::setTransparencyObj(Property* p) {
00161     try {
00162         vRef<ParentChildRelation> pcr = findChild("a3dl:transparency");
00163         setChild(pcr->position, "a3dl:transparency", p);
00164     } catch(NoSuchObjectError) {
00165         insertChild(-1, "a3dl:transparency", p);
00166     }
00167 }
00168 
00169 void Texture::setUVScaleAndShift(float uscale, float vscale, float ushift, float vshift)
00170 {
00171     char s[256];
00172     sprintf(s, "%f %f %f %f", uscale, vscale, ushift, vshift);
00173     Property::setProperty(*this, "a3dl:uv-scale-shift", s, "text/x-vector", accesscontrol);
00174 }
00175 
00176 void Texture::getUVScaleAndShift(float& uscale, float& vscale, float& ushift, float& vshift)
00177 {
00178     string s;
00179     try {
00180     vRef<Property> p = meta_cast<Property*>(&findObject("a3dl:blend-mode"));
00181     if(!&p) throw bad_cast();
00182     p->read(s);
00183 
00184     sscanf(s.c_str(), " %f %f %f %f ", &uscale, &vscale, &ushift, &vshift);
00185     } catch(bad_cast) {
00186         uscale = vscale = ushift = vshift = 0;
00187     } catch(NoSuchObjectError) {
00188         uscale = vscale = ushift = vshift = 0;
00189     }
00190 }
00191 
00192 
00193 void Texture::setTransparentKeycolor(float r, float g, float b)
00194 {
00195     char s[256];
00196     sprintf(s, "%f %f %f", r, g, b);
00197     Property::setProperty(*this, "a3dl:transparent-keycolor", s, "text/x-vector", accesscontrol);
00198 }
00199 
00200 void Texture::getTransparentKeycolor(float& r, float& g, float& b)
00201 {
00202     string s;
00203     try {
00204     vRef<Property> p = meta_cast<Property*>(&findObject("a3dl:transparent-keycolor"));
00205     if(!&p) throw bad_cast();
00206     p->read(s);
00207 
00208     sscanf(s.c_str(), " %f %f %f ", &r, &g, &b);
00209     } catch(bad_cast) {
00210         r = g = b = 0;
00211     } catch(NoSuchObjectError) {
00212         r = g = b = 0;
00213     }
00214 }
00215 
00216 void Texture::setShaded(bool s, PropertyAccessControl* ac) {
00217     Property::setBoolProperty(*this, "a3dl:shaded", s, ac);
00218 }
00219 
00220 bool Texture::getShaded() {
00221     return Property::getBoolProperty(*this, "a3dl:shaded");
00222 }
00223 
00224 
00225 Property* Texture::getShadedObj() {
00226     return meta_cast<Property*>(&findObject("a3dl:shaded"));
00227 }
00228 
00229 void Texture::setShadedObj(Property* p) {
00230     try {
00231         vRef<ParentChildRelation> pcr = findChild("a3dl:shaded");
00232         setChild(pcr->position, "a3dl:shaded", p);
00233     } catch(NoSuchObjectError) {
00234         insertChild(-1, "a3dl:shaded", p);
00235     }
00236 }
00237 

Generated on Tue Aug 12 03:55:37 2003 for Interreality Project - VOS by doxygen 1.3.2