未验证 提交 4b217f81 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #15164 from Mugen87/dev17

Examples: Clean up
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
<div> <div>
[example:webgl_sprites WebGL / sprites]<br /> [example:webgl_sprites WebGL / sprites]<br />
[example:misc_ubiquity_test misc / ubiquity / test]<br /> [example:misc_ubiquity_test misc / ubiquity / test]<br />
[example:misc_ubiquity_test2 misc / ubiquity / test2]<br />
[example:software_sandbox software / sandbox]<br /> [example:software_sandbox software / sandbox]<br />
[example:svg_sandbox svg / sandbox]<br /> [example:svg_sandbox svg / sandbox]<br />
[example:webgl_materials_cubemap_dynamic webgl / materials / cubemap / dynamic] [example:webgl_materials_cubemap_dynamic webgl / materials / cubemap / dynamic]
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
<div> <div>
[example:webgl_sprites WebGL / sprites]<br /> [example:webgl_sprites WebGL / sprites]<br />
[example:misc_ubiquity_test misc / ubiquity / test]<br /> [example:misc_ubiquity_test misc / ubiquity / test]<br />
[example:misc_ubiquity_test2 misc / ubiquity / test2]<br />
[example:software_sandbox software / sandbox]<br /> [example:software_sandbox software / sandbox]<br />
[example:svg_sandbox svg / sandbox]<br /> [example:svg_sandbox svg / sandbox]<br />
[example:webgl_materials_cubemap_dynamic webgl / materials / cubemap / dynamic] [example:webgl_materials_cubemap_dynamic webgl / materials / cubemap / dynamic]
......
...@@ -189,7 +189,6 @@ var files = { ...@@ -189,7 +189,6 @@ var files = {
"webgl_modifier_tessellation", "webgl_modifier_tessellation",
"webgl_morphtargets", "webgl_morphtargets",
"webgl_morphtargets_horse", "webgl_morphtargets_horse",
"webgl_morphtargets_human",
"webgl_morphtargets_sphere", "webgl_morphtargets_sphere",
"webgl_multiple_canvases_circle", "webgl_multiple_canvases_circle",
"webgl_multiple_canvases_complex", "webgl_multiple_canvases_complex",
...@@ -356,7 +355,7 @@ var files = { ...@@ -356,7 +355,7 @@ var files = {
"misc_fps", "misc_fps",
"misc_lights_test", "misc_lights_test",
"misc_lookat", "misc_lookat",
"misc_ubiquity_test2", "misc_ubiquity_test",
"misc_uv_tests" "misc_uv_tests"
], ],
"css3d": [ "css3d": [
......
THREE.UCSCharacter = function () {
var scope = this;
var mesh;
this.scale = 1;
this.root = new THREE.Object3D();
this.numSkins = undefined;
this.numMorphs = undefined;
this.skins = [];
this.materials = [];
this.morphs = [];
this.mixer = new THREE.AnimationMixer( this.root );
this.onLoadComplete = function () {};
this.loadCounter = 0;
this.loadParts = function ( config ) {
this.numSkins = config.skins.length;
this.numMorphs = config.morphs.length;
// Character geometry + number of skins
this.loadCounter = 1 + config.skins.length;
// SKINS
this.skins = loadTextures( config.baseUrl + "skins/", config.skins );
this.materials = createMaterials( this.skins );
// MORPHS
this.morphs = config.morphs;
// CHARACTER
var loader = new THREE.JSONLoader();
console.log( config.baseUrl + config.character );
loader.load( config.baseUrl + config.character, function ( geometry ) {
geometry.computeBoundingBox();
geometry.computeVertexNormals();
mesh = new THREE.SkinnedMesh( geometry, [] );
mesh.name = config.character;
scope.root.add( mesh );
var bb = geometry.boundingBox;
scope.root.scale.set( config.s, config.s, config.s );
scope.root.position.set( config.x, config.y - bb.min.y * config.s, config.z );
mesh.castShadow = true;
mesh.receiveShadow = true;
scope.mixer.clipAction( geometry.animations[ 0 ], mesh ).play();
scope.setSkin( 0 );
scope.checkLoadComplete();
} );
};
this.setSkin = function ( index ) {
if ( mesh && scope.materials ) {
mesh.material = scope.materials[ index ];
}
};
this.updateMorphs = function ( influences ) {
if ( mesh ) {
for ( var i = 0; i < scope.numMorphs; i ++ ) {
mesh.morphTargetInfluences[ i ] = influences[ scope.morphs[ i ] ] / 100;
}
}
};
function loadTextures( baseUrl, textureUrls ) {
var textureLoader = new THREE.TextureLoader();
var textures = [];
for ( var i = 0; i < textureUrls.length; i ++ ) {
textures[ i ] = textureLoader.load( baseUrl + textureUrls[ i ], scope.checkLoadComplete );
textures[ i ].mapping = THREE.UVMapping;
textures[ i ].name = textureUrls[ i ];
}
return textures;
}
function createMaterials( skins ) {
var materials = [];
for ( var i = 0; i < skins.length; i ++ ) {
materials[ i ] = new THREE.MeshLambertMaterial( {
color: 0xeeeeee,
specular: 10.0,
map: skins[ i ],
skinning: true,
morphTargets: true
} );
}
return materials;
}
this.checkLoadComplete = function () {
scope.loadCounter -= 1;
if ( scope.loadCounter === 0 ) {
scope.onLoadComplete();
}
};
};
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>three.js misc - ubiquity - test2</title> <title>three.js misc - ubiquity - test</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style> <style>
...@@ -15,9 +15,6 @@ ...@@ -15,9 +15,6 @@
<body> <body>
<script src="../build/three.js"></script> <script src="../build/three.js"></script>
<script src="js/renderers/Projector.js"></script>
<script src="js/libs/stats.min.js"></script> <script src="js/libs/stats.min.js"></script>
<div id='container1' style='float: left '></div> <div id='container1' style='float: left '></div>
......
此差异已折叠。
{
"baseUrl": "models/skinned/UCS/",
"character": "umich_ucs.js",
"skins": ["Asian_Male.jpg", "Black_Female.jpg", "Caucasion_Female.jpg", "Caucasion_Male.jpg", "Highlighted_Muscles.jpg", "Indian_Male.jpg"],
"morphs": ["Obesity", "Femininity", "Musculature", "Age", "Skinniness"],
"x": 0,
"y": -500,
"z": -300,
"s": 30
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - morph target - human</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #000;
font-family:Monospace;
font-size:13px;
text-align:center;
background-color: #fff;
margin: 0px;
overflow: hidden;
}
#info {
position: absolute;
top: 0px; width: 100%;
padding: 5px;
}
a {
color: #0af;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="info">
<a href="http://github.com/mrdoob/three.js" target="_blank" rel="noopener">three.js</a> webgl - morph targets - human
</div>
<script src="../build/three.js"></script>
<script src="js/UCSCharacter.js"></script>
<script src="js/WebGL.js"></script>
<script src='js/libs/dat.gui.min.js'></script>
<script src="js/controls/OrbitControls.js"></script>
<script>
var SCREEN_WIDTH = window.innerWidth;
var SCREEN_HEIGHT = window.innerHeight;
var container;
var camera, scene, renderer;
var character, controls;
var clock = new THREE.Clock();
var gui, skinConfig, morphConfig;
init();
animate();
function init() {
container = document.getElementById( 'container' );
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 100000 );
camera.position.set( 2000, 5000, 5000 );
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xffffff );
// LIGHTS
var light = new THREE.DirectionalLight( 0xffffff, 1 );
light.position.set( 0, 140, 500 );
light.position.multiplyScalar( 1.1 );
light.color.setHSL( 0.6, 0.075, 1 );
scene.add( light );
//
var light = new THREE.DirectionalLight( 0xffffff, 1 );
light.position.set( 0, - 1, 0 );
scene.add( light );
// RENDERER
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
container.appendChild( renderer.domElement );
// CHARACTER
character = new THREE.UCSCharacter();
character.onLoadComplete = function () {
console.log( "Load Complete" );
console.log( character.numSkins + " skins and " + character.numMorphs + " morphtargets loaded." );
gui = new dat.GUI();
setupSkinsGUI();
setupMorphsGUI();
gui.width = 300;
gui.open();
};
var loader = new THREE.FileLoader();
loader.load( 'models/skinned/UCS_config.json', function ( text ) {
var config = JSON.parse( text );
character.loadParts( config );
scene.add( character.root );
} );
window.addEventListener( 'resize', onWindowResize, false );
controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.target.set( 0, 3000, 0 );
controls.update();
controls.addEventListener( 'change', render );
}
function setupSkinsGUI() {
var skinGui = gui.addFolder( "Skins" );
skinConfig = {
wireframe: false
};
var skinCallback = function ( index ) {
return function () {
character.setSkin( index );
};
};
for ( var i = 0; i < character.numSkins; i ++ ) {
var name = character.skins[ i ].name;
skinConfig[ name ] = skinCallback( i );
}
for ( var i = 0; i < character.numSkins; i ++ ) {
skinGui.add( skinConfig, character.skins[ i ].name );
}
skinGui.open();
}
function setupMorphsGUI() {
var morphGui = gui.addFolder( "Morphs" );
morphConfig = {
};
var morphCallback = function () {
return function () {
character.updateMorphs( morphConfig );
};
};
for ( var i = 0; i < character.numMorphs; i ++ ) {
var morphName = character.morphs[ i ];
morphConfig[ morphName ] = 0;
}
for ( var i = 0; i < character.numMorphs; i ++ ) {
morphGui.add( morphConfig, character.morphs[ i ] ).min( 0 ).max( 100 ).onChange( morphCallback( i ) );
}
morphGui.open();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
//
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
var delta = 0.75 * clock.getDelta();
// update skinning
character.mixer.update( delta );
renderer.render( scene, camera );
}
</script>
</body>
</html>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册