@@ -1802,9 +1802,15 @@ Scene3D.prototype.render=function(){
18021802
18031803/** @private */
18041804Scene3D . prototype . _renderShape = function ( shape , program ) {
1805+ if ( shape . constructor == ShapeGroup ) {
1806+ for ( var i = 0 ; i < shape . shapes . length ; i ++ ) {
1807+ this . _renderShape ( shape . shapes [ i ] , program ) ;
1808+ }
1809+ } else {
18051810 this . _setupMatrices ( shape , program ) ;
18061811 Binders . getMaterialBinder ( shape . material ) . bind ( program ) ;
18071812 shape . bufferedMesh . draw ( program ) ;
1813+ }
18081814}
18091815/**
18101816 * Uses a shader program to apply a texture filter after the
@@ -1865,6 +1871,20 @@ Scene3D.prototype._renderInner=function(){
18651871 return this ;
18661872}
18671873
1874+ function ShapeGroup ( ) {
1875+ this . shapes = [ ] ;
1876+ this . transform = new Transform ( ) ;
1877+ }
1878+ ShapeGroup . prototype . addShape = function ( shape ) {
1879+ this . shapes . add ( shape ) ;
1880+ }
1881+ ShapeGroup . prototype . getTransform = function ( ) {
1882+ return this . getTransform ( ) ;
1883+ }
1884+ ShapeGroup . prototype . setTransform = function ( transform ) {
1885+ this . transform = transform . copy ( ) ;
1886+ return this ;
1887+ }
18681888/**
18691889* An object that associates a geometric mesh (the shape of the object) with
18701890* material data (which defines what is seen on the object's surface)
@@ -1881,6 +1901,7 @@ function Shape(mesh){
18811901 this . bufferedMesh = mesh ;
18821902 this . transform = new Transform ( ) ;
18831903 this . material = new Material ( ) ;
1904+ this . parent = null ;
18841905}
18851906/**
18861907 * Not documented yet.
@@ -1895,34 +1916,6 @@ Shape.prototype.primitiveCount=function(){
18951916 return ( this . bufferedMesh ) ? this . bufferedMesh . primitiveCount ( ) : 0 ;
18961917}
18971918
1898- /**
1899- * Makes a copy of this object. The copied object
1900- * will have its own version of the transform and
1901- * material data, but any texture
1902- * image data and vertex buffers will not be duplicated,
1903- * but rather just references to them will be used.
1904- * @return {glutil.Shape } A copy of this object.
1905- */
1906- Shape . prototype . copy = function ( ) {
1907- var ret = new Shape ( this . bufferedMesh ) ;
1908- ret . material = this . material . copy ( ) ;
1909- ret . transform = this . transform . copy ( ) ;
1910- return ret ;
1911- }
1912-
1913-
1914- /**
1915- * Sets this shape's transformation matrix. This method
1916- * will set the position, rotation, and scale properties
1917- * accordingly to the matrix given.
1918- * @param {Array<number> } value A 4x4 matrix.
1919- * This method will copy the value of this parameter.
1920- * @return {glutil.Shape } This object.
1921- */
1922- Shape . prototype . setMatrix = function ( value ) {
1923- this . transform . setMatrix ( value ) ;
1924- return this ;
1925- }
19261919/**
19271920* Sets material parameters that give the shape a certain color.
19281921* However, if the mesh defines its own colors, those colors will take
@@ -1961,16 +1954,24 @@ Shape.prototype.setMaterial=function(material){
19611954 return this ;
19621955}
19631956/**
1964- * Resets this shape to the untransformed state.
1965- * @return {glutil.Shape } This object.
1957+ * Makes a copy of this object. The copied object
1958+ * will have its own version of the transform and
1959+ * material data, but any texture
1960+ * image data and vertex buffers will not be duplicated,
1961+ * but rather just references to them will be used.
1962+ * @return {glutil.Shape } A copy of this object.
19661963*/
1967- Shape . prototype . resetTransform = function ( ) {
1968- this . matrix = GLMath . mat4identity ( ) ;
1969- this . position = [ 0 , 0 , 0 ] ;
1970- this . scale = [ 1 , 1 , 1 ] ;
1971- this . rotation = GLMath . quatIdentity ( ) ;
1972- this . complexMatrix = false ;
1973- this . _matrixDirty = false ;
1964+ Shape . prototype . copy = function ( ) {
1965+ var ret = new Shape ( this . bufferedMesh ) ;
1966+ ret . material = this . material . copy ( ) ;
1967+ ret . transform = this . getTransform ( ) . copy ( ) ;
1968+ return ret ;
1969+ }
1970+ Shape . prototype . getTransform = function ( ) {
1971+ return this . transform ;
1972+ }
1973+ Shape . prototype . setTransform = function ( transform ) {
1974+ this . transform = transform . copy ( ) ;
19741975 return this ;
19751976}
19761977/**
@@ -1983,7 +1984,7 @@ Shape.prototype.resetTransform=function(){
19831984* @return {glutil.Scene3D } This object.
19841985 */
19851986Shape . prototype . setScale = function ( x , y , z ) {
1986- this . transform . setScale ( x , y , z ) ;
1987+ this . getTransform ( ) . setScale ( x , y , z ) ;
19871988 return this ;
19881989}
19891990/**
@@ -1996,7 +1997,7 @@ Shape.prototype.setScale=function(x,y,z){
19961997* @return {glutil.Scene3D } This object.
19971998 */
19981999Shape . prototype . setPosition = function ( x , y , z ) {
1999- this . transform . setPosition ( x , y , z ) ;
2000+ this . getTransform ( ) . setPosition ( x , y , z ) ;
20002001 return this ;
20012002}
20022003/**
@@ -2006,57 +2007,7 @@ Shape.prototype.setPosition=function(x,y,z){
20062007 * @return {glutil.Shape } This object.
20072008 */
20082009Shape . prototype . setQuaternion = function ( quat ) {
2009- this . transform . setQuaternion ( quat ) ;
2010- return this ;
2011- }
2012- /**
2013- * Sets this object's orientation in the form of an angle and an axis of
2014- * rotation.
2015- * See {@link glutil.Transform.setOrientation}.
2016- * @param {Array<number>|number } angle The desired angle
2017- * to rotate in degrees, or a 4-element array as described in {@link glutil.Transform.setOrientation}.
2018- * @param {Array<number>|number } v X-component of the axis
2019- * of rotation or a 3-element array giving the axis
2020- * of rotation in x, y, and z, respectively.
2021- * @param {number } vy Y-component of the axis
2022- * of rotation.
2023- * @param {number } vz Z-component of the axis
2024- * of rotation.
2025- * @return {glutil.Shape } This object.
2026- */
2027- Shape . prototype . setOrientation = function ( angle , v , vy , vz ) {
2028- this . transform . setOrientation ( angle , v , vy , vz ) ;
2029- return this ;
2030- }
2031- /**
2032- * Combines this shape's current rotation with another rotation
2033- * described by a [quaternion]{@link glmath.GLMath}.
2034- * See {@link glutil.Transform.multQuaternion}.
2035- * @param {Array<number> } quat A four-element array describing the rotation.
2036- * @return {glutil.Shape } This object.
2037- */
2038- Shape . prototype . multQuaternion = function ( quat ) {
2039- this . transform . multQuaternion ( angle , v , vy , vz ) ;
2040- return this ;
2041- }
2042- /**
2043- * Combines this shape's current orientation with another orientation
2044- * in the form of an angle and an axis of
2045- * rotation.
2046- * See {@link glutil.Transform.multOrientation}.
2047- * @param {Array<number>|number } angle The desired angle
2048- * to rotate in degrees, or a 4-element array as described in {@link glutil.Transform.setOrientation}.
2049- * @param {Array<number>|number } v X-component of the axis
2050- * of rotation or a 3-element array giving the axis
2051- * of rotation in x, y, and z, respectively.
2052- * @param {number } vy Y-component of the axis
2053- * of rotation.
2054- * @param {number } vz Z-component of the axis
2055- * of rotation.
2056- * @return {glutil.Shape } This object.
2057- */
2058- Shape . prototype . multOrientation = function ( angle , v , vy , vz ) {
2059- this . transform . multOrientation ( angle , v , vy , vz ) ;
2010+ this . getTransform ( ) . setQuaternion ( quat ) ;
20602011 return this ;
20612012}
20622013/**
@@ -2065,10 +2016,29 @@ Shape.prototype.multOrientation=function(angle, v,vy,vz){
20652016 * @return {Array<number> } The current transformation matrix.
20662017 */
20672018Shape . prototype . getMatrix = function ( ) {
2068- return this . transform . getMatrix ( ) ;
2019+ return this . getTransform ( ) . getMatrix ( ) ;
20692020}
2021+ /////////////
2022+ // Deprecated methods
2023+ /** @deprecated Use Shape.getTransform().multQuaternion(...) instead. */
2024+ Shape . prototype . multQuaternion = function ( x ) {
2025+ this . getTransform ( ) . multQuaternion ( x ) ;
2026+ return this ;
2027+ }
2028+ /** @deprecated Use Shape.getTransform().multOrientation(...) instead. */
2029+ Shape . prototype . multRotation = function ( a , b , c , d ) {
2030+ this . getTransform ( ) . multRotation ( a , b , c , d ) ;
2031+ return this ;
2032+ }
2033+ /** @deprecated Use Shape.getTransform().setOrientation(...) instead. */
2034+ Shape . prototype . setRotation = function ( a , b , c , d ) {
2035+ this . getTransform ( ) . setOrientation ( a , b , c , d ) ;
2036+ return this ;
2037+ }
2038+
20702039/////////////
20712040exports [ "BufferedMesh" ] = BufferedMesh ;
2041+ exports [ "ShapeGroup" ] = ShapeGroup ;
20722042exports [ "Lights" ] = Lights ;
20732043exports [ "FrameBuffer" ] = FrameBuffer ;
20742044exports [ "LightSource" ] = LightSource ;
0 commit comments