Skip to content

Commit

Permalink
add three.js for task 8
Browse files Browse the repository at this point in the history
  • Loading branch information
suiwei committed Apr 13, 2021
1 parent 929f394 commit c423ab6
Show file tree
Hide file tree
Showing 500 changed files with 1,390,062 additions and 0 deletions.
935 changes: 935 additions & 0 deletions examples/task8/three.js/BufferGeometryUtils.js

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions examples/task8/three.js/jsm/WebGL.js
@@ -0,0 +1,91 @@
var WEBGL = {

isWebGLAvailable: function () {

try {

var canvas = document.createElement( 'canvas' );
return !! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) );

} catch ( e ) {

return false;

}

},

isWebGL2Available: function () {

try {

var canvas = document.createElement( 'canvas' );
return !! ( window.WebGL2RenderingContext && canvas.getContext( 'webgl2' ) );

} catch ( e ) {

return false;

}

},

getWebGLErrorMessage: function () {

return this.getErrorMessage( 1 );

},

getWebGL2ErrorMessage: function () {

return this.getErrorMessage( 2 );

},

getErrorMessage: function ( version ) {

var names = {
1: 'WebGL',
2: 'WebGL 2'
};

var contexts = {
1: window.WebGLRenderingContext,
2: window.WebGL2RenderingContext
};

var message = 'Your $0 does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">$1</a>';

var element = document.createElement( 'div' );
element.id = 'webglmessage';
element.style.fontFamily = 'monospace';
element.style.fontSize = '13px';
element.style.fontWeight = 'normal';
element.style.textAlign = 'center';
element.style.background = '#fff';
element.style.color = '#000';
element.style.padding = '1.5em';
element.style.width = '400px';
element.style.margin = '5em auto 0';

if ( contexts[ version ] ) {

message = message.replace( '$0', 'graphics card' );

} else {

message = message.replace( '$0', 'browser' );

}

message = message.replace( '$1', names[ version ] );

element.innerHTML = message;

return element;

}

};

export { WEBGL };
117 changes: 117 additions & 0 deletions examples/task8/three.js/jsm/animation/AnimationClipCreator.js
@@ -0,0 +1,117 @@
import {
AnimationClip,
BooleanKeyframeTrack,
ColorKeyframeTrack,
NumberKeyframeTrack,
Vector3,
VectorKeyframeTrack
} from '../../../build/three.module.js';

var AnimationClipCreator = function () {};

AnimationClipCreator.CreateRotationAnimation = function ( period, axis ) {

var times = [ 0, period ], values = [ 0, 360 ];

axis = axis || 'x';
var trackName = '.rotation[' + axis + ']';

var track = new NumberKeyframeTrack( trackName, times, values );

return new AnimationClip( null, period, [ track ] );

};

AnimationClipCreator.CreateScaleAxisAnimation = function ( period, axis ) {

var times = [ 0, period ], values = [ 0, 1 ];

axis = axis || 'x';
var trackName = '.scale[' + axis + ']';

var track = new NumberKeyframeTrack( trackName, times, values );

return new AnimationClip( null, period, [ track ] );

};

AnimationClipCreator.CreateShakeAnimation = function ( duration, shakeScale ) {

var times = [], values = [], tmp = new Vector3();

for ( var i = 0; i < duration * 10; i ++ ) {

times.push( i / 10 );

tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).
multiply( shakeScale ).
toArray( values, values.length );

}

var trackName = '.position';

var track = new VectorKeyframeTrack( trackName, times, values );

return new AnimationClip( null, duration, [ track ] );

};


AnimationClipCreator.CreatePulsationAnimation = function ( duration, pulseScale ) {

var times = [], values = [], tmp = new Vector3();

for ( var i = 0; i < duration * 10; i ++ ) {

times.push( i / 10 );

var scaleFactor = Math.random() * pulseScale;
tmp.set( scaleFactor, scaleFactor, scaleFactor ).
toArray( values, values.length );

}

var trackName = '.scale';

var track = new VectorKeyframeTrack( trackName, times, values );

return new AnimationClip( null, duration, [ track ] );

};


AnimationClipCreator.CreateVisibilityAnimation = function ( duration ) {

var times = [ 0, duration / 2, duration ], values = [ true, false, true ];

var trackName = '.visible';

var track = new BooleanKeyframeTrack( trackName, times, values );

return new AnimationClip( null, duration, [ track ] );

};


AnimationClipCreator.CreateMaterialColorAnimation = function ( duration, colors ) {

var times = [], values = [],
timeStep = duration / colors.length;

for ( var i = 0; i <= colors.length; i ++ ) {

times.push( i * timeStep );
values.push( colors[ i % colors.length ] );

}

var trackName = '.material[0].color';

var track = new ColorKeyframeTrack( trackName, times, values );

return new AnimationClip( null, duration, [ track ] );

};

export { AnimationClipCreator };

0 comments on commit c423ab6

Please sign in to comment.