未验证 提交 a8a6aec4 编写于 作者: M Michael Herzog 提交者: GitHub

Merge pull request #16472 from Mugen87/dev30

JSM: More modules and TS files.
......@@ -88,6 +88,7 @@
<li>OrthographicTrackballControls</li>
<li>PointerLockControls</li>
<li>TrackballControls</li>
<li>TransformControls</li>
</ul>
</li>
<li>exporters
......@@ -121,6 +122,12 @@
<li>PMREMGenerator</li>
</ul>
</li>
<li>renderers
<ul>
<li>CSS2DRenderer</li>
<li>CSS3DRenderer</li>
</ul>
</li>
<li>utils
<ul>
<li>BufferGeometryUtils</li>
......
......@@ -151,7 +151,7 @@ THREE.MTLLoader.prototype = {
} else {
if ( key === 'ka' || key === 'kd' || key === 'ks' || key ==='ke' ) {
if ( key === 'ka' || key === 'kd' || key === 'ks' || key === 'ke' ) {
var ss = value.split( delimiter_pattern, 3 );
info[ key ] = [ parseFloat( ss[ 0 ] ), parseFloat( ss[ 1 ] ), parseFloat( ss[ 2 ] ) ];
......
import {
Object3D,
Camera,
Vector3,
Euler
} from '../../../src/Three';
export class TransformControls extends Object3D {
constructor(object: Camera, domElement?: HTMLElement);
domElement: HTMLElement;
// API
camera: Camera;
object: Object3D;
enabled: boolean;
axis: string;
mode: string;
translationSnap: Vector3;
rotationSnap: Vector3;
space: string;
size: number;
dragging: boolean;
showX: boolean;
showY: boolean;
showZ: boolean;
isTransformControls: boolean;
visible: boolean;
attach(object: Object3D): void;
detach(): void;
pointerHover(pointer: Object): void;
pointerDown(pointer: Object): void;
pointerMove(pointer: Object): void;
pointerUp(pointer: Object): void;
getMode(): string;
setMode(mode: string): void;
setTranslationSnap(translationSnap: Vector3): void;
setRotationSnap(rotationSnap: Euler): void;
setSize(size: number): void;
setSpace(space: string): void;
dispose(): void;
update(): void;
}
此差异已折叠。
......@@ -5,17 +5,13 @@
*/
import {
BackSide,
ClampToEdgeWrapping,
Color,
DefaultLoadingManager,
DoubleSide,
FileLoader,
FrontSide,
Loader,
LoaderUtils,
MeshPhongMaterial,
MirroredRepeatWrapping,
RepeatWrapping,
TextureLoader,
Vector2
......@@ -31,6 +27,8 @@ MTLLoader.prototype = {
constructor: MTLLoader,
crossOrigin: 'anonymous',
/**
* Loads and parses a MTL asset from a URL.
*
......@@ -166,7 +164,7 @@ MTLLoader.prototype = {
} else {
if ( key === 'ka' || key === 'kd' || key === 'ks' || key ==='ke' ) {
if ( key === 'ka' || key === 'kd' || key === 'ks' || key === 'ke' ) {
var ss = value.split( delimiter_pattern, 3 );
info[ key ] = [ parseFloat( ss[ 0 ] ), parseFloat( ss[ 1 ] ), parseFloat( ss[ 2 ] ) ];
......@@ -196,9 +194,9 @@ MTLLoader.prototype = {
* @param baseUrl - Url relative to which textures are loaded
* @param options - Set of options on how to construct the materials
* side: Which side to apply the material
* FrontSide (default), BackSide, DoubleSide
* FrontSide (default), THREE.BackSide, THREE.DoubleSide
* wrap: What type of wrapping to apply for textures
* RepeatWrapping (default), ClampToEdgeWrapping, MirroredRepeatWrapping
* RepeatWrapping (default), THREE.ClampToEdgeWrapping, THREE.MirroredRepeatWrapping
* normalizeRGB: RGBs need to be normalized to 0-1 from 0-255
* Default: false, assumed to be already normalized
* ignoreZeroRGBs: Ignore values of RGBs (Ka,Kd,Ks) that are all 0's
......
import {
Object3D,
Scene,
Camera
} from '../../../src/Three';
export class CSS2DObject extends Object3D {
constructor(element: HTMLElement);
element: HTMLElement;
}
export class CSS2DRenderer {
constructor();
domElement: HTMLElement;
getSize(): {width: number, height: number};
setSize(width: number, height: number): void;
render(scene: Scene, camera: Camera): void;
}
/**
* @author mrdoob / http://mrdoob.com/
*/
import {
Matrix4,
Object3D,
REVISION,
Vector3
} from "../../../build/three.module.js";
var CSS2DObject = function ( element ) {
Object3D.call( this );
this.element = element;
this.element.style.position = 'absolute';
this.addEventListener( 'removed', function () {
if ( this.element.parentNode !== null ) {
this.element.parentNode.removeChild( this.element );
}
} );
};
CSS2DObject.prototype = Object.create( Object3D.prototype );
CSS2DObject.prototype.constructor = CSS2DObject;
//
var CSS2DRenderer = function () {
console.log( 'THREE.CSS2DRenderer', REVISION );
var _width, _height;
var _widthHalf, _heightHalf;
var vector = new Vector3();
var viewMatrix = new Matrix4();
var viewProjectionMatrix = new Matrix4();
var cache = {
objects: new WeakMap()
};
var domElement = document.createElement( 'div' );
domElement.style.overflow = 'hidden';
this.domElement = domElement;
this.getSize = function () {
return {
width: _width,
height: _height
};
};
this.setSize = function ( width, height ) {
_width = width;
_height = height;
_widthHalf = _width / 2;
_heightHalf = _height / 2;
domElement.style.width = width + 'px';
domElement.style.height = height + 'px';
};
var renderObject = function ( object, camera ) {
if ( object instanceof CSS2DObject ) {
vector.setFromMatrixPosition( object.matrixWorld );
vector.applyMatrix4( viewProjectionMatrix );
var element = object.element;
var style = 'translate(-50%,-50%) translate(' + ( vector.x * _widthHalf + _widthHalf ) + 'px,' + ( - vector.y * _heightHalf + _heightHalf ) + 'px)';
element.style.WebkitTransform = style;
element.style.MozTransform = style;
element.style.oTransform = style;
element.style.transform = style;
element.style.display = ( object.visible && vector.z >= - 1 && vector.z <= 1 ) ? '' : 'none';
var objectData = {
distanceToCameraSquared: getDistanceToSquared( camera, object )
};
cache.objects.set( object, objectData );
if ( element.parentNode !== domElement ) {
domElement.appendChild( element );
}
}
for ( var i = 0, l = object.children.length; i < l; i ++ ) {
renderObject( object.children[ i ], camera );
}
};
var getDistanceToSquared = function () {
var a = new Vector3();
var b = new Vector3();
return function ( object1, object2 ) {
a.setFromMatrixPosition( object1.matrixWorld );
b.setFromMatrixPosition( object2.matrixWorld );
return a.distanceToSquared( b );
};
}();
var filterAndFlatten = function ( scene ) {
var result = [];
scene.traverse( function ( object ) {
if ( object instanceof CSS2DObject ) result.push( object );
} );
return result;
};
var zOrder = function ( scene ) {
var sorted = filterAndFlatten( scene ).sort( function ( a, b ) {
var distanceA = cache.objects.get( a ).distanceToCameraSquared;
var distanceB = cache.objects.get( b ).distanceToCameraSquared;
return distanceA - distanceB;
} );
var zMax = sorted.length;
for ( var i = 0, l = sorted.length; i < l; i ++ ) {
sorted[ i ].element.style.zIndex = zMax - i;
}
};
this.render = function ( scene, camera ) {
scene.updateMatrixWorld();
if ( camera.parent === null ) camera.updateMatrixWorld();
viewMatrix.copy( camera.matrixWorldInverse );
viewProjectionMatrix.multiplyMatrices( camera.projectionMatrix, viewMatrix );
renderObject( scene, camera );
zOrder( scene );
};
};
export { CSS2DObject, CSS2DRenderer };
import {
Object3D,
Scene,
Camera
} from '../../../src/Three';
export class CSS3DObject extends Object3D {
constructor(element: HTMLElement);
element: HTMLElement;
}
export class CSS3DSprite extends CSS3DObject {
constructor(element: HTMLElement);
}
export class CSS3DRenderer {
constructor();
domElement: HTMLElement;
getSize(): {width: number, height: number};
setSize(width: number, height: number): void;
render(scene: Scene, camera: Camera): void;
}
/**
* Based on http://www.emagix.net/academic/mscs-project/item/camera-sync-with-css3-and-webgl-threejs
* @author mrdoob / http://mrdoob.com/
* @author yomotsu / https://yomotsu.net/
*/
import {
Matrix4,
Object3D,
REVISION,
Vector3
} from "../../../build/three.module.js";
var CSS3DObject = function ( element ) {
Object3D.call( this );
this.element = element;
this.element.style.position = 'absolute';
this.addEventListener( 'removed', function () {
if ( this.element.parentNode !== null ) {
this.element.parentNode.removeChild( this.element );
}
} );
};
CSS3DObject.prototype = Object.create( Object3D.prototype );
CSS3DObject.prototype.constructor = CSS3DObject;
var CSS3DSprite = function ( element ) {
CSS3DObject.call( this, element );
};
CSS3DSprite.prototype = Object.create( CSS3DObject.prototype );
CSS3DSprite.prototype.constructor = CSS3DSprite;
//
var CSS3DRenderer = function () {
console.log( 'THREE.CSS3DRenderer', REVISION );
var _width, _height;
var _widthHalf, _heightHalf;
var matrix = new Matrix4();
var cache = {
camera: { fov: 0, style: '' },
objects: new WeakMap()
};
var domElement = document.createElement( 'div' );
domElement.style.overflow = 'hidden';
this.domElement = domElement;
var cameraElement = document.createElement( 'div' );
cameraElement.style.WebkitTransformStyle = 'preserve-3d';
cameraElement.style.transformStyle = 'preserve-3d';
domElement.appendChild( cameraElement );
var isIE = /Trident/i.test( navigator.userAgent );
this.getSize = function () {
return {
width: _width,
height: _height
};
};
this.setSize = function ( width, height ) {
_width = width;
_height = height;
_widthHalf = _width / 2;
_heightHalf = _height / 2;
domElement.style.width = width + 'px';
domElement.style.height = height + 'px';
cameraElement.style.width = width + 'px';
cameraElement.style.height = height + 'px';
};
function epsilon( value ) {
return Math.abs( value ) < 1e-10 ? 0 : value;
}
function getCameraCSSMatrix( matrix ) {
var elements = matrix.elements;
return 'matrix3d(' +
epsilon( elements[ 0 ] ) + ',' +
epsilon( - elements[ 1 ] ) + ',' +
epsilon( elements[ 2 ] ) + ',' +
epsilon( elements[ 3 ] ) + ',' +
epsilon( elements[ 4 ] ) + ',' +
epsilon( - elements[ 5 ] ) + ',' +
epsilon( elements[ 6 ] ) + ',' +
epsilon( elements[ 7 ] ) + ',' +
epsilon( elements[ 8 ] ) + ',' +
epsilon( - elements[ 9 ] ) + ',' +
epsilon( elements[ 10 ] ) + ',' +
epsilon( elements[ 11 ] ) + ',' +
epsilon( elements[ 12 ] ) + ',' +
epsilon( - elements[ 13 ] ) + ',' +
epsilon( elements[ 14 ] ) + ',' +
epsilon( elements[ 15 ] ) +
')';
}
function getObjectCSSMatrix( matrix, cameraCSSMatrix ) {
var elements = matrix.elements;
var matrix3d = 'matrix3d(' +
epsilon( elements[ 0 ] ) + ',' +
epsilon( elements[ 1 ] ) + ',' +
epsilon( elements[ 2 ] ) + ',' +
epsilon( elements[ 3 ] ) + ',' +
epsilon( - elements[ 4 ] ) + ',' +
epsilon( - elements[ 5 ] ) + ',' +
epsilon( - elements[ 6 ] ) + ',' +
epsilon( - elements[ 7 ] ) + ',' +
epsilon( elements[ 8 ] ) + ',' +
epsilon( elements[ 9 ] ) + ',' +
epsilon( elements[ 10 ] ) + ',' +
epsilon( elements[ 11 ] ) + ',' +
epsilon( elements[ 12 ] ) + ',' +
epsilon( elements[ 13 ] ) + ',' +
epsilon( elements[ 14 ] ) + ',' +
epsilon( elements[ 15 ] ) +
')';
if ( isIE ) {
return 'translate(-50%,-50%)' +
'translate(' + _widthHalf + 'px,' + _heightHalf + 'px)' +
cameraCSSMatrix +
matrix3d;
}
return 'translate(-50%,-50%)' + matrix3d;
}
function renderObject( object, camera, cameraCSSMatrix ) {
if ( object instanceof CSS3DObject ) {
var style;
if ( object instanceof CSS3DSprite ) {
// http://swiftcoder.wordpress.com/2008/11/25/constructing-a-billboard-matrix/
matrix.copy( camera.matrixWorldInverse );
matrix.transpose();
matrix.copyPosition( object.matrixWorld );
matrix.scale( object.scale );
matrix.elements[ 3 ] = 0;
matrix.elements[ 7 ] = 0;
matrix.elements[ 11 ] = 0;
matrix.elements[ 15 ] = 1;
style = getObjectCSSMatrix( matrix, cameraCSSMatrix );
} else {
style = getObjectCSSMatrix( object.matrixWorld, cameraCSSMatrix );
}
var element = object.element;
var cachedObject = cache.objects.get( object );
if ( cachedObject === undefined || cachedObject.style !== style ) {
element.style.WebkitTransform = style;
element.style.transform = style;
var objectData = { style: style };
if ( isIE ) {
objectData.distanceToCameraSquared = getDistanceToSquared( camera, object );
}
cache.objects.set( object, objectData );
}
if ( element.parentNode !== cameraElement ) {
cameraElement.appendChild( element );
}
}
for ( var i = 0, l = object.children.length; i < l; i ++ ) {
renderObject( object.children[ i ], camera, cameraCSSMatrix );
}
}
var getDistanceToSquared = function () {
var a = new Vector3();
var b = new Vector3();
return function ( object1, object2 ) {
a.setFromMatrixPosition( object1.matrixWorld );
b.setFromMatrixPosition( object2.matrixWorld );
return a.distanceToSquared( b );
};
}();
function filterAndFlatten( scene ) {
var result = [];
scene.traverse( function ( object ) {
if ( object instanceof CSS3DObject ) result.push( object );
} );
return result;
}
function zOrder( scene ) {
var sorted = filterAndFlatten( scene ).sort( function ( a, b ) {
var distanceA = cache.objects.get( a ).distanceToCameraSquared;
var distanceB = cache.objects.get( b ).distanceToCameraSquared;
return distanceA - distanceB;
} );
var zMax = sorted.length;
for ( var i = 0, l = sorted.length; i < l; i ++ ) {
sorted[ i ].element.style.zIndex = zMax - i;
}
}
this.render = function ( scene, camera ) {
var fov = camera.projectionMatrix.elements[ 5 ] * _heightHalf;
if ( cache.camera.fov !== fov ) {
if ( camera.isPerspectiveCamera ) {
domElement.style.WebkitPerspective = fov + 'px';
domElement.style.perspective = fov + 'px';
}
cache.camera.fov = fov;
}
scene.updateMatrixWorld();
if ( camera.parent === null ) camera.updateMatrixWorld();
if ( camera.isOrthographicCamera ) {
var tx = - ( camera.right + camera.left ) / 2;
var ty = ( camera.top + camera.bottom ) / 2;
}
var cameraCSSMatrix = camera.isOrthographicCamera ?
'scale(' + fov + ')' + 'translate(' + epsilon( tx ) + 'px,' + epsilon( ty ) + 'px)' + getCameraCSSMatrix( camera.matrixWorldInverse ) :
'translateZ(' + fov + 'px)' + getCameraCSSMatrix( camera.matrixWorldInverse );
var style = cameraCSSMatrix +
'translate(' + _widthHalf + 'px,' + _heightHalf + 'px)';
if ( cache.camera.style !== style && ! isIE ) {
cameraElement.style.WebkitTransform = style;
cameraElement.style.transform = style;
cache.camera.style = style;
}
renderObject( scene, camera, cameraCSSMatrix );
if ( isIE ) {
// IE10 and 11 does not support 'preserve-3d'.
// Thus, z-order in 3D will not work.
// We have to calc z-order manually and set CSS z-index for IE.
// FYI: z-index can't handle object intersection
zOrder( scene );
}
};
};
export { CSS3DObject, CSS3DSprite, CSS3DRenderer };
......@@ -18,7 +18,7 @@ var files = [
{ path: 'controls/OrthographicTrackballControls.js', ignoreList: [] },
{ path: 'controls/PointerLockControls.js', ignoreList: [] },
{ path: 'controls/TrackballControls.js', ignoreList: [] },
// { path: 'controls/TransformControls.js', ignoreList: [] },
{ path: 'controls/TransformControls.js', ignoreList: [] },
{ path: 'exporters/GLTFExporter.js', ignoreList: [ 'AnimationClip', 'Camera', 'Geometry', 'Material', 'Mesh', 'Object3D', 'RGBFormat', 'Scenes', 'ShaderMaterial', 'VertexColors' ] },
{ path: 'exporters/MMDExporter.js', ignoreList: [] },
......@@ -31,7 +31,7 @@ var files = [
{ path: 'loaders/PCDLoader.js', ignoreList: [] },
{ path: 'loaders/GLTFLoader.js', ignoreList: [ 'NoSide', 'Matrix2', 'DDSLoader' ] },
{ path: 'loaders/OBJLoader.js', ignoreList: [] },
{ path: 'loaders/MTLLoader.js', ignoreList: [] },
{ path: 'loaders/MTLLoader.js', ignoreList: [ 'BackSide', 'DoubleSide', 'ClampToEdgeWrapping', 'MirroredRepeatWrapping' ] },
{ path: 'loaders/PLYLoader.js', ignoreList: [ 'Mesh' ] },
{ path: 'loaders/STLLoader.js', ignoreList: [ 'Mesh', 'MeshPhongMaterial', 'VertexColors' ] },
{ path: 'loaders/SVGLoader.js', ignoreList: [] },
......@@ -41,6 +41,9 @@ var files = [
{ path: 'pmrem/PMREMCubeUVPacker.js', ignoreList: [] },
{ path: 'pmrem/PMREMGenerator.js', ignoreList: [] },
{ path: 'renderers/CSS2DRenderer.js', ignoreList: [] },
{ path: 'renderers/CSS3DRenderer.js', ignoreList: [] },
{ path: 'utils/BufferGeometryUtils.js', ignoreList: [] },
{ path: 'utils/GeometryUtils.js', ignoreList: [] },
{ path: 'utils/MathUtils.js', ignoreList: [] },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册