Skip to content

Commit f99b57d

Browse files
committed
代码提交
1 parent 69f31f5 commit f99b57d

File tree

324 files changed

+113273
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

324 files changed

+113273
-0
lines changed

njs/animation/CCDIKSolver.js

Lines changed: 455 additions & 0 deletions
Large diffs are not rendered by default.

njs/animation/MMDAnimationHelper.js

Lines changed: 1041 additions & 0 deletions
Large diffs are not rendered by default.

njs/animation/MMDPhysics.js

Lines changed: 1406 additions & 0 deletions
Large diffs are not rendered by default.

njs/cameras/CinematicCamera.js

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/**
2+
* @author mrdoob / http://mrdoob.com/
3+
* @author greggman / http://games.greggman.com/
4+
* @author zz85 / http://www.lab4games.net/zz85/blog
5+
* @author kaypiKun
6+
*/
7+
8+
THREE.CinematicCamera = function ( fov, aspect, near, far ) {
9+
10+
THREE.PerspectiveCamera.call( this, fov, aspect, near, far );
11+
12+
this.type = 'CinematicCamera';
13+
14+
this.postprocessing = { enabled: true };
15+
this.shaderSettings = {
16+
rings: 3,
17+
samples: 4
18+
};
19+
20+
var depthShader = THREE.BokehDepthShader;
21+
22+
this.materialDepth = new THREE.ShaderMaterial( {
23+
uniforms: depthShader.uniforms,
24+
vertexShader: depthShader.vertexShader,
25+
fragmentShader: depthShader.fragmentShader
26+
} );
27+
28+
this.materialDepth.uniforms[ 'mNear' ].value = near;
29+
this.materialDepth.uniforms[ 'mFar' ].value = far;
30+
31+
// In case of cinematicCamera, having a default lens set is important
32+
this.setLens();
33+
34+
this.initPostProcessing();
35+
36+
};
37+
38+
THREE.CinematicCamera.prototype = Object.create( THREE.PerspectiveCamera.prototype );
39+
THREE.CinematicCamera.prototype.constructor = THREE.CinematicCamera;
40+
41+
42+
// providing fnumber and coc(Circle of Confusion) as extra arguments
43+
THREE.CinematicCamera.prototype.setLens = function ( focalLength, filmGauge, fNumber, coc ) {
44+
45+
// In case of cinematicCamera, having a default lens set is important
46+
if ( focalLength === undefined ) focalLength = 35;
47+
if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
48+
49+
this.setFocalLength( focalLength );
50+
51+
// if fnumber and coc are not provided, cinematicCamera tries to act as a basic PerspectiveCamera
52+
if ( fNumber === undefined ) fNumber = 8;
53+
if ( coc === undefined ) coc = 0.019;
54+
55+
this.fNumber = fNumber;
56+
this.coc = coc;
57+
58+
// fNumber is focalLength by aperture
59+
this.aperture = focalLength / this.fNumber;
60+
61+
// hyperFocal is required to calculate depthOfField when a lens tries to focus at a distance with given fNumber and focalLength
62+
this.hyperFocal = ( focalLength * focalLength ) / ( this.aperture * this.coc );
63+
64+
};
65+
66+
THREE.CinematicCamera.prototype.linearize = function ( depth ) {
67+
68+
var zfar = this.far;
69+
var znear = this.near;
70+
return - zfar * znear / ( depth * ( zfar - znear ) - zfar );
71+
72+
};
73+
74+
THREE.CinematicCamera.prototype.smoothstep = function ( near, far, depth ) {
75+
76+
var x = this.saturate( ( depth - near ) / ( far - near ) );
77+
return x * x * ( 3 - 2 * x );
78+
79+
};
80+
81+
THREE.CinematicCamera.prototype.saturate = function ( x ) {
82+
83+
return Math.max( 0, Math.min( 1, x ) );
84+
85+
};
86+
87+
// function for focusing at a distance from the camera
88+
THREE.CinematicCamera.prototype.focusAt = function ( focusDistance ) {
89+
90+
if ( focusDistance === undefined ) focusDistance = 20;
91+
92+
var focalLength = this.getFocalLength();
93+
94+
// distance from the camera (normal to frustrum) to focus on
95+
this.focus = focusDistance;
96+
97+
// the nearest point from the camera which is in focus (unused)
98+
this.nearPoint = ( this.hyperFocal * this.focus ) / ( this.hyperFocal + ( this.focus - focalLength ) );
99+
100+
// the farthest point from the camera which is in focus (unused)
101+
this.farPoint = ( this.hyperFocal * this.focus ) / ( this.hyperFocal - ( this.focus - focalLength ) );
102+
103+
// the gap or width of the space in which is everything is in focus (unused)
104+
this.depthOfField = this.farPoint - this.nearPoint;
105+
106+
// Considering minimum distance of focus for a standard lens (unused)
107+
if ( this.depthOfField < 0 ) this.depthOfField = 0;
108+
109+
this.sdistance = this.smoothstep( this.near, this.far, this.focus );
110+
111+
this.ldistance = this.linearize( 1 - this.sdistance );
112+
113+
this.postprocessing.bokeh_uniforms[ 'focalDepth' ].value = this.ldistance;
114+
115+
};
116+
117+
THREE.CinematicCamera.prototype.initPostProcessing = function () {
118+
119+
if ( this.postprocessing.enabled ) {
120+
121+
this.postprocessing.scene = new THREE.Scene();
122+
123+
this.postprocessing.camera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, - 10000, 10000 );
124+
125+
this.postprocessing.scene.add( this.postprocessing.camera );
126+
127+
var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat };
128+
this.postprocessing.rtTextureDepth = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, pars );
129+
this.postprocessing.rtTextureColor = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, pars );
130+
131+
var bokeh_shader = THREE.BokehShader;
132+
133+
this.postprocessing.bokeh_uniforms = THREE.UniformsUtils.clone( bokeh_shader.uniforms );
134+
135+
this.postprocessing.bokeh_uniforms[ "tColor" ].value = this.postprocessing.rtTextureColor.texture;
136+
this.postprocessing.bokeh_uniforms[ "tDepth" ].value = this.postprocessing.rtTextureDepth.texture;
137+
138+
this.postprocessing.bokeh_uniforms[ "manualdof" ].value = 0;
139+
this.postprocessing.bokeh_uniforms[ "shaderFocus" ].value = 0;
140+
141+
this.postprocessing.bokeh_uniforms[ "fstop" ].value = 2.8;
142+
143+
this.postprocessing.bokeh_uniforms[ "showFocus" ].value = 1;
144+
145+
this.postprocessing.bokeh_uniforms[ "focalDepth" ].value = 0.1;
146+
147+
//console.log( this.postprocessing.bokeh_uniforms[ "focalDepth" ].value );
148+
149+
this.postprocessing.bokeh_uniforms[ "znear" ].value = this.near;
150+
this.postprocessing.bokeh_uniforms[ "zfar" ].value = this.near;
151+
152+
153+
this.postprocessing.bokeh_uniforms[ "textureWidth" ].value = window.innerWidth;
154+
155+
this.postprocessing.bokeh_uniforms[ "textureHeight" ].value = window.innerHeight;
156+
157+
this.postprocessing.materialBokeh = new THREE.ShaderMaterial( {
158+
uniforms: this.postprocessing.bokeh_uniforms,
159+
vertexShader: bokeh_shader.vertexShader,
160+
fragmentShader: bokeh_shader.fragmentShader,
161+
defines: {
162+
RINGS: this.shaderSettings.rings,
163+
SAMPLES: this.shaderSettings.samples,
164+
DEPTH_PACKING: 1
165+
}
166+
} );
167+
168+
this.postprocessing.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( window.innerWidth, window.innerHeight ), this.postprocessing.materialBokeh );
169+
this.postprocessing.quad.position.z = - 500;
170+
this.postprocessing.scene.add( this.postprocessing.quad );
171+
172+
}
173+
174+
};
175+
176+
THREE.CinematicCamera.prototype.renderCinematic = function ( scene, renderer ) {
177+
178+
if ( this.postprocessing.enabled ) {
179+
180+
var currentRenderTarget = renderer.getRenderTarget();
181+
182+
renderer.clear();
183+
184+
// Render scene into texture
185+
186+
scene.overrideMaterial = null;
187+
renderer.setRenderTarget( this.postprocessing.rtTextureColor );
188+
renderer.clear();
189+
renderer.render( scene, camera );
190+
191+
// Render depth into texture
192+
193+
scene.overrideMaterial = this.materialDepth;
194+
renderer.setRenderTarget( this.postprocessing.rtTextureDepth );
195+
renderer.clear();
196+
renderer.render( scene, camera );
197+
198+
// Render bokeh composite
199+
200+
renderer.setRenderTarget( null );
201+
renderer.render( this.postprocessing.scene, this.postprocessing.camera );
202+
203+
renderer.setRenderTarget( currentRenderTarget );
204+
205+
}
206+
207+
};
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @author richt / http://richt.me
3+
* @author WestLangley / http://github.com/WestLangley
4+
*
5+
* W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
6+
*/
7+
8+
THREE.DeviceOrientationControls = function ( object ) {
9+
10+
var scope = this;
11+
12+
this.object = object;
13+
this.object.rotation.reorder( 'YXZ' );
14+
15+
this.enabled = true;
16+
17+
this.deviceOrientation = {};
18+
this.screenOrientation = 0;
19+
20+
this.alphaOffset = 0; // radians
21+
22+
var onDeviceOrientationChangeEvent = function ( event ) {
23+
24+
scope.deviceOrientation = event;
25+
26+
};
27+
28+
var onScreenOrientationChangeEvent = function () {
29+
30+
scope.screenOrientation = window.orientation || 0;
31+
32+
};
33+
34+
// The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''
35+
36+
var setObjectQuaternion = function () {
37+
38+
var zee = new THREE.Vector3( 0, 0, 1 );
39+
40+
var euler = new THREE.Euler();
41+
42+
var q0 = new THREE.Quaternion();
43+
44+
var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis
45+
46+
return function ( quaternion, alpha, beta, gamma, orient ) {
47+
48+
euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us
49+
50+
quaternion.setFromEuler( euler ); // orient the device
51+
52+
quaternion.multiply( q1 ); // camera looks out the back of the device, not the top
53+
54+
quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation
55+
56+
};
57+
58+
}();
59+
60+
this.connect = function () {
61+
62+
onScreenOrientationChangeEvent(); // run once on load
63+
64+
window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );
65+
window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );
66+
67+
scope.enabled = true;
68+
69+
};
70+
71+
this.disconnect = function () {
72+
73+
window.removeEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );
74+
window.removeEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );
75+
76+
scope.enabled = false;
77+
78+
};
79+
80+
this.update = function () {
81+
82+
if ( scope.enabled === false ) return;
83+
84+
var device = scope.deviceOrientation;
85+
86+
if ( device ) {
87+
88+
var alpha = device.alpha ? THREE.Math.degToRad( device.alpha ) + scope.alphaOffset : 0; // Z
89+
90+
var beta = device.beta ? THREE.Math.degToRad( device.beta ) : 0; // X'
91+
92+
var gamma = device.gamma ? THREE.Math.degToRad( device.gamma ) : 0; // Y''
93+
94+
var orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O
95+
96+
setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient );
97+
98+
}
99+
100+
101+
};
102+
103+
this.dispose = function () {
104+
105+
scope.disconnect();
106+
107+
};
108+
109+
this.connect();
110+
111+
};

0 commit comments

Comments
 (0)