Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: samples/o3d-webgl/curve.js

Issue 3020030: Fixes errors when loading animated meshes in simpleviewer.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | samples/o3d-webgl/function.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010, Google Inc. 2 * Copyright 2010, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 return this.sample_rate_; 422 return this.sample_rate_;
423 }); 423 });
424 424
425 o3d.Curve.prototype.__defineSetter__("sampleRate", function(rate) { 425 o3d.Curve.prototype.__defineSetter__("sampleRate", function(rate) {
426 if (rate < o3d.Curve.kMinimumSampleRate) { 426 if (rate < o3d.Curve.kMinimumSampleRate) {
427 rate = o3d.Curve.kMinimumSampleRate; 427 rate = o3d.Curve.kMinimumSampleRate;
428 this.gl.client.error_callback( 428 this.gl.client.error_callback(
429 "attempt to set sample rate to " + rate + 429 "attempt to set sample rate to " + rate +
430 " which is lower than the minimum of " + o3d.Curve.kMinimumSampleRate); 430 " which is lower than the minimum of " + o3d.Curve.kMinimumSampleRate);
431 } else if (rate != this.sample_rate_) { 431 } else if (rate != this.sample_rate_) {
432 this.sample_rate_ = new_sample_rate; 432 this.sample_rate_ = rate;
433 this.invalidateCache_(); 433 this.invalidateCache_();
434 } 434 }
435 }); 435 });
436 436
437 /** 437 /**
438 * @type {number} 438 * @type {number}
439 */ 439 */
440 o3d.Curve.Infinity = goog.typedef; 440 o3d.Curve.Infinity = goog.typedef;
441 441
442 /** 442 /**
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 * Length must be a multiple of 2 519 * Length must be a multiple of 2
520 */ 520 */
521 o3d.Curve.prototype.addLinearKeys = function(values) { 521 o3d.Curve.prototype.addLinearKeys = function(values) {
522 var kNumLinearKeyValues = 2; 522 var kNumLinearKeyValues = 2;
523 if (values.length % kNumLinearKeyValues != 0) { 523 if (values.length % kNumLinearKeyValues != 0) {
524 this.gl.client.error_callback( 524 this.gl.client.error_callback(
525 "addLinearKeys: expected multiple of 2 values got "+values.size()); 525 "addLinearKeys: expected multiple of 2 values got "+values.size());
526 return; 526 return;
527 } 527 }
528 for (var i = 0; i < values.length; i += kNumLinearKeyValues) { 528 for (var i = 0; i < values.length; i += kNumLinearKeyValues) {
529 var newKey = this.createKey("LinearKey"); 529 var newKey = this.createKey("LinearCurveKey");
530 newKey.input = values[i]; 530 newKey.input = values[i];
531 newKey.output = values[i+1]; 531 newKey.output = values[i+1];
532 } 532 }
533 this.sorted_ = false; 533 this.sorted_ = false;
534 }; 534 };
535 535
536 /** 536 /**
537 * Adds 1 or more StepKeys to this Curve. 537 * Adds 1 or more StepKeys to this Curve.
538 * 538 *
539 * Example: 539 * Example:
540 * <pre> 540 * <pre>
541 * // Creates 2 keys. 541 * // Creates 2 keys.
542 * // 1 key at 0 with an output of 10 542 * // 1 key at 0 with an output of 10
543 * // 1 key at 20 with an output of 30 543 * // 1 key at 20 with an output of 30
544 * curve.addStepKeys([0,10,20,30]); 544 * curve.addStepKeys([0,10,20,30]);
545 * </pre>. 545 * </pre>.
546 * 546 *
547 * @param {!Array.<number>} values Array of input, output pairs. 547 * @param {!Array.<number>} values Array of input, output pairs.
548 * Length must be a multiple of 2 548 * Length must be a multiple of 2
549 */ 549 */
550 o3d.Curve.prototype.addStepKeys = function(values) { 550 o3d.Curve.prototype.addStepKeys = function(values) {
551 var kNumStepKeyValues = 2; 551 var kNumStepKeyValues = 2;
552 if (values.length % kNumStepKeyValues != 0) { 552 if (values.length % kNumStepKeyValues != 0) {
553 this.gl.client.error_callback( 553 this.gl.client.error_callback(
554 "addStepKeys: expected multiple of 2 values got "+values.size()); 554 "addStepKeys: expected multiple of 2 values got "+values.size());
555 return; 555 return;
556 } 556 }
557 for (var i = 0; i < values.length; i += kNumStepKeyValues) { 557 for (var i = 0; i < values.length; i += kNumStepKeyValues) {
558 var newKey = this.createKey("StepKey"); 558 var newKey = this.createKey("StepCurveKey");
559 newKey.input = values[i]; 559 newKey.input = values[i];
560 newKey.output = values[i+1]; 560 newKey.output = values[i+1];
561 } 561 }
562 this.sorted_ = false; 562 this.sorted_ = false;
563 }; 563 };
564 564
565 /** 565 /**
566 * Adds 1 or more BezierKeys to this Curve. 566 * Adds 1 or more BezierKeys to this Curve.
567 * 567 *
568 * Example: 568 * Example:
569 * <pre> 569 * <pre>
570 * // Creates 2 keys. 570 * // Creates 2 keys.
571 * // 1 key at 0 with an output of 10, in tangent of 1,9, out tangent 9,0.5 571 * // 1 key at 0 with an output of 10, in tangent of 1,9, out tangent 9,0.5
572 * // 1 key at 20 with an output of 30, in tangent of 30, 3, out tangent 4, 28 572 * // 1 key at 20 with an output of 30, in tangent of 30, 3, out tangent 4, 28
573 * curve.addBezierKeys([0,10,1,9,9,0.5,2,30,3,4,28]); 573 * curve.addBezierKeys([0,10,1,9,9,0.5,2,30,3,4,28]);
574 * </pre>. 574 * </pre>.
575 * 575 *
576 * @param {!Array.<number>} values Array of tuples of the form (input, output, 576 * @param {!Array.<number>} values Array of tuples of the form (input, output,
577 * inTangent[0], inTangent[1], outTangent[0], outTangent[1]). 577 * inTangent[0], inTangent[1], outTangent[0], outTangent[1]).
578 * Length must be a multiple of 6. 578 * Length must be a multiple of 6.
579 */ 579 */
580 o3d.Curve.prototype.addBezierKeys = function(values) { 580 o3d.Curve.prototype.addBezierKeys = function(values) {
581 var kNumBezierKeyValues = 6; 581 var kNumBezierKeyValues = 6;
582 if (values.length % kNumBezierKeyValues != 0) { 582 if (values.length % kNumBezierKeyValues != 0) {
583 this.gl.client.error_callback( 583 this.gl.client.error_callback(
584 "addBezierKeys: expected multiple of 6 values got "+values.size()); 584 "addBezierKeys: expected multiple of 6 values got "+values.size());
585 return; 585 return;
586 } 586 }
587 for (var ii = 0; ii < values.length; ii += kNumBezierKeyValues) { 587 for (var ii = 0; ii < values.length; ii += kNumBezierKeyValues) {
588 var newKey = this.createKey("BezierKey"); 588 var newKey = this.createKey("BezierCurveKey");
589 newKey.input = values[i]; 589 newKey.input = values[i];
590 newKey.output = values[i+1]; 590 newKey.output = values[i+1];
591 newKey.inTangent[0] = values[i+2]; 591 newKey.inTangent[0] = values[i+2];
592 newKey.inTangent[1] = values[i+3]; 592 newKey.inTangent[1] = values[i+3];
593 newKey.outTangent[0] = values[i+4]; 593 newKey.outTangent[0] = values[i+4];
594 newKey.outTangent[1] = values[i+5]; 594 newKey.outTangent[1] = values[i+5];
595 } 595 }
596 this.sorted_ = false; 596 this.sorted_ = false;
597 }; 597 };
598 598
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 } 718 }
719 } 719 }
720 } 720 }
721 721
722 if (!found) { 722 if (!found) {
723 // TODO: If we assume the most common case is sampled keys and 723 // TODO: If we assume the most common case is sampled keys and
724 // constant intervals we can make a quick guess where that key is. 724 // constant intervals we can make a quick guess where that key is.
725 725
726 // Find the current the keys that cover our input. 726 // Find the current the keys that cover our input.
727 while (start <= end) { 727 while (start <= end) {
728 var mid = (start + end) / 2; 728 var mid = Math.floor((start + end)/2);
729 if (input > keys[mid].input) { 729 if (input > keys[mid].input) {
730 start = mid + 1; 730 start = mid + 1;
731 } else { 731 } else {
732 if (mid == 0) { 732 if (mid == 0) {
733 break; 733 break;
734 } 734 }
735 end = mid - 1; 735 end = mid - 1;
736 } 736 }
737 } 737 }
738 738
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 // interpolate end_input to anything past it. 893 // interpolate end_input to anything past it.
894 if (input >= end_input) { 894 if (input >= end_input) {
895 return end_output + output_offset; 895 return end_output + output_offset;
896 } 896 }
897 897
898 // TODO(pathorn): Implement curve cache in javascript. 898 // TODO(pathorn): Implement curve cache in javascript.
899 // See 'void Curve::CreateCache' in o3d/core/cross/curve.cc 899 // See 'void Curve::CreateCache' in o3d/core/cross/curve.cc
900 900
901 return this.getOutputInSpan_(input, context) + output_offset; 901 return this.getOutputInSpan_(input, context) + output_offset;
902 }; 902 };
OLDNEW
« no previous file with comments | « no previous file | samples/o3d-webgl/function.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698