1 /** 2 * Copyright (C) 2009-2012 Klaus Reimer <k@ailis.de> 3 * See LICENSE.txt for licensing information 4 * 5 * @require threedee.js 6 * @use threedee/rendering/RenderPolygon.js 7 */ 8 9 /** 10 * Constructs a new render model. 11 * 12 * @param {!threedee.Model} model 13 * The original model 14 * 15 * @constructor 16 * @class A render model is a wrapper around a model which is used internally 17 * for rendering the model. It is responsible for transforming the vertices 18 * of the model (and caching them) and it also wraps the polygons of the 19 * model with RenderPolygon objects. 20 */ 21 threedee.RenderModel = function(model) 22 { 23 var i, max; 24 25 this.model = model; 26 27 this.vertices = []; 28 for (i = 0, max = this.model.countVertices(); i < max; i++) 29 this.vertices.push(this.model.getVertex(i).copy()); 30 31 this.polygons = []; 32 for (i = 0, max = this.model.countPolygons(); i < max; i++) 33 this.polygons.push(new threedee.RenderPolygon(model, this.model.getPolygon(i), 34 this.vertices)); 35 }; 36 37 /** 38 * The vertices. 39 * @private 40 * @type {!Array.<!threedee.Vector>} 41 */ 42 threedee.RenderModel.prototype.vertices; 43 44 /** 45 * The polygons. 46 * @private 47 * @type {!Array.<!threedee.RenderPolygon>} 48 */ 49 threedee.RenderModel.prototype.polygons; 50 51 /** 52 * The model. 53 * @private 54 * @type {!threedee.Model} 55 */ 56 threedee.RenderModel.prototype.model; 57 58 /** 59 * Transforms this node model. 60 * 61 * @param {!threedee.Matrix} transform 62 * The transformation matrix 63 */ 64 threedee.RenderModel.prototype.transform = function(transform) 65 { 66 var i, max; 67 68 // Transform the vertices 69 for (i = 0, max = this.vertices.length; i < max; i++) 70 this.model.getVertex(i).copy(this.vertices[i]).transform(transform); 71 }; 72 73 /** 74 * Returns the number of polygons. 75 * 76 * @return {number} The number of polygons 77 */ 78 threedee.RenderModel.prototype.countPolygons = function() 79 { 80 return this.polygons.length; 81 }; 82 83 /** 84 * Returns the polygon with the specified index. 85 * 86 * @param {number} index 87 * The polygon index 88 * @return {!threedee.RenderPolygon} The polygon 89 */ 90 threedee.RenderModel.prototype.getPolygon = function(index) 91 { 92 return this.polygons[index]; 93 }; 94