API Documentation
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_material_glge_multimaterial.js.html, line: 130 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_material_glge_multimaterial.js.html, line: 130 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_material_glge_multimaterial.js.html, line: 130 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_material_glge_multimaterial.js.html, line: 130 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_material_glge_multimaterial.js.html, line: 130 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_material_glge_multimaterial.js.html, line: 130 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29
1 /* 2 GLGE WebGL Graphics Engine 3 Copyright (c) 2010, Paul Brunt 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 * Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above copyright 11 notice, this list of conditions and the following disclaimer in the 12 documentation and/or other materials provided with the distribution. 13 * Neither the name of GLGE nor the 14 names of its contributors may be used to endorse or promote products 15 derived from this software without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY 21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * @fileOverview 31 * @name glge_multimaterial.js 32 * @author me@paulbrunt.co.uk 33 */ 34 35 36 (function(GLGE){ 37 38 /** 39 * @name GLGE.MultiMaterial#downloadComplete 40 * @event fires when all the assets for this class have finished loading 41 * @param {object} data 42 */ 43 44 /** 45 * @class Creates a new mesh/material to add to an object 46 * @augments GLGE.QuickNotation 47 * @augments GLGE.JSONLoader 48 * @augments GLGE.Events 49 */ 50 GLGE.MultiMaterial=function(uid){ 51 var multiMaterial=this; 52 this.downloadComplete=function(){ 53 if(multiMaterial.isComplete()) multiMaterial.fireEvent("downloadComplete"); 54 } 55 this.boundUpdate=function(){ 56 multiMaterial.fireEvent("boundupdate"); 57 } 58 this.lods=[new GLGE.ObjectLod]; 59 this.lods[0].addEventListener("downloadComplete",this.downloadComplete); 60 this.lods[0].addEventListener("boundupdate",this.boundUpdate); 61 GLGE.Assets.registerAsset(this,uid); 62 } 63 GLGE.augment(GLGE.QuickNotation,GLGE.MultiMaterial); 64 GLGE.augment(GLGE.JSONLoader,GLGE.MultiMaterial); 65 GLGE.augment(GLGE.Events,GLGE.MultiMaterial); 66 GLGE.MultiMaterial.prototype.className="MultiMaterial"; 67 GLGE.MultiMaterial.prototype.oneLod=true; 68 69 70 /** 71 * Checks if resources have finished downloading 72 * @returns {boolean} 73 */ 74 GLGE.MultiMaterial.prototype.isComplete=function(){ 75 for(var i=0;i<this.lods.length;i++){ 76 if(!this.lods[i].isComplete()) return false; 77 } 78 return true; 79 } 80 81 /** 82 * sets the mesh 83 * @param {GLGE.Mesh} mesh 84 */ 85 GLGE.MultiMaterial.prototype.setMesh=function(mesh){ 86 this.lods[0].setMesh(mesh); 87 return this; 88 } 89 /** 90 * gets the mesh 91 * @returns {GLGE.Mesh} 92 */ 93 GLGE.MultiMaterial.prototype.getMesh=function(){ 94 return this.lods[0].getMesh(); 95 } 96 /** 97 * sets the material 98 * @param {GLGE.Material} material 99 */ 100 GLGE.MultiMaterial.prototype.setMaterial=function(material){ 101 this.lods[0].setMaterial(material); 102 return this; 103 } 104 /** 105 * gets the material 106 * @returns {GLGE.Material} 107 */ 108 GLGE.MultiMaterial.prototype.getMaterial=function(){ 109 return this.lods[0].getMaterial(); 110 } 111 112 /** 113 * returns the load for a given pixel size 114 * @param {number} pixelsize the current pixel size of the object 115 * @returns {GLGE.ObjectLod} 116 */ 117 GLGE.MultiMaterial.prototype.getLOD=function(pixelsize){ 118 var currentSize=0; 119 var currentLOD=this.lods[0]; 120 if(this.lods.length>1){ 121 for(var i=1; i<this.lods.length;i++){ 122 var size=this.lods[i].pixelSize; 123 if(size>currentSize && size<pixelsize && this.lods[i].mesh && this.lods[i].mesh.loaded){ 124 currentSize=size; 125 currentLOD=this.lods[i]; 126 } 127 } 128 } 129 return currentLOD; 130 } 131 132 /** 133 * adds a lod to this multimaterial 134 * @param {GLGE.ObjectLod} lod the lod to add 135 */ 136 GLGE.MultiMaterial.prototype.addObjectLod=function(lod){ 137 if(this.oneLod){ 138 this.oneLod=false; 139 this.lods=[]; 140 } 141 this.lods.push(lod); 142 lod.addEventListener("downloadComplete",this.downloadComplete); 143 return this; 144 } 145 146 /** 147 * Updates the GL shader program for the object 148 * @private 149 */ 150 GLGE.MultiMaterial.prototype.updateProgram=function(){ 151 for(var i=0; i<this.lods.length;i++){ 152 this.lods[i].GLShaderProgram=null; 153 } 154 return this; 155 } 156 157 158 /** 159 * removes a lod to this multimaterial 160 * @param {GLGE.ObjectLod} lod the lod to remove 161 */ 162 GLGE.MultiMaterial.prototype.removeObjectLod=function(lod){ 163 var idx=this.lods.indexOf(lod); 164 lods[idx].removeEventListener("downloadComplete",this.downloadComplete); 165 if(idx) this.lods.splice(idx,1); 166 return this; 167 } 168 169 170 171 })(GLGE);