Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1533,15 +1533,30 @@ class GLTFWriter {

}

let mimeType = map.userData.mimeType;
const mimeType = map.userData.mimeType;

if ( mimeType === 'image/webp' ) mimeType = 'image/png';
const imageIndex = this.processImage( map.image, map.format, map.flipY, mimeType );

const textureDef = {
sampler: this.processSampler( map ),
source: this.processImage( map.image, map.format, map.flipY, mimeType )
sampler: this.processSampler( map )
};

if ( mimeType === 'image/webp' ) {

textureDef.extensions = textureDef.extensions || {};
textureDef.extensions[ 'EXT_texture_webp' ] = {
source: imageIndex
};

this.extensionsUsed[ 'EXT_texture_webp' ] = true;
this.extensionsRequired[ 'EXT_texture_webp' ] = true;

} else {

textureDef.source = imageIndex;

}

if ( map.name ) textureDef.name = map.name;

await this._invokeAllAsync( async function ( ext ) {
Expand Down
130 changes: 130 additions & 0 deletions examples/jsm/loaders/usd/USDComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
BufferGeometry,
CapsuleGeometry,
ClampToEdgeWrapping,
Color,
ConeGeometry,
CylinderGeometry,
DirectionalLight,
Euler,
Group,
Matrix4,
Expand All @@ -17,14 +19,17 @@ import {
Object3D,
OrthographicCamera,
PerspectiveCamera,
PointLight,
Quaternion,
QuaternionKeyframeTrack,
RectAreaLight,
RepeatWrapping,
ShapeUtils,
SkinnedMesh,
Skeleton,
Bone,
SphereGeometry,
SpotLight,
SRGBColorSpace,
Texture,
Vector2,
Expand Down Expand Up @@ -725,6 +730,15 @@ class USDComposer {
parent.add( obj );
this._buildHierarchy( obj, path );

} else if ( typeName === 'DistantLight' || typeName === 'SphereLight' || typeName === 'RectLight' || typeName === 'DiskLight' ) {

const obj = this._buildLight( path, typeName );
obj.name = name;
const attrs = this._getAttributes( path );
this.applyTransform( obj, spec.fields, attrs );
parent.add( obj );
this._buildHierarchy( obj, path );

} else if ( typeName === 'Cube' || typeName === 'Sphere' || typeName === 'Cylinder' || typeName === 'Cone' || typeName === 'Capsule' ) {

const obj = this._buildGeomPrimitive( path, spec, typeName );
Expand Down Expand Up @@ -1435,6 +1449,122 @@ class USDComposer {

}

/**
* Build a light from a UsdLux light spec.
*/
_buildLight( path, typeName ) {

const attrs = this._getAttributes( path );

const intensity = this._parseNumber( attrs[ 'inputs:intensity' ], 1 );
const baseColor = attrs[ 'inputs:color' ] || [ 1, 1, 1 ];
const enableColorTemperature = attrs[ 'inputs:enableColorTemperature' ] === true;
const colorTemperature = this._parseNumber( attrs[ 'inputs:colorTemperature' ], 6500 );

const color = new Color( baseColor[ 0 ], baseColor[ 1 ], baseColor[ 2 ] );

if ( enableColorTemperature ) {

const temp = this._colorTemperature( colorTemperature );
color.multiply( temp );

}

let light;

switch ( typeName ) {

case 'DistantLight':
light = new DirectionalLight( color, intensity );
break;

case 'SphereLight': {

const coneAngle = this._parseNumber( attrs[ 'shaping:cone:angle' ], 0 );

if ( coneAngle > 0 ) {

const angle = coneAngle * Math.PI / 180;
const softness = this._parseNumber( attrs[ 'shaping:cone:softness' ], 0 );
light = new SpotLight( color, intensity, 0, angle, softness );

} else {

light = new PointLight( color, intensity );

}

break;

}

case 'RectLight': {

const width = this._parseNumber( attrs[ 'inputs:width' ], 1 );
const height = this._parseNumber( attrs[ 'inputs:height' ], 1 );
light = new RectAreaLight( color, intensity, width, height );
break;

}

case 'DiskLight': {

const radius = this._parseNumber( attrs[ 'inputs:radius' ], 0.5 );
const side = radius * 2;
light = new RectAreaLight( color, intensity, side, side );
break;

}

}

return light;

}

/**
* Convert a color temperature in Kelvin to an RGB Color.
* Based on Tanner Helland's algorithm.
*/
_colorTemperature( kelvin ) {

const temp = kelvin / 100;
let r, g, b;

if ( temp <= 66 ) {

r = 1;
g = 0.39008157876901960784 * Math.log( temp ) - 0.63184144378862745098;

} else {

r = 1.29293618606274509804 * Math.pow( temp - 60, - 0.1332047592 );
g = 1.12989086089529411765 * Math.pow( temp - 60, - 0.0755148492 );

}

if ( temp >= 66 ) {

b = 1;

} else if ( temp <= 19 ) {

b = 0;

} else {

b = 0.54320678911019607843 * Math.log( temp - 10 ) - 1.19625408914;

}

return new Color(
Math.min( Math.max( r, 0 ), 1 ),
Math.min( Math.max( g, 0 ), 1 ),
Math.min( Math.max( b, 0 ), 1 )
);

}

_parseNumber( value, fallback ) {

const n = Number( value );
Expand Down
34 changes: 33 additions & 1 deletion examples/misc_exporter_gltf.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
let container;

let camera, object, object2, material, geometry, scene1, scene2, renderer;
let gridHelper, sphere, model, coffeemat;
let gridHelper, sphere, model, coffeemat, webpBox;

const params = {
trs: false,
Expand All @@ -112,6 +112,7 @@
exportObjects: exportObjects,
exportSceneObject: exportSceneObject,
exportCompressedObject: exportCompressedObject,
exportWebPModel: exportWebPModel,
};

init();
Expand Down Expand Up @@ -501,6 +502,30 @@

} );

// ---------------------------------------------------------------------
// Box with WebP texture (EXT_texture_webp)
// ---------------------------------------------------------------------
const canvas = document.createElement( 'canvas' );
canvas.width = 64;
canvas.height = 64;
const ctx = canvas.getContext( '2d' );
ctx.fillStyle = '#005BBB';
ctx.fillRect( 0, 0, 64, 64 );
ctx.fillStyle = '#FFD500';
ctx.fillRect( 16, 16, 32, 32 );

const webpTexture = new THREE.CanvasTexture( canvas );
webpTexture.userData.mimeType = 'image/webp';
webpTexture.colorSpace = THREE.SRGBColorSpace;

webpBox = new THREE.Mesh(
new THREE.BoxGeometry( 100, 100, 100 ),
new THREE.MeshBasicMaterial( { map: webpTexture } )
);
webpBox.position.set( 400, 0, 0 );
webpBox.name = 'WebPBox';
scene1.add( webpBox );

//

const gui = new GUI();
Expand All @@ -519,6 +544,7 @@
h.add( params, 'exportObjects' ).name( 'Export Sphere With Grid' );
h.add( params, 'exportSceneObject' ).name( 'Export Scene 1 and Object' );
h.add( params, 'exportCompressedObject' ).name( 'Export Coffeemat (from compressed data)' );
h.add( params, 'exportWebPModel' ).name( 'Export WebP Model (EXT_texture_webp)' );

gui.open();

Expand Down Expand Up @@ -566,6 +592,12 @@

}

function exportWebPModel() {

exportGLTF( webpBox );

}

function onWindowResize() {

camera.aspect = window.innerWidth / window.innerHeight;
Expand Down
Binary file modified examples/screenshots/misc_exporter_gltf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions manual/en/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ <h1>Making a Game</h1>
<p>When I first started this I used just one radius for all animals
but of course that was no good as the pug is much smaller than the horse.
So I added the difference sizes but I wanted to be able to visualize
things. To do that I made a <code class="notranslate" translate="no">StatusDisplayHelper</code> component.</p>
things. To do that I made a <code class="notranslate" translate="no">StateDisplayHelper</code> component.</p>
<p>I uses a <a href="/docs/#api/en/helpers/PolarGridHelper"><code class="notranslate" translate="no">PolarGridHelper</code></a> to draw a circle around each character
and it uses html elements to let each character show some status using
the techniques covered in <a href="align-html-elements-to-3d.html">the article on aligning html elements to 3D</a>.</p>
Expand Down Expand Up @@ -1673,7 +1673,7 @@ <h1>Making a Game</h1>
<p>To make a coroutine you make a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*">JavaScript generator function</a>.
A generator function is preceded by the keyword <code class="notranslate" translate="no">function*</code> (the asterisk is important!)</p>
<p>Generator functions can <code class="notranslate" translate="no">yield</code>. For example</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function* countOTo9() {
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function* count0To9() {
for (let i = 0; i &lt; 10; ++i) {
console.log(i);
yield;
Expand Down
4 changes: 2 additions & 2 deletions manual/fr/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ <h1>Crรฉer un jeu</h1>
<p>Lorsque j'ai commencรฉ cela, j'ai utilisรฉ un seul rayon pour tous les animaux,
mais bien sรปr, ce n'รฉtait pas bon, car le carlin est beaucoup plus petit que le cheval.
J'ai donc ajoutรฉ les diffรฉrentes tailles, mais je voulais pouvoir visualiser
les choses. Pour ce faire, j'ai crรฉรฉ un composant <code class="notranslate" translate="no">StatusDisplayHelper</code>.</p>
les choses. Pour ce faire, j'ai crรฉรฉ un composant <code class="notranslate" translate="no">StateDisplayHelper</code>.</p>
<p>J'utilise un <a href="/docs/#api/en/helpers/PolarGridHelper"><code class="notranslate" translate="no">PolarGridHelper</code></a> pour dessiner un cercle autour de chaque personnage,
et il utilise des รฉlรฉments html pour permettre ร  chaque personnage d'afficher un certain statut en utilisant
les techniques couvertes dans <a href="align-html-elements-to-3d.html">l'article sur l'alignement des รฉlรฉments html en 3D</a>.</p>
Expand Down Expand Up @@ -1498,7 +1498,7 @@ <h1>Crรฉer un jeu</h1>
<p>Pour crรฉer une coroutine, vous crรฉez une <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*">fonction gรฉnรฉratrice JavaScript</a>.
Une fonction gรฉnรฉratrice est prรฉcรฉdรฉe du mot-clรฉ <code class="notranslate" translate="no">function*</code> (l'astรฉrisque est important !)</p>
<p>Les fonctions gรฉnรฉratrices peuvent <code class="notranslate" translate="no">yield</code> (cรฉder). Par exemple</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function* countOTo9() {
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function* count0To9() {
for (let i = 0; i &lt; 10; ++i) {
console.log(i);
yield;
Expand Down
4 changes: 2 additions & 2 deletions manual/ko/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ <h1>๋กœ ๊ฒŒ์ž„ ๋งŒ๋“ค๊ธฐ</h1>
+ globals.playerRadius = model.size / 2;
</pre>
<p>์ด์ œ ์™€ ์ƒ๊ฐํ•ด๋ณด๋‹ˆ ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์•„๋‹ˆ๋ผ ๊ธฐ์ฐจ์˜ ๋จธ๋ฆฌ๋ฅผ ๋ฐ”๋ผ๋ณด๊ฒŒ ํ•˜๋Š” ํŽธ์ด ๋” ๋‚˜์•˜๊ฒ ๋„ค์š”. ์ด๊ฑด ๋‚˜์ค‘์— ๋Œ์•„์™€ ๊ณ ์น˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.</p>
<p>์˜ˆ์ œ๋ฅผ ์ฒ˜์Œ ๋งŒ๋“ค์—ˆ์„ ๋•Œ๋Š” ๋™๋ฌผ๋“ค์ด ๋ชจ๋‘ ๊ฐ™์€ ํฌ๊ธฐ์˜ ๊ฒฝ๊ณ„ ์›(radius)์„ ์ผ์ง€๋งŒ, ์ด๋ ‡๊ฒŒ ํ•˜๊ณ  ๋ณด๋‹ˆ ๋ง๊ณผ ํผ๊ทธ(๊ฐ•์•„์ง€)์˜ ํฌ๊ธฐ๊ฐ€ ๊ฐ™์€ ๊ฒŒ ๋ง์ด ์•ˆ ๋œ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๊ฐ ๋ชจ๋ธ์˜ ํฌ๊ธฐ์— ๋”ฐ๋ผ ๊ฒฝ๊ณ„ ์›์„ ๋”ฐ๋กœ ์ง€์ •ํ–ˆ์ฃ . ๊ทธ๋ฆฌ๊ณ  ์ƒํƒœ๋ฅผ ๋ณด์—ฌ์ฃผ๋ฉด ์ข‹๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด ์ƒํƒœ๋ฅผ ๋ณด์—ฌ ์ค„ <code class="notranslate" translate="no">StatusDisplayHelper</code> ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.</p>
<p>์˜ˆ์ œ๋ฅผ ์ฒ˜์Œ ๋งŒ๋“ค์—ˆ์„ ๋•Œ๋Š” ๋™๋ฌผ๋“ค์ด ๋ชจ๋‘ ๊ฐ™์€ ํฌ๊ธฐ์˜ ๊ฒฝ๊ณ„ ์›(radius)์„ ์ผ์ง€๋งŒ, ์ด๋ ‡๊ฒŒ ํ•˜๊ณ  ๋ณด๋‹ˆ ๋ง๊ณผ ํผ๊ทธ(๊ฐ•์•„์ง€)์˜ ํฌ๊ธฐ๊ฐ€ ๊ฐ™์€ ๊ฒŒ ๋ง์ด ์•ˆ ๋œ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๊ฐ ๋ชจ๋ธ์˜ ํฌ๊ธฐ์— ๋”ฐ๋ผ ๊ฒฝ๊ณ„ ์›์„ ๋”ฐ๋กœ ์ง€์ •ํ–ˆ์ฃ . ๊ทธ๋ฆฌ๊ณ  ์ƒํƒœ๋ฅผ ๋ณด์—ฌ์ฃผ๋ฉด ์ข‹๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด ์ƒํƒœ๋ฅผ ๋ณด์—ฌ ์ค„ <code class="notranslate" translate="no">StateDisplayHelper</code> ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.</p>
<p>๋˜ํ•œ <a href="/docs/#api/ko/helpers/PolarGridHelper"><code class="notranslate" translate="no">PolarGridHelper</code></a>๋ฅผ ์จ ๊ฐ ์บ๋ฆญํ„ฐ์˜ ๊ฒฝ๊ณ„ ์›์ด ๋ณด์ด๋„๋ก ํ–ˆ๊ณ , <a href="align-html-elements-to-3d.html">HTML ์š”์†Œ๋ฅผ 3D๋กœ ์ •๋ ฌํ•˜๊ธฐ</a>์—์„œ ์ผ๋˜ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ฐ ์บ๋ฆญํ„ฐ์˜ ์ƒํƒœ๋ฅผ HTML๋กœ ๋ณด์—ฌ์ฃผ๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค.</p>
<p>๋จผ์ € ๊ฐ ์š”์†Œ๋ฅผ ๋‹ด์„ HTML์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.</p>
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;body&gt;
Expand Down Expand Up @@ -1438,7 +1438,7 @@ <h1>๋กœ ๊ฒŒ์ž„ ๋งŒ๋“ค๊ธฐ</h1>
<p>์œ„ ํด๋ž˜์Šค๋Š” ๋‹ค๋ฅธ ์ฝ”๋ฃจํ‹ด์ด ์‹คํ–‰๋˜๋Š” ๋™์•ˆ ์š”์†Œ๋ฅผ ์•ˆ์ „ํ•˜๊ฒŒ ์ œ๊ฑฐ/์ถ”๊ฐ€ํ•˜๋„๋ก <code class="notranslate" translate="no">SafeArray</code>์™€ ๋น„์Šทํ•œ ๊ตฌ์กฐ๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ์ด ํด๋ž˜์Šค๋Š” ์ค‘์ฒฉ๋œ ์ฝ”๋ฃจํ‹ด๋„ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.</p>
<p>์ฝ”๋ฃจํ‹ด์„ ๋งŒ๋“ค๋ ค๋ฉด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ <a href="https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/function*">์ œ๋„ˆ๋ ˆ์ดํ„ฐ ํ•จ์ˆ˜</a>๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ œ๋„ˆ๋ ˆ์ดํ„ฐ ํ•จ์ˆ˜๋Š” <code class="notranslate" translate="no">function*</code>์ด๋ผ๋Š” ํ‚ค์›Œ๋“œ๋กœ ์ƒ์„ฑํ•˜์ฃ (๋ณ„ํ‘œ๋ฅผ ๋ถ™์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค!).</p>
<p>์ œ๋„ˆ๋ ˆ์ดํ„ฐ ํ•จ์ˆ˜๋Š” <code class="notranslate" translate="no">yield</code> ํ‚ค์›Œ๋“œ๋กœ ์‹คํ–‰ ์ˆœ์„œ๋ฅผ <strong>์–‘๋ณด(yield)</strong>ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function* countOTo9() {
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function* count0To9() {
for (let i = 0; i &lt; 10; ++i) {
console.log(i);
yield;
Expand Down
Loading