Skip to content

Commit aa1c782

Browse files
committed
add new ShapeGroup methods, fix bugs, expand squares.html demo
1 parent e3415be commit aa1c782

File tree

4 files changed

+332
-56
lines changed

4 files changed

+332
-56
lines changed

glutil-shaderprog.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ ShaderProgram.prototype.use=function(){
153153
}
154154
/** @private */
155155
ShaderProgram.prototype._log=function(i,v){
156-
// console.log("setting "+i+": "+v);
156+
//console.log("setting "+i+": "+v);
157157
}
158158
/** @private */
159159
ShaderProgram.prototype._setUniform=function(uniforms,i,isCurrentProgram){
@@ -178,6 +178,7 @@ ShaderProgram.prototype._setUniform=function(uniforms,i,isCurrentProgram){
178178
newUv=true;
179179
} else if(uv!=v){
180180
uv=v;
181+
this.uniformValues[i]=v;
181182
newUv=true;
182183
}
183184
if(newUv){

glutil.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ Lights.prototype.setPointLight=function(index,position){
641641
* May be null or omitted; default is (0,0,0).
642642
*/
643643
function Material(ambient, diffuse, specular,shininess,emission) {
644+
//console.log([ambient,diffuse,specular,shininess,emission]+"")
644645
if(ambient!=null)ambient=GLUtil["toGLColor"](ambient)
645646
if(diffuse!=null)diffuse=GLUtil["toGLColor"](diffuse)
646647
if(specular!=null)specular=GLUtil["toGLColor"](specular)
@@ -1795,12 +1796,12 @@ Scene3D.prototype.render=function(){
17951796
if(typeof this.fboFilter!="undefined" && this.fboFilter){
17961797
// Render to the framebuffer, then to the main buffer via
17971798
// a filter
1798-
this.fbo.bind(this.program);
1799-
this._renderInner();
1800-
this.fbo.unbind();
18011799
var oldProgram=this.program;
18021800
var oldProj=this._projectionMatrix.slice(0,16);
18031801
var oldView=this._viewMatrix.slice(0,16);
1802+
this.fbo.bind(this.program);
1803+
this._renderInner();
1804+
this.fbo.unbind();
18041805
this.useProgram(this.fboFilter);
18051806
this.context.clear(
18061807
this.context.COLOR_BUFFER_BIT|this.context.DEPTH_BUFFER_BIT);
@@ -1906,13 +1907,17 @@ function ShapeGroup(){
19061907
* @param {*} shape
19071908
*/
19081909
ShapeGroup.prototype.addShape=function(shape){
1909-
this.shapes.add(shape);
1910+
shape.parent=this;
1911+
this.shapes.push(shape);
19101912
}
19111913
/**
19121914
* Not documented yet.
19131915
*/
19141916
ShapeGroup.prototype.getTransform=function(){
1915-
return this.getTransform();
1917+
return this.transform;
1918+
}
1919+
ShapeGroup.prototype.getMatrix=function(){
1920+
return this.getTransform().getMatrix();
19161921
}
19171922
/**
19181923
* Not documented yet.
@@ -1922,6 +1927,18 @@ ShapeGroup.prototype.setTransform=function(transform){
19221927
this.transform=transform.copy();
19231928
return this;
19241929
}
1930+
ShapeGroup.prototype.setPosition=function(x,y,z){
1931+
this.transform.setPosition(x,y,z)
1932+
return this;
1933+
}
1934+
ShapeGroup.prototype.setQuaternion=function(quat){
1935+
this.transform.setQuaternion(quat);
1936+
return this;
1937+
}
1938+
ShapeGroup.prototype.setScale=function(x,y,z){
1939+
this.transform.setScale(x,y,z);
1940+
return this;
1941+
}
19251942
/**
19261943
* An object that associates a geometric mesh (the shape of the object) with
19271944
* material data (which defines what is seen on the object's surface)
@@ -2060,7 +2077,12 @@ Shape.prototype.setQuaternion=function(quat){
20602077
* @return {Array<number>} The current transformation matrix.
20612078
*/
20622079
Shape.prototype.getMatrix=function(){
2063-
return this.getTransform().getMatrix();
2080+
var mat=this.getTransform().getMatrix();
2081+
if(this.parent!=null){
2082+
var pmat=this.parent.getMatrix();
2083+
mat=GLMath.mat4multiply(pmat,mat);
2084+
}
2085+
return mat;
20642086
}
20652087
/////////////
20662088
// Deprecated methods

glutil_min.js

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)