diff options
author | pathorn@chromium.org <pathorn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-28 18:50:00 +0000 |
---|---|---|
committer | pathorn@chromium.org <pathorn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-28 18:50:00 +0000 |
commit | 83f5692868b639409546a9ffbcd6f64c78995a6c (patch) | |
tree | 2f04935713d928e683a5a2687ee20019c683e0a5 /o3d | |
parent | 5658ec7812a5fed0bf5d0e87c91cce447581e88b (diff) | |
download | chromium_src-83f5692868b639409546a9ffbcd6f64c78995a6c.zip chromium_src-83f5692868b639409546a9ffbcd6f64c78995a6c.tar.gz chromium_src-83f5692868b639409546a9ffbcd6f64c78995a6c.tar.bz2 |
o3d-webgl: Fixes errors when loading animated meshes in simpleviewer.
Use setUpO3DParam_ instead of createParam so that the "o3d." names can be used by serialization.js;
simpleviewer calls Pack.destroy which can fail.
Implement o3d.Matrix4Composition.
Typos in curve loading.
Review URL: http://codereview.chromium.org/3020030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53985 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/samples/o3d-webgl/curve.js | 10 | ||||
-rw-r--r-- | o3d/samples/o3d-webgl/function.js | 36 | ||||
-rw-r--r-- | o3d/samples/o3d-webgl/pack.js | 2 | ||||
-rw-r--r-- | o3d/samples/o3d-webgl/param_operation.js | 48 |
4 files changed, 55 insertions, 41 deletions
diff --git a/o3d/samples/o3d-webgl/curve.js b/o3d/samples/o3d-webgl/curve.js index 68573092..d8ec585 100644 --- a/o3d/samples/o3d-webgl/curve.js +++ b/o3d/samples/o3d-webgl/curve.js @@ -429,7 +429,7 @@ o3d.Curve.prototype.__defineSetter__("sampleRate", function(rate) { "attempt to set sample rate to " + rate + " which is lower than the minimum of " + o3d.Curve.kMinimumSampleRate); } else if (rate != this.sample_rate_) { - this.sample_rate_ = new_sample_rate; + this.sample_rate_ = rate; this.invalidateCache_(); } }); @@ -526,7 +526,7 @@ o3d.Curve.prototype.addLinearKeys = function(values) { return; } for (var i = 0; i < values.length; i += kNumLinearKeyValues) { - var newKey = this.createKey("LinearKey"); + var newKey = this.createKey("LinearCurveKey"); newKey.input = values[i]; newKey.output = values[i+1]; } @@ -555,7 +555,7 @@ o3d.Curve.prototype.addStepKeys = function(values) { return; } for (var i = 0; i < values.length; i += kNumStepKeyValues) { - var newKey = this.createKey("StepKey"); + var newKey = this.createKey("StepCurveKey"); newKey.input = values[i]; newKey.output = values[i+1]; } @@ -585,7 +585,7 @@ o3d.Curve.prototype.addBezierKeys = function(values) { return; } for (var ii = 0; ii < values.length; ii += kNumBezierKeyValues) { - var newKey = this.createKey("BezierKey"); + var newKey = this.createKey("BezierCurveKey"); newKey.input = values[i]; newKey.output = values[i+1]; newKey.inTangent[0] = values[i+2]; @@ -725,7 +725,7 @@ o3d.Curve.prototype.getOutputInSpan_ = function(input, context) { // Find the current the keys that cover our input. while (start <= end) { - var mid = (start + end) / 2; + var mid = Math.floor((start + end)/2); if (input > keys[mid].input) { start = mid + 1; } else { diff --git a/o3d/samples/o3d-webgl/function.js b/o3d/samples/o3d-webgl/function.js index ea1f819..8bde542 100644 --- a/o3d/samples/o3d-webgl/function.js +++ b/o3d/samples/o3d-webgl/function.js @@ -66,21 +66,21 @@ o3d.FunctionEval = function() { * @private * @type {o3d.ParamFloat} */ - this.input_param_ = this.createParam("input", "ParamFloat"); + this.input_param_ = this.getParam("input"); /** * ParamFunction whose value is a o3d.Function or subclass. * @private * @type {o3d.ParamFunction} */ - this.func_param_ = this.createParam("functionObject", "ParamFunction"); + this.func_param_ = this.getParam("functionObject"); /** * Read-only output value. Value is cached if input does not change. * @private * @type {o3d.ParamFloatOutput} */ - this.output_param_ = this.createParam("output", "ParamFloatOutput"); + this.output_param_ = this.getParam("output"); /** * Context value to allow faster evaluation for adjacent input values. @@ -109,40 +109,22 @@ o3d.inherit('FunctionEval', 'ParamObject'); /** * Read-only output value. Value is cached if input does not change. - * @private - * @type {o3d.ParamFloatOutput} + * @type {number} */ -o3d.FunctionEval.prototype.__defineGetter__("output", - function() { - return this.output_param_.value; - }); +o3d.ParamObject.setUpO3DParam_(o3d.FunctionEval, "output", "ParamFloatOutput"); /** * Read/write input value to the function. - * @type {o3d.ParamFloat} + * @type {number} */ -o3d.FunctionEval.prototype.__defineGetter__("input", - function() { - return this.input_param_.value; - }); -o3d.FunctionEval.prototype.__defineSetter__("input", - function(newInput) { - this.input_param_.value = newInput; - }); +o3d.ParamObject.setUpO3DParam_(o3d.FunctionEval, "input", "ParamFloat"); /** * o3d.Function object (or subclass) with evaluate function. - * @private * @type {o3d.Function} */ -o3d.FunctionEval.prototype.__defineGetter__("functionObject", - function() { - return this.func_param_.value; - }); -o3d.FunctionEval.prototype.__defineSetter__("functionObject", - function(newFunc) { - this.func_param_.value = newFunc; - }); +o3d.ParamObject.setUpO3DParam_(o3d.FunctionEval, "functionObject", + "ParamFunction"); /** * Called by o3d.Param*Output whenever its value gets read. diff --git a/o3d/samples/o3d-webgl/pack.js b/o3d/samples/o3d-webgl/pack.js index a168820..f74d196 100644 --- a/o3d/samples/o3d-webgl/pack.js +++ b/o3d/samples/o3d-webgl/pack.js @@ -73,7 +73,7 @@ o3d.inherit('Pack', 'NamedObject'); */ o3d.Pack.prototype.destroy = function() { this.objects_ = []; - this.client.removePack(this); + this.client.destroyPack(this); }; diff --git a/o3d/samples/o3d-webgl/param_operation.js b/o3d/samples/o3d-webgl/param_operation.js index 2de2300..f847670 100644 --- a/o3d/samples/o3d-webgl/param_operation.js +++ b/o3d/samples/o3d-webgl/param_operation.js @@ -147,7 +147,7 @@ o3d.inherit('ParamOp2FloatsToFloat2', 'ParamObject'); /** * Called by o3d.Param*Output whenever its value gets read. - * @return {Array<number>} 2-element array equal to [input0,input1] + * @return {!Array<number>} 2-element array equal to [input0,input1] */ o3d.ParamOp2FloatsToFloat2.prototype.updateOutputs = function() { this.last_output_value_[0] = this.getParam("input0").value; @@ -177,7 +177,7 @@ o3d.inherit('ParamOp3FloatsToFloat3', 'ParamObject'); /** * Called by o3d.Param*Output whenever its value gets read. - * @return {Array<number>} 3-element array equal to [input0,input1,input2] + * @return {!Array<number>} 3-element array equal to [input0,input1,input2] */ o3d.ParamOp3FloatsToFloat3.prototype.updateOutputs = function() { this.last_output_value_[0] = this.getParam("input0").value; @@ -208,7 +208,7 @@ o3d.inherit('ParamOp4FloatsToFloat4', 'ParamObject'); /** * Called by o3d.Param*Output whenever its value gets read. - * @return {Array<number>} 4-element array equal to + * @return {!Array<number>} 4-element array equal to * [input0,input1,input2,input3] */ o3d.ParamOp4FloatsToFloat4.prototype.updateOutputs = function() { @@ -241,12 +241,13 @@ o3d.inherit('ParamOp16FloatsToMatrix4', 'ParamObject'); /** * Called by o3d.Param*Output whenever its value gets read. - * @return {Array<Array<number>>} 4x4 array equal to + * @return {!Array<!Array<number>>} 4x4 array equal to * [[i0,i1,i2,i3],[i4,i5,i6,i7],[i8,i9,i10,i11],[i12,i13,i14,i15]] */ o3d.ParamOp16FloatsToMatrix4.prototype.updateOutputs = function() { for (var i = 0; i < 16; i++) { - this.last_output_value_[i/4][i%4] = this.getParam("input"+i).value; + this.last_output_value_[Math.floor(i/4)][i%4] = + this.getParam("input"+i).value; } return this.last_output_value_; }; @@ -281,8 +282,6 @@ o3d.TRSToMatrix4 = function() { this.scaleZ = 1; this.last_output_value_ = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]; - - this.createParam("output", "ParamMatrix4Output"); }; o3d.inherit('TRSToMatrix4', 'ParamObject'); @@ -299,7 +298,7 @@ o3d.inherit('TRSToMatrix4', 'ParamObject'); /** * Called by o3d.Param*Output whenever its value gets read. - * @return {matrix4} 4x4 array equal to Translate * Rotate * Scale. + * @return {!Array<!Array<number>>} Matrix4 equal to Translate * Rotate * Scale. */ o3d.TRSToMatrix4.prototype.updateOutputs = function () { var ret = this.last_output_value_; @@ -336,3 +335,36 @@ o3d.TRSToMatrix4.prototype.updateOutputs = function () { 1); return ret; }; + +/** + * A Param operation that takes 16 floats to produce a 4-by-4 matrix. + * @constructor + * @extends {o3d.ParamObject} + */ +o3d.Matrix4Composition = function() { + o3d.ParamObject.call(this); + this.last_output_value_ = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]; +}; +o3d.inherit('Matrix4Composition', 'ParamObject'); + +o3d.ParamObject.setUpO3DParam_( + o3d.Matrix4Composition, "inputMatrix", "ParamMatrix4"); + +o3d.ParamObject.setUpO3DParam_( + o3d.Matrix4Composition, "localMatrix", "ParamMatrix4"); + +o3d.ParamObject.setUpO3DParam_( + o3d.Matrix4Composition, "outputMatrix", "ParamMatrix4Output"); + +/** + * Called by o3d.Param*Output whenever its value gets read. + * @return {!Array<!Array<number>>} 4x4 array equal to + * [[i0,i1,i2,i3],[i4,i5,i6,i7],[i8,i9,i10,i11],[i12,i13,i14,i15]] + */ +o3d.Matrix4Composition.prototype.updateOutputs = function() { + o3d.Transform.compose(this.inputMatrix, this.localMatrix, + this.last_output_value_); + return this.last_output_value_; +}; + + |