提交 5be57033 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #12262 from WestLangley/dev-cloth

Animation cloth example: clean up
...@@ -44,40 +44,6 @@ ...@@ -44,40 +44,6 @@
<script src="js/Cloth.js"></script> <script src="js/Cloth.js"></script>
<script type="x-shader/x-fragment" id="fragmentShaderDepth">
#include <packing>
uniform sampler2D texture;
varying vec2 vUV;
void main() {
vec4 pixel = texture2D( texture, vUV );
if ( pixel.a < 0.5 ) discard;
gl_FragData[ 0 ] = packDepthToRGBA( gl_FragCoord.z );
}
</script>
<script type="x-shader/x-vertex" id="vertexShaderDepth">
varying vec2 vUV;
void main() {
vUV = 0.75 * uv;
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * mvPosition;
}
</script>
<script> <script>
/* testing cloth simulation */ /* testing cloth simulation */
...@@ -134,10 +100,7 @@ ...@@ -134,10 +100,7 @@
// camera // camera
camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 1, 10000 ); camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.x = 1000; camera.position.set( 1000, 50, 1500 );
camera.position.y = 50;
camera.position.z = 1500;
scene.add( camera );
// lights // lights
...@@ -145,7 +108,7 @@ ...@@ -145,7 +108,7 @@
scene.add( new THREE.AmbientLight( 0x666666 ) ); scene.add( new THREE.AmbientLight( 0x666666 ) );
light = new THREE.DirectionalLight( 0xdfebff, 1.75 ); light = new THREE.DirectionalLight( 0xdfebff, 1 );
light.position.set( 50, 200, 100 ); light.position.set( 50, 200, 100 );
light.position.multiplyScalar( 1.3 ); light.position.multiplyScalar( 1.3 );
...@@ -170,6 +133,8 @@ ...@@ -170,6 +133,8 @@
var loader = new THREE.TextureLoader(); var loader = new THREE.TextureLoader();
var clothTexture = loader.load( 'textures/patterns/circuit_pattern.png' ); var clothTexture = loader.load( 'textures/patterns/circuit_pattern.png' );
clothTexture.wrapS = clothTexture.wrapT = THREE.RepeatWrapping; clothTexture.wrapS = clothTexture.wrapT = THREE.RepeatWrapping;
clothTexture.offset.set( 0.1, 0.1 );
clothTexture.repeat.set( 0.5, 0.5 );
clothTexture.anisotropy = 16; clothTexture.anisotropy = 16;
var clothMaterial = new THREE.MeshPhongMaterial( { var clothMaterial = new THREE.MeshPhongMaterial( {
...@@ -180,12 +145,8 @@ ...@@ -180,12 +145,8 @@
} ); } );
// cloth geometry // cloth geometry
clothGeometry = new THREE.ParametricGeometry( clothFunction, cloth.w, cloth.h );
clothGeometry.dynamic = true;
var uniforms = { texture: { value: clothTexture } }; clothGeometry = new THREE.ParametricGeometry( clothFunction, cloth.w, cloth.h );
var vertexShader = document.getElementById( 'vertexShaderDepth' ).textContent;
var fragmentShader = document.getElementById( 'fragmentShaderDepth' ).textContent;
// cloth mesh // cloth mesh
...@@ -194,16 +155,17 @@ ...@@ -194,16 +155,17 @@
object.castShadow = true; object.castShadow = true;
scene.add( object ); scene.add( object );
object.customDepthMaterial = new THREE.ShaderMaterial( { object.customDepthMaterial = new THREE.MeshDepthMaterial( {
uniforms: uniforms,
vertexShader: vertexShader, depthPacking: THREE.RGBADepthPacking,
fragmentShader: fragmentShader, map: clothTexture,
side: THREE.DoubleSide alphaTest: 0.5
} ); } );
// sphere // sphere
var ballGeo = new THREE.SphereGeometry( ballSize, 20, 20 ); var ballGeo = new THREE.SphereBufferGeometry( ballSize, 32, 16 );
var ballMaterial = new THREE.MeshPhongMaterial( { color: 0xaaaaaa } ); var ballMaterial = new THREE.MeshPhongMaterial( { color: 0xaaaaaa } );
sphere = new THREE.Mesh( ballGeo, ballMaterial ); sphere = new THREE.Mesh( ballGeo, ballMaterial );
...@@ -228,7 +190,7 @@ ...@@ -228,7 +190,7 @@
// poles // poles
var poleGeo = new THREE.BoxGeometry( 5, 375, 5 ); var poleGeo = new THREE.BoxBufferGeometry( 5, 375, 5 );
var poleMat = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, shininess: 100 } ); var poleMat = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, shininess: 100 } );
var mesh = new THREE.Mesh( poleGeo, poleMat ); var mesh = new THREE.Mesh( poleGeo, poleMat );
...@@ -245,14 +207,14 @@ ...@@ -245,14 +207,14 @@
mesh.castShadow = true; mesh.castShadow = true;
scene.add( mesh ); scene.add( mesh );
var mesh = new THREE.Mesh( new THREE.BoxGeometry( 255, 5, 5 ), poleMat ); var mesh = new THREE.Mesh( new THREE.BoxBufferGeometry( 255, 5, 5 ), poleMat );
mesh.position.y = - 250 + ( 750 / 2 ); mesh.position.y = - 250 + ( 750 / 2 );
mesh.position.x = 0; mesh.position.x = 0;
mesh.receiveShadow = true; mesh.receiveShadow = true;
mesh.castShadow = true; mesh.castShadow = true;
scene.add( mesh ); scene.add( mesh );
var gg = new THREE.BoxGeometry( 10, 10, 10 ); var gg = new THREE.BoxBufferGeometry( 10, 10, 10 );
var mesh = new THREE.Mesh( gg, poleMat ); var mesh = new THREE.Mesh( gg, poleMat );
mesh.position.y = - 250; mesh.position.y = - 250;
mesh.position.x = 125; mesh.position.x = 125;
...@@ -285,7 +247,7 @@ ...@@ -285,7 +247,7 @@
var controls = new THREE.OrbitControls( camera, renderer.domElement ); var controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.maxPolarAngle = Math.PI * 0.5; controls.maxPolarAngle = Math.PI * 0.5;
controls.minDistance = 1000; controls.minDistance = 1000;
controls.maxDistance = 7500; controls.maxDistance = 5000;
// performance monitor // performance monitor
...@@ -341,16 +303,13 @@ ...@@ -341,16 +303,13 @@
} }
clothGeometry.verticesNeedUpdate = true;
clothGeometry.computeFaceNormals(); clothGeometry.computeFaceNormals();
clothGeometry.computeVertexNormals(); clothGeometry.computeVertexNormals();
clothGeometry.normalsNeedUpdate = true;
clothGeometry.verticesNeedUpdate = true;
sphere.position.copy( ballPosition ); sphere.position.copy( ballPosition );
camera.lookAt( scene.position );
renderer.render( scene, camera ); renderer.render( scene, camera );
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册