From 4394dc65a298c715dc6bbf3111dfae2aa8e4f840 Mon Sep 17 00:00:00 2001 From: Antoine Pultier Date: Tue, 29 Jul 2014 15:43:41 +0200 Subject: [PATCH 01/11] API update (version 0.7.3) --- leaflet/leaflet.d.ts | 145 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 141 insertions(+), 4 deletions(-) diff --git a/leaflet/leaflet.d.ts b/leaflet/leaflet.d.ts index 54f0fe4f0..ff5a42d05 100644 --- a/leaflet/leaflet.d.ts +++ b/leaflet/leaflet.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Leaflet.js 0.6.4 +// Type definitions for Leaflet.js 0.7.3 // Project: https://github.com/Leaflet/Leaflet // Definitions by: Vladimir Zotov // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -870,6 +870,13 @@ declare module L { * Default value: [0, 0]. */ padding?: Point; + + /** + * The maximum possible zoom to use. + * + * Default value: null + */ + maxZoom?: number; } } @@ -1128,6 +1135,11 @@ declare module L { * Mercator-based CRS. */ scale(zoom: number): number; + + /** + * Returns the size of the world in pixels for a particular zoom. + */ + getSize(zoom: number): Point; } } @@ -1277,6 +1289,11 @@ declare module L { * Sets the opacity of the overlay. */ setOpacity(opacity: number): ImageOverlay; + + /** + * Changes the URL of the image. + */ + setUrl(imageUrl: string): ImageOverlay; /** * Brings the layer to the top of all overlays. @@ -1802,6 +1819,17 @@ declare module L { popup: Popup; } } + +declare module L { + + export interface LeafletDragEndEvent extends LeafletEvent { + + /** + * The distance in pixels the draggable element was moved by. + */ + distance: number; + } +} declare module L { @@ -1960,7 +1988,7 @@ declare module L { * Sets the view of the map (geographical center and zoom) with the given * animation options. */ - setView(center: LatLng, zoom: number, options?: ZoomPanOptions): Map; + setView(center: LatLng, zoom?: number, options?: ZoomPanOptions): Map; /** * Sets the zoom of the map. @@ -2370,17 +2398,24 @@ declare module L { /** * Whether the map can be zoomed by using the mouse wheel. + * If passed 'center', it will zoom to the center of the view regardless of + * where the mouse was. * * Default value: true. */ scrollWheelZoom?: boolean; + scrollWheelZoom?: string; /** - * Whether the map can be zoomed in by double clicking on it. + * Whether the map can be zoomed in by double clicking on it and zoomed out + * by double clicking while holding shift. + * If passed 'center', double-click zoom will zoom to the center of the view + * regardless of where the mouse was. * * Default value: true. */ doubleClickZoom?: boolean; + doubleClickZoom?: string; /** * Whether the map can be zoomed to a rectangular area specified by dragging @@ -2529,6 +2564,14 @@ declare module L { * in all browsers that support CSS3 Transitions except Android. */ markerZoomAnimation?: boolean; + + /** + * Set it to false if you don't want the map to zoom beyond min/max zoom + * and then bounce back when pinch-zooming. + * + * Default value: true. + */ + bounceAtZoomLimits?: boolean; } } @@ -2652,6 +2695,11 @@ declare module L { * Opens the popup previously bound by the bindPopup method. */ openPopup(): Marker; + + /** + * Returns the popup previously bound by the bindPopup method. + */ + getPopup(): Popup; /** * Closes the bound popup of the marker if it's opened. @@ -2752,6 +2800,13 @@ declare module L { * Default value: ''. */ title?: string; + + /** + * Text for the alt attribute of the icon image (useful for accessibility). + * + * Default value: ''. + */ + alt?: string; /** * By default, marker images zIndex is set automatically based on its latitude. @@ -2814,6 +2869,11 @@ declare module L { */ getLatLngs(): LatLng[][]; + /** + * Opens the popup previously bound by bindPopup. + */ + openPopup(): MultiPolygon; + /** * Returns a GeoJSON representation of the multipolygon (GeoJSON MultiPolygon Feature). */ @@ -2848,6 +2908,11 @@ declare module L { */ getLatLngs(): LatLng[][]; + /** + * Opens the popup previously bound by bindPopup. + */ + openPopup(): MultiPolyline; + /** * Returns a GeoJSON representation of the multipolyline (GeoJSON MultiLineString Feature). */ @@ -3076,6 +3141,20 @@ declare module L { * layers (e.g. Android 2). */ dashArray?: string; + + /** + * A string that defines shape to be used at the end of the stroke. + * + * Default: null. + */ + lineCap?: string; + + /** + * A string that defines shape to be used at the corners of the stroke. + * + * Default: null. + */ + lineJoin?: string; /** * If false, the vector will not emit mouse events and will act as a part of the @@ -3089,6 +3168,13 @@ declare module L { * Sets the pointer-events attribute on the path if SVG backend is used. */ pointerEvents?: boolean; + + /** + * Custom class name set on an element. + * + * Default value: ''. + */ + className?: string; } } @@ -3308,7 +3394,12 @@ declare module L { * Sets the geographical point where the popup will open. */ setLatLng(latlng: LatLng): Popup; - + + /** + * Returns the geographical point of popup. + */ + getLatLng(): LatLng; + /** * Sets the HTML content of the popup. */ @@ -3319,6 +3410,16 @@ declare module L { */ setContent(el: HTMLElement): Popup; + /** + * Returns the content of the popup. + */ + getContent(): string; + + /** + * Returns the content of the popup. + */ + getContent(): HTMLElement; + //////////// //////////// /** @@ -3333,6 +3434,12 @@ declare module L { * the DOM and removes listeners previously added in onAdd. Called on map.removeLayer(layer). */ onRemove(map: Map): void; + + /** + * Updates the popup content, layout and position. Useful for updating the popup after + * something inside changed, e.g. image loaded. + */ + update(): Popup; } } @@ -3382,6 +3489,22 @@ declare module L { * Default value: new Point(0, 6). */ offset?: Point; + + /** + * The margin between the popup and the top left corner of the map view after + * autopanning was performed. + * + * Default value: null. + */ + autoPanPaddingTopLeft?: Point; + + /** + * The margin between the popup and the bottom right corner of the map view after + * autopanning was performed. + * + * Default value: null. + */ + autoPanPaddingBottomRight?: Point; /** * The margin between the popup and the edges of the map view after autopanning @@ -3695,6 +3818,15 @@ declare module L { * Default value: 18. */ maxZoom?: number; + + /** + * Maximum zoom number the tiles source has available. If it is specified, + * the tiles on all zoom levels higher than maxNativeZoom will be loaded from + * maxZoom level and auto-scaled. + * + * Default value: null. + */ + maxNativeZoom?: number; /** * Tile size (width and height in pixels, assuming tiles are square). @@ -3997,6 +4129,11 @@ declare module L { * An equivalent of passing animate to both zoom and pan options (see below). */ animate?: boolean; + + /** + * If true, it will delay moveend event so that it doesn't happen many times in a row. + */ + debounceMoveend?: boolean; } } From c11810a1cc5cbf7f8008b930bb2abef2d332fe7e Mon Sep 17 00:00:00 2001 From: Antoine Pultier Date: Tue, 29 Jul 2014 15:55:02 +0200 Subject: [PATCH 02/11] L.Handler object --- leaflet/leaflet.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/leaflet/leaflet.d.ts b/leaflet/leaflet.d.ts index ff5a42d05..42a7d4d82 100644 --- a/leaflet/leaflet.d.ts +++ b/leaflet/leaflet.d.ts @@ -1243,6 +1243,10 @@ declare module L { */ enabled(): boolean; } + + export class Handler extends Class implements IHandler { + initialize(map: Map): void; + } } declare module L { From 4d014a48600d27b4626bab48816977cb7c850aa5 Mon Sep 17 00:00:00 2001 From: Antoine Pultier Date: Tue, 29 Jul 2014 16:17:55 +0200 Subject: [PATCH 03/11] Leaflet: L.Mixin.Events --- leaflet/leaflet.d.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/leaflet/leaflet.d.ts b/leaflet/leaflet.d.ts index 42a7d4d82..7f7b8dc9a 100644 --- a/leaflet/leaflet.d.ts +++ b/leaflet/leaflet.d.ts @@ -1267,6 +1267,17 @@ declare module L { onRemove(map: Map): void; } } + +declare module L { + export var Mixin: any; + + module Mixin { + export interface LeafletMixinEvents implements IEventPowered { + } + + export var Events: LeafletMixinEvents; + } +} declare module L { From 12fba7b62683f4ed7a78247756b69bdb06675ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20H=C3=A4berle?= Date: Sat, 2 Aug 2014 20:29:45 +0200 Subject: [PATCH 04/11] missing npost() function added --- q/Q.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/q/Q.d.ts b/q/Q.d.ts index 8e9696be5..617bf0140 100644 --- a/q/Q.d.ts +++ b/q/Q.d.ts @@ -214,6 +214,7 @@ declare module Q { export function nfapply(nodeFunction: Function, args: any[]): Promise; export function ninvoke(nodeModule: any, functionName: string, ...args: any[]): Promise; + export function npost(nodeModule: any, functionName: string, args: any[]): Promise; export function nsend(nodeModule: any, functionName: string, ...args: any[]): Promise; export function nmcall(nodeModule: any, functionName: string, ...args: any[]): Promise; From d9ada3076f601e05a8fb85eee418ced6ba545e26 Mon Sep 17 00:00:00 2001 From: satoru kimura Date: Sun, 3 Aug 2014 13:13:23 +0900 Subject: [PATCH 05/11] update to three.js r68. --- threejs/tests/canvas/canvas_geometry_cube.ts | 2 +- .../canvas/canvas_interactive_cubes_tween.ts | 1 + .../tests/canvas/canvas_lights_pointlights.ts | 43 +- threejs/tests/canvas/canvas_materials.ts | 19 +- threejs/tests/css3d/css3d_sprites.ts | 20 +- threejs/tests/math/test_unit_math.ts | 640 ++++++++++++---- .../webgl/webgl_animation_skinning_morph.ts | 297 ++++++++ threejs/tests/webgl/webgl_buffergeometry.ts | 18 +- threejs/tests/webgl/webgl_camera.ts | 2 +- ...webgl_interactive_raycasting_pointcloud.ts | 335 +++++++++ threejs/tests/webgl/webgl_lensflares.ts | 2 +- threejs/tests/webgl/webgl_materials.ts | 10 +- .../tests/webgl/webgl_particles_billboards.ts | 4 +- threejs/tests/webgl/webgl_postprocessing.ts | 2 - threejs/three-tests.ts | 3 + threejs/three.d.ts | 710 ++++++++++++------ 16 files changed, 1653 insertions(+), 455 deletions(-) create mode 100644 threejs/tests/webgl/webgl_animation_skinning_morph.ts create mode 100644 threejs/tests/webgl/webgl_interactive_raycasting_pointcloud.ts diff --git a/threejs/tests/canvas/canvas_geometry_cube.ts b/threejs/tests/canvas/canvas_geometry_cube.ts index 00c3b0426..bf5f9ae99 100644 --- a/threejs/tests/canvas/canvas_geometry_cube.ts +++ b/threejs/tests/canvas/canvas_geometry_cube.ts @@ -43,7 +43,7 @@ // Cube - var geometry = new THREE.CubeGeometry(200, 200, 200); + var geometry = new THREE.BoxGeometry(200, 200, 200); for (var i = 0; i < geometry.faces.length; i += 2) { diff --git a/threejs/tests/canvas/canvas_interactive_cubes_tween.ts b/threejs/tests/canvas/canvas_interactive_cubes_tween.ts index 8fbd7c2cf..865e07023 100644 --- a/threejs/tests/canvas/canvas_interactive_cubes_tween.ts +++ b/threejs/tests/canvas/canvas_interactive_cubes_tween.ts @@ -1,5 +1,6 @@ /// /// +/// // https://github.com/mrdoob/three.js/blob/master/examples/canvas_interactive_cubes_tween.html diff --git a/threejs/tests/canvas/canvas_lights_pointlights.ts b/threejs/tests/canvas/canvas_lights_pointlights.ts index 1b6a6663f..ad1a103d5 100644 --- a/threejs/tests/canvas/canvas_lights_pointlights.ts +++ b/threejs/tests/canvas/canvas_lights_pointlights.ts @@ -7,7 +7,6 @@ // ------- variable definitions that does not exist in the original code. These are for typescript. // ------- var camera, scene, renderer, - particle1, particle2, particle3, light1, light2, light3, loader, mesh; @@ -43,14 +42,14 @@ } - particle1 = new THREE.Sprite(new THREE.SpriteCanvasMaterial({ color: 0xff0040, program: program })); - scene.add(particle1); + var sprite = new THREE.Sprite( new THREE.SpriteCanvasMaterial( { color: 0xff0040, program: program } ) ); + light1.add( sprite ); - particle2 = new THREE.Sprite(new THREE.SpriteCanvasMaterial({ color: 0x0040ff, program: program })); - scene.add(particle2); + var sprite = new THREE.Sprite( new THREE.SpriteCanvasMaterial( { color: 0x0040ff, program: program } ) ); + light2.add( sprite ); - particle3 = new THREE.Sprite(new THREE.SpriteCanvasMaterial({ color: 0x80ff80, program: program })); - scene.add(particle3); + var sprite = new THREE.Sprite( new THREE.SpriteCanvasMaterial( { color: 0x80ff80, program: program } ) ); + light3.add( sprite ); loader = new THREE.JSONLoader(); loader.load('obj/WaltHeadLo.js', function (geometry) { @@ -94,29 +93,17 @@ if (mesh) mesh.rotation.y -= 0.01; - particle1.position.x = Math.sin(time * 0.7) * 30; - particle1.position.y = Math.cos(time * 0.5) * 40; - particle1.position.z = Math.cos(time * 0.3) * 30; + light1.position.x = Math.sin( time * 0.7 ) * 30; + light1.position.y = Math.cos( time * 0.5 ) * 40; + light1.position.z = Math.cos( time * 0.3 ) * 30; - light1.position.x = particle1.position.x; - light1.position.y = particle1.position.y; - light1.position.z = particle1.position.z; + light2.position.x = Math.cos( time * 0.3 ) * 30; + light2.position.y = Math.sin( time * 0.5 ) * 40; + light2.position.z = Math.sin( time * 0.7 ) * 30; - particle2.position.x = Math.cos(time * 0.3) * 30; - particle2.position.y = Math.sin(time * 0.5) * 40; - particle2.position.z = Math.sin(time * 0.7) * 30; - - light2.position.x = particle2.position.x; - light2.position.y = particle2.position.y; - light2.position.z = particle2.position.z; - - particle3.position.x = Math.sin(time * 0.7) * 30; - particle3.position.y = Math.cos(time * 0.3) * 40; - particle3.position.z = Math.sin(time * 0.5) * 30; - - light3.position.x = particle3.position.x; - light3.position.y = particle3.position.y; - light3.position.z = particle3.position.z; + light3.position.x = Math.sin( time * 0.7 ) * 30; + light3.position.y = Math.cos( time * 0.3 ) * 40; + light3.position.z = Math.sin( time * 0.5 ) * 30; renderer.render(scene, camera); diff --git a/threejs/tests/canvas/canvas_materials.ts b/threejs/tests/canvas/canvas_materials.ts index 23524098a..a39a780ca 100644 --- a/threejs/tests/canvas/canvas_materials.ts +++ b/threejs/tests/canvas/canvas_materials.ts @@ -11,7 +11,7 @@ var container, stats; var camera, scene, renderer, objects; - var particleLight, pointLight; + var pointLight; init(); animate(); @@ -103,10 +103,6 @@ } - particleLight = new THREE.Sprite(new THREE.SpriteCanvasMaterial({ color: 0xffffff, program: program })); - particleLight.scale.x = particleLight.scale.y = 8; - scene.add(particleLight); - // Lights scene.add(new THREE.AmbientLight(Math.random() * 0x202020)); @@ -121,6 +117,10 @@ pointLight = new THREE.PointLight(0xffffff, 1); scene.add(pointLight); + var sprite = new THREE.Sprite( new THREE.SpriteCanvasMaterial( { color: 0xffffff, program: program } ) ); + sprite.scale.set( 8, 8, 8 ); + pointLight.add( sprite ); + renderer = new THREE.CanvasRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); container.appendChild(renderer.domElement); @@ -198,13 +198,10 @@ } - particleLight.position.x = Math.sin(timer * 7) * 300; - particleLight.position.y = Math.cos(timer * 5) * 400; - particleLight.position.z = Math.cos(timer * 3) * 300; + pointLight.position.x = Math.sin( timer * 7 ) * 300; + pointLight.position.y = Math.cos( timer * 5 ) * 400; + pointLight.position.z = Math.cos( timer * 3 ) * 300; - pointLight.position.x = particleLight.position.x; - pointLight.position.y = particleLight.position.y; - pointLight.position.z = particleLight.position.z; renderer.render(scene, camera); diff --git a/threejs/tests/css3d/css3d_sprites.ts b/threejs/tests/css3d/css3d_sprites.ts index 20760735a..0b69a85bf 100644 --- a/threejs/tests/css3d/css3d_sprites.ts +++ b/threejs/tests/css3d/css3d_sprites.ts @@ -1,5 +1,6 @@ /// /// +/// // https://github.com/mrdoob/three.js/blob/master/examples/css3d_sprites.html @@ -26,23 +27,16 @@ scene = new THREE.Scene(); - var sprite = document.createElement('img'); - sprite.addEventListener('load', function (event) { + var image = document.createElement( 'img' ); + image.addEventListener( 'load', function ( event ) { - for (var i = 0, j = 0; i < particlesTotal; i++, j += 3) { + for ( var i = 0; i < particlesTotal; i ++ ) { - var canvas = document.createElement('canvas'); - canvas.width = sprite.width; - canvas.height = sprite.height; - - var context = canvas.getContext('2d'); - context.drawImage(sprite, 0, 0); - - var object = new THREE.CSS3DSprite(canvas); + var object = new THREE.CSS3DSprite( image.cloneNode() ); object.position.x = Math.random() * 4000 - 2000, object.position.y = Math.random() * 4000 - 2000, object.position.z = Math.random() * 4000 - 2000 - scene.add(object); + scene.add(object); objects.push(object); @@ -51,7 +45,7 @@ transition(); }, false); - sprite.src = 'textures/sprite.png'; + image.src = 'textures/sprite.png'; // Plane diff --git a/threejs/tests/math/test_unit_math.ts b/threejs/tests/math/test_unit_math.ts index f1c3818cc..a30e60dcd 100644 --- a/threejs/tests/math/test_unit_math.ts +++ b/threejs/tests/math/test_unit_math.ts @@ -6,6 +6,7 @@ // https://github.com/mrdoob/three.js/tree/master/test/unit/math ()=>{ + // -------------------------------------------- Constants var x = 2; var y = 3; var z = 4; @@ -25,8 +26,7 @@ var one3 = new THREE.Vector3( 1, 1, 1 ); var two3 = new THREE.Vector3( 2, 2, 2 ); - (QUnit.module)( "Box2" ); - + // -------------------------------------------- Box2 test( "constructor", function() { var a = new THREE.Box2(); ok( a.min.equals( posInf2 ), "Passed!" ); @@ -62,6 +62,21 @@ ok( a.max.equals( one2 ), "Passed!" ); }); + test( "setFromPoints", function() { + var a = new THREE.Box2(); + + a.setFromPoints( [ zero2, one2, two2 ] ); + ok( a.min.equals( zero2 ), "Passed!" ); + ok( a.max.equals( two2 ), "Passed!" ); + + a.setFromPoints( [ one2 ] ); + ok( a.min.equals( one2 ), "Passed!" ); + ok( a.max.equals( one2 ), "Passed!" ); + + a.setFromPoints( [] ); + ok( a.empty(), "Passed!" ); + }); + test( "empty/makeEmpty", function() { var a = new THREE.Box2(); @@ -197,21 +212,6 @@ ok( b.distanceToPoint( new THREE.Vector2( -2, -2 ) ) == Math.sqrt( 2 ), "Passed!" ); }); - test( "distanceToPoint", function() { - var a = new THREE.Box2( zero2.clone(), zero2.clone() ); - var b = new THREE.Box2( one2.clone().negate(), one2.clone() ); - - ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" ); - ok( a.distanceToPoint( new THREE.Vector2( 1, 1 ) ) == Math.sqrt( 2 ), "Passed!" ); - ok( a.distanceToPoint( new THREE.Vector2( -1, -1 ) ) == Math.sqrt( 2 ), "Passed!" ); - - ok( b.distanceToPoint( new THREE.Vector2( 2, 2 ) ) == Math.sqrt( 2 ), "Passed!" ); - ok( b.distanceToPoint( new THREE.Vector2( 1, 1 ) ) == 0, "Passed!" ); - ok( b.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" ); - ok( b.distanceToPoint( new THREE.Vector2( -1, -1 ) ) == 0, "Passed!" ); - ok( b.distanceToPoint( new THREE.Vector2( -2, -2 ) ) == Math.sqrt( 2 ), "Passed!" ); - }); - test( "isIntersectionBox", function() { var a = new THREE.Box2( zero2.clone(), zero2.clone() ); var b = new THREE.Box2( zero2.clone(), one2.clone() ); @@ -267,6 +267,7 @@ ok( b.clone().translate( one2.clone().negate() ).equals( d ), "Passed!" ); }); + // -------------------------------------------- Box3 test( "constructor", function() { var a = new THREE.Box3(); ok( a.min.equals( posInf3 ), "Passed!" ); @@ -302,6 +303,21 @@ ok( a.max.equals( one3 ), "Passed!" ); }); + test( "setFromPoints", function() { + var a = new THREE.Box3(); + + a.setFromPoints( [ zero3, one3, two3 ] ); + ok( a.min.equals( zero3 ), "Passed!" ); + ok( a.max.equals( two3 ), "Passed!" ); + + a.setFromPoints( [ one3 ] ); + ok( a.min.equals( one3 ), "Passed!" ); + ok( a.max.equals( one3 ), "Passed!" ); + + a.setFromPoints( [] ); + ok( a.empty(), "Passed!" ); + }); + test( "empty/makeEmpty", function() { var a = new THREE.Box3(); @@ -508,7 +524,7 @@ var compareBox = function ( a, b, threshold? ) { threshold = threshold || 0.0001; return ( a.min.distanceTo( b.min ) < threshold && - a.max.distanceTo( b.max ) < threshold ); + a.max.distanceTo( b.max ) < threshold ); }; test( "applyMatrix4", function() { @@ -538,11 +554,19 @@ ok( b.clone().translate( one3.clone().negate() ).equals( d ), "Passed!" ); }); + // -------------------------------------------- Color test( "constructor", function(){ var c = new THREE.Color(); ok( c.r, "Red: " + c.r ); ok( c.g, "Green: " + c.g ); - ok( c.b, "Blue: " + c.g ); + ok( c.b, "Blue: " + c.b ); + }); + + test( "rgb constructor", function(){ + var c = new THREE.Color( 1, 1, 1 ); + ok( c.r == 1, "Passed" ); + ok( c.g == 1, "Passed" ); + ok( c.b == 1, "Passed" ); }); test( "copyHex", function(){ @@ -560,48 +584,48 @@ }); test( "setRGB", function(){ - var c = new THREE.Color() - c.setRGB(255, 2, 1); - ok( c.r == 255, "Red: " + c.r ); - ok( c.g == 2, "Green: " + c.g ); - ok( c.b == 1, "Blue: " + c.b ); + var c = new THREE.Color(); + c.setRGB(1, 0.2, 0.1); + ok( c.r == 1, "Red: " + c.r ); + ok( c.g == 0.2, "Green: " + c.g ); + ok( c.b == 0.1, "Blue: " + c.b ); }); test( "copyGammaToLinear", function(){ var c = new THREE.Color(); var c2 = new THREE.Color(); - c2.setRGB(2, 4, 8) - c.copyGammaToLinear(c2) - ok( c.r == 4, "Red c: " + c.r + " Red c2: " + c2.r); - ok( c.g == 16, "Green c: " + c.g + " Green c2: " + c2.g); - ok( c.b == 64, "Blue c: " + c.b + " Blue c2: " + c2.b); + c2.setRGB(0.3, 0.5, 0.9); + c.copyGammaToLinear(c2); + ok( c.r == 0.09, "Red c: " + c.r + " Red c2: " + c2.r); + ok( c.g == 0.25, "Green c: " + c.g + " Green c2: " + c2.g); + ok( c.b == 0.81, "Blue c: " + c.b + " Blue c2: " + c2.b); }); test( "copyLinearToGamma", function(){ var c = new THREE.Color(); var c2 = new THREE.Color(); - c2.setRGB(4, 9, 16) - c.copyLinearToGamma(c2) - ok( c.r == 2, "Red c: " + c.r + " Red c2: " + c2.r); - ok( c.g == 3, "Green c: " + c.g + " Green c2: " + c2.g); - ok( c.b == 4, "Blue c: " + c.b + " Blue c2: " + c2.b); + c2.setRGB(0.09, 0.25, 0.81); + c.copyLinearToGamma(c2); + ok( c.r == 0.3, "Red c: " + c.r + " Red c2: " + c2.r); + ok( c.g == 0.5, "Green c: " + c.g + " Green c2: " + c2.g); + ok( c.b == 0.9, "Blue c: " + c.b + " Blue c2: " + c2.b); }); test( "convertGammaToLinear", function(){ var c = new THREE.Color(); - c.setRGB(2, 4, 8) - c.convertGammaToLinear() - ok( c.r == 4, "Red: " + c.r ); - ok( c.g == 16, "Green: " + c.g ); - ok( c.b == 64, "Blue: " + c.b ); + c.setRGB(0.3, 0.5, 0.9); + c.convertGammaToLinear(); + ok( c.r == 0.09, "Red: " + c.r ); + ok( c.g == 0.25, "Green: " + c.g ); + ok( c.b == 0.81, "Blue: " + c.b ); }); test( "convertLinearToGamma", function(){ var c = new THREE.Color(); - c.setRGB(4, 9, 16) - c.convertLinearToGamma() + c.setRGB(4, 9, 16); + c.convertLinearToGamma(); ok( c.r == 2, "Red: " + c.r ); ok( c.g == 3, "Green: " + c.g ); ok( c.b == 4, "Blue: " + c.b ); @@ -611,8 +635,8 @@ var c = new THREE.Color(); c.set(0xFF0000); ok( c.r == 1, "Red: " + c.r ); - ok( c.g == 0, "Green: " + c.g ); - ok( c.b == 0, "Blue: " + c.b ); + ok( c.g === 0, "Green: " + c.g ); + ok( c.b === 0, "Blue: " + c.b ); }); @@ -633,11 +657,11 @@ var c = new THREE.Color(); var c2 = new THREE.Color(); c.setRGB(0, 0, 0); - c.lerp(c2, 2); - ok( c.r == 2, "Red: " + c.r ); - ok( c.g == 2, "Green: " + c.g ); - ok( c.b == 2, "Blue: " + c.b ); - + c.lerp(c2, 0.2); + ok( c.r == 0.2, "Red: " + c.r ); + ok( c.g == 0.2, "Green: " + c.g ); + ok( c.b == 0.2, "Blue: " + c.b ); + }); @@ -645,8 +669,16 @@ var c = new THREE.Color(); c.setStyle('rgb(255,0,0)'); ok( c.r == 1, "Red: " + c.r ); - ok( c.g == 0, "Green: " + c.g ); - ok( c.b == 0, "Blue: " + c.b ); + ok( c.g === 0, "Green: " + c.g ); + ok( c.b === 0, "Blue: " + c.b ); + }); + + test( "setStyleRGBRedWithSpaces", function(){ + var c = new THREE.Color(); + c.setStyle('rgb(255, 0, 0)'); + ok( c.r == 1, "Red: " + c.r ); + ok( c.g === 0, "Green: " + c.g ); + ok( c.b === 0, "Blue: " + c.b ); }); test( "setStyleRGBPercent", function(){ @@ -657,6 +689,14 @@ ok( c.b == 0.1, "Blue: " + c.b ); }); + test( "setStyleRGBPercentWithSpaces", function(){ + var c = new THREE.Color(); + c.setStyle('rgb(100%,50%,10%)'); + ok( c.r == 1, "Red: " + c.r ); + ok( c.g == 0.5, "Green: " + c.g ); + ok( c.b == 0.1, "Blue: " + c.b ); + }); + test( "setStyleHexSkyBlue", function(){ var c = new THREE.Color(); c.setStyle('#87CEEB'); @@ -706,10 +746,7 @@ ok( hsl.h == 0.5, "hue: " + hsl.h ); ok( hsl.s == 1.0, "saturation: " + hsl.s ); - - - //ok( (Math.round(parseFloat(hsl.l)*100)/100) == 0.75, "lightness: " + hsl.l ); - ok( (Math.round(hsl.l*100)/100) == 0.75, "lightness: " + hsl.l ); + ok( (Math.round(parseFloat(hsl.l.toString())*100)/100) == 0.75, "lightness: " + hsl.l ); }); test( "setHSL", function () { @@ -722,6 +759,98 @@ ok( hsl.l == 0.25, "lightness: " + hsl.l ); }); + // -------------------------------------------- Euler + + var eulerZero = new THREE.Euler( 0, 0, 0, "XYZ" ); + var eulerAxyz = new THREE.Euler( 1, 0, 0, "XYZ" ); + var eulerAzyx = new THREE.Euler( 0, 1, 0, "ZYX" ); + + var matrixEquals4 = function( a, b ) { + var tolerance = 0.0001; + if( a.elements.length != b.elements.length ) { + return false; + } + for( var i = 0, il = a.elements.length; i < il; i ++ ) { + var delta = a.elements[i] - b.elements[i]; + if( delta > tolerance ) { + return false; + } + } + return true; + }; + + test( "constructor/equals", function() { + var a = new THREE.Euler(); + ok( a.equals( eulerZero ), "Passed!" ); + ok( ! a.equals( eulerAxyz ), "Passed!" ); + ok( ! a.equals( eulerAzyx ), "Passed!" ); + }); + + test( "clone/copy/equals", function() { + var a = eulerAxyz.clone(); + ok( a.equals( eulerAxyz ), "Passed!" ); + ok( ! a.equals( eulerZero ), "Passed!" ); + ok( ! a.equals( eulerAzyx ), "Passed!" ); + + a.copy( eulerAzyx ); + ok( a.equals( eulerAzyx ), "Passed!" ); + ok( ! a.equals( eulerAxyz ), "Passed!" ); + ok( ! a.equals( eulerZero ), "Passed!" ); + + }); + + test( "set", function() { + var a = new THREE.Euler(); + + a.set( 0, 1, 0, "ZYX" ); + ok( a.equals( eulerAzyx ), "Passed!" ); + ok( ! a.equals( eulerAxyz ), "Passed!" ); + ok( ! a.equals( eulerZero ), "Passed!" ); + }); + + test( "Quaternion.setFromEuler/Euler.fromQuaternion", function() { + var testValues = [ eulerZero, eulerAxyz, eulerAzyx ]; + for( var i = 0; i < testValues.length; i ++ ) { + var v = testValues[i]; + var q = new THREE.Quaternion().setFromEuler( v ); + + var v2 = new THREE.Euler().setFromQuaternion( q, v.order ); + var q2 = new THREE.Quaternion().setFromEuler( v2 ); + ok( q.equals( q2 ), "Passed!" ); + } + }); + + + test( "Matrix4.setFromEuler/Euler.fromRotationMatrix", function() { + var testValues = [ eulerZero, eulerAxyz, eulerAzyx ]; + for( var i = 0; i < testValues.length; i ++ ) { + var v = testValues[i]; + var m = new THREE.Matrix4().makeRotationFromEuler( v ); + + var v2 = new THREE.Euler().setFromRotationMatrix( m, v.order ); + var m2 = new THREE.Matrix4().makeRotationFromEuler( v2 ); + ok( matrixEquals4( m, m2 ), "Passed!" ); + } + }); + + test( "reorder", function() { + var testValues = [ eulerZero, eulerAxyz, eulerAzyx ]; + for( var i = 0; i < testValues.length; i ++ ) { + var v = testValues[i]; + var q = new THREE.Quaternion().setFromEuler( v ); + + v.reorder( 'YZX' ); + var q2 = new THREE.Quaternion().setFromEuler( v ); + ok( q.equals( q2 ), "Passed!" ); + + v.reorder( 'ZXY' ); + var q3 = new THREE.Quaternion().setFromEuler( v ); + ok( q.equals( q3 ), "Passed!" ); + } + }); + + // -------------------------------------------- Frustum + var unit3 = new THREE.Vector3( 1, 0, 0 ); var planeEquals = function ( a, b, tolerance ) { @@ -873,6 +1002,7 @@ ok( b.planes[0].equals( p0 ), "Passed!" ); }); + // -------------------------------------------- Line3 test( "constructor/equals", function() { var a = new THREE.Line3(); @@ -925,7 +1055,6 @@ // nearby the ray ok( a.closestPointToPointParameter( zero3.clone(), false ) == -1, "Passed!" ); var b2 = a.closestPointToPoint( zero3.clone(), false ); - console.log( b2 ); ok( b2.distanceTo( new THREE.Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" ); // nearby the ray @@ -939,7 +1068,7 @@ ok( c.distanceTo( one3.clone() ) < 0.0001, "Passed!" ); }); - + // -------------------------------------------- Matrix3 var matrixEquals3 = function( a, b, tolerance? ) { tolerance = tolerance || 0.0001; @@ -1081,15 +1210,13 @@ var identity = new THREE.Matrix4(); var a = new THREE.Matrix4(); var b = new THREE.Matrix3( 0, 0, 0, 0, 0, 0, 0, 0, 0 ); - - //var c = new THREE.Matrix4( 0, 0, 0, 0, 0, 0, 0, 0, 0 ); - var c = new THREE.Matrix4( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); + var c = new THREE.Matrix4( 0, 0, 0, 0, 0, 0, 0, 0, 0 ); ok( ! matrixEquals3( a, b ), "Passed!" ); b.getInverse( a, false ); ok( matrixEquals3( b, new THREE.Matrix3() ), "Passed!" ); - try { + try { b.getInverse( c, true ); ok( false, "Passed!" ); // should never get here. } @@ -1106,7 +1233,7 @@ new THREE.Matrix4().makeRotationZ( -0.3 ), new THREE.Matrix4().makeScale( 1, 2, 3 ), new THREE.Matrix4().makeScale( 1/8, 1/2, 1/3 ) - ]; + ]; for( var i = 0, il = testMatrices.length; i < il; i ++ ) { var m = testMatrices[i]; @@ -1131,9 +1258,9 @@ b = new THREE.Matrix3( 0, 1, 2, 3, 4, 5, 6, 7, 8 ); var c = b.clone().transpose(); - ok( ! matrixEquals3( b, c ), "Passed!" ); + ok( ! matrixEquals3( b, c ), "Passed!" ); c.transpose(); - ok( matrixEquals3( b, c ), "Passed!" ); + ok( matrixEquals3( b, c ), "Passed!" ); }); test( "clone", function() { @@ -1147,8 +1274,10 @@ ok( ! matrixEquals3( a, b ), "Passed!" ); }); - var matrixEquals4 = function( a, b, tolerance? ) { - tolerance = tolerance || 0.0001; + // -------------------------------------------- Matrix4 + + var matrixEquals4 = function (a, b) { + var tolerance = 0.0001; if( a.elements.length != b.elements.length ) { return false; } @@ -1310,7 +1439,7 @@ b.getInverse( a, false ); ok( matrixEquals4( b, new THREE.Matrix4() ), "Passed!" ); - try { + try { b.getInverse( c, true ); ok( false, "Passed!" ); // should never get here. } @@ -1330,15 +1459,21 @@ new THREE.Matrix4().makeFrustum( -1, 1, -1, 1, 1, 1000 ), new THREE.Matrix4().makeFrustum( -16, 16, -9, 9, 0.1, 10000 ), new THREE.Matrix4().makeTranslation( 1, 2, 3 ) - ]; + ]; for( var i = 0, il = testMatrices.length; i < il; i ++ ) { var m = testMatrices[i]; var mInverse = new THREE.Matrix4().getInverse( m ); + var mSelfInverse = m.clone(); + mSelfInverse.getInverse( mSelfInverse ); + + + // self-inverse should the same as inverse + ok( matrixEquals4( mSelfInverse, mInverse ), "Passed!" ); // the determinant of the inverse should be the reciprocal - ok( Math.abs( m.determinant() * mInverse.determinant() - 1 ) < 0.0001, "Passed!" ); + ok( Math.abs( m.determinant() * mInverse.determinant() - 1 ) < 0.0001, "Passed!" ); var mProduct = new THREE.Matrix4().multiplyMatrices( m, mInverse ); @@ -1355,9 +1490,9 @@ b = new THREE.Matrix4( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ); var c = b.clone().transpose(); - ok( ! matrixEquals4( b, c ), "Passed!" ); + ok( ! matrixEquals4( b, c ), "Passed!" ); c.transpose(); - ok( matrixEquals4( b, c ), "Passed!" ); + ok( matrixEquals4( b, c ), "Passed!" ); }); test( "clone", function() { @@ -1372,10 +1507,75 @@ }); + test( "compose/decompose", function() { + var tValues = [ + new THREE.Vector3(), + new THREE.Vector3( 3, 0, 0 ), + new THREE.Vector3( 0, 4, 0 ), + new THREE.Vector3( 0, 0, 5 ), + new THREE.Vector3( -6, 0, 0 ), + new THREE.Vector3( 0, -7, 0 ), + new THREE.Vector3( 0, 0, -8 ), + new THREE.Vector3( -2, 5, -9 ), + new THREE.Vector3( -2, -5, -9 ) + ]; + + var sValues = [ + new THREE.Vector3( 1, 1, 1 ), + new THREE.Vector3( 2, 2, 2 ), + new THREE.Vector3( 1, -1, 1 ), + new THREE.Vector3( -1, 1, 1 ), + new THREE.Vector3( 1, 1, -1 ), + new THREE.Vector3( 2, -2, 1 ), + new THREE.Vector3( -1, 2, -2 ), + new THREE.Vector3( -1, -1, -1 ), + new THREE.Vector3( -2, -2, -2 ) + ]; + + var rValues = [ + new THREE.Quaternion(), + new THREE.Quaternion().setFromEuler( new THREE.Euler( 1, 1, 0 ) ), + new THREE.Quaternion().setFromEuler( new THREE.Euler( 1, -1, 1 ) ), + new THREE.Quaternion( 0, 0.9238795292366128, 0, 0.38268342717215614 ) + ]; + + + for( var ti = 0; ti < tValues.length; ti ++ ) { + for( var si = 0; si < sValues.length; si ++ ) { + for( var ri = 0; ri < rValues.length; ri ++ ) { + var t = tValues[ti]; + var s = sValues[si]; + var r = rValues[ri]; + + var m = new THREE.Matrix4().compose( t, r, s ); + var t2 = new THREE.Vector3(); + var r2 = new THREE.Quaternion(); + var s2 = new THREE.Vector3(); + + m.decompose( t2, r2, s2 ); + + var m2 = new THREE.Matrix4().compose( t2, r2, s2 ); + + var matrixIsSame = matrixEquals4( m, m2 ); + /* debug code + if( ! matrixIsSame ) { + console.log( t, s, r ); + console.log( t2, s2, r2 ); + console.log( m, m2 ); + }*/ + ok( matrixEquals4( m, m2 ), "Passed!" ); + + } + } + } + }); + + // -------------------------------------------- Plane + var comparePlane = function ( a, b, threshold? ) { threshold = threshold || 0.0001; return ( a.normal.distanceTo( b.normal ) < threshold && - Math.abs( a.constant - b.constant ) < threshold ); + Math.abs( a.constant - b.constant ) < threshold ); }; @@ -1564,6 +1764,8 @@ ok( comparePlane( a.clone().applyMatrix4( m ), a.clone().translate( new THREE.Vector3( 1, 1, 1 ) ) ), "Passed!" ); }); + // -------------------------------------------- Quaternion + var orders = [ 'XYZ', 'YXZ', 'ZXY', 'ZYX', 'YZX', 'XZY' ]; var eulerAngles = new THREE.Euler( 0.1, -0.3, 0.25 ); @@ -1658,12 +1860,9 @@ // ensure euler conversion to/from Quaternion matches. for( var i = 0; i < orders.length; i ++ ) { for( var j = 0; j < angles.length; j ++ ) { - var eulers2 = new THREE.Euler().setFromQuaternion( - new THREE.Quaternion().setFromEuler(new THREE.Euler(angles[j].x, angles[j].y, angles[j].z, orders[i])), - orders[i] - ); - var v = new THREE.Vector3().applyEuler(eulers2); - ok( v.distanceTo( angles[j] ) < 0.001, "Passed!" ); + var eulers2 = new THREE.Euler().setFromQuaternion( new THREE.Quaternion().setFromEuler( new THREE.Euler( angles[j].x, angles[j].y, angles[j].z, orders[i] ) ), orders[i] ); + var newAngle = new THREE.Vector3( eulers2.x, eulers2.y, eulers2.z ); + ok( newAngle.distanceTo( angles[j] ) < 0.001, "Passed!" ); } } @@ -1673,7 +1872,7 @@ // ensure euler conversion for Quaternion matches that of Matrix4 for( var i = 0; i < orders.length; i ++ ) { - var q = new THREE.Quaternion().setFromEuler( eulerAngles ); + var q = new THREE.Quaternion().setFromEuler( eulerAngles, false ); var m = new THREE.Matrix4().makeRotationFromEuler( eulerAngles ); var q2 = new THREE.Quaternion().setFromRotationMatrix( m ); @@ -1716,17 +1915,17 @@ test( "multiplyQuaternions/multiply", function() { - var angles = [ new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ) ]; + var angles = [ new THREE.Euler( 1, 0, 0 ), new THREE.Euler( 0, 1, 0 ), new THREE.Euler( 0, 0, 1 ) ]; - var q1 = new THREE.Quaternion().setFromEuler( new THREE.Euler(angles[0].x, angles[0].y, angles[0].z) ); - var q2 = new THREE.Quaternion().setFromEuler( new THREE.Euler(angles[1].x, angles[1].y, angles[1].z) ); - var q3 = new THREE.Quaternion().setFromEuler( new THREE.Euler(angles[2].x, angles[2].y, angles[2].z) ); + var q1 = new THREE.Quaternion().setFromEuler( angles[0], false ); + var q2 = new THREE.Quaternion().setFromEuler( angles[1], false ); + var q3 = new THREE.Quaternion().setFromEuler( angles[2], false ); var q = new THREE.Quaternion().multiplyQuaternions( q1, q2 ).multiply( q3 ); - var m1 = new THREE.Matrix4().makeRotationFromEuler( new THREE.Euler(angles[0].x, angles[0].y, angles[0].z) ); - var m2 = new THREE.Matrix4().makeRotationFromEuler( new THREE.Euler(angles[1].x, angles[1].y, angles[1].z) ); - var m3 = new THREE.Matrix4().makeRotationFromEuler( new THREE.Euler(angles[2].x, angles[2].y, angles[2].z) ); + var m1 = new THREE.Matrix4().makeRotationFromEuler( angles[0] ); + var m2 = new THREE.Matrix4().makeRotationFromEuler( angles[1] ); + var m3 = new THREE.Matrix4().makeRotationFromEuler( angles[2] ); var m = new THREE.Matrix4().multiplyMatrices( m1, m2 ).multiply( m3 ); @@ -1737,13 +1936,13 @@ test( "multiplyVector3", function() { - var angles = [ new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ) ]; + var angles = [ new THREE.Euler( 1, 0, 0 ), new THREE.Euler( 0, 1, 0 ), new THREE.Euler( 0, 0, 1 ) ]; // ensure euler conversion for Quaternion matches that of Matrix4 for( var i = 0; i < orders.length; i ++ ) { for( var j = 0; j < angles.length; j ++ ) { - var q = new THREE.Quaternion().setFromEuler( new THREE.Euler(angles[j].x, angles[j].y, angles[j].z, orders[i]) ); - var m = new THREE.Matrix4().makeRotationFromEuler( new THREE.Euler(angles[j].x, angles[j].y, angles[j].z, orders[i]) ); + var q = new THREE.Quaternion().setFromEuler( angles[j], false ); + var m = new THREE.Matrix4().makeRotationFromEuler( angles[j] ); var v0 = new THREE.Vector3(1, 0, 0); var qv = v0.clone().applyQuaternion( q ); @@ -1773,6 +1972,7 @@ ok( b.equals( a ), "Passed!" ); }); + // -------------------------------------------- Ray test( "constructor/equals", function() { var a = new THREE.Ray(); @@ -1834,25 +2034,33 @@ test( "closestPointToPoint", function() { var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) ); - // nearby the ray + // behind the ray var b = a.closestPointToPoint( zero3 ); - ok( b.equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" ); + ok( b.equals( one3 ), "Passed!" ); + + // front of the ray + var c = a.closestPointToPoint( new THREE.Vector3( 0, 0, 50 ) ); + ok( c.equals( new THREE.Vector3( 1, 1, 50 ) ), "Passed!" ); // exactly on the ray - var c = a.closestPointToPoint( one3 ); - ok( c.equals( one3 ), "Passed!" ); + var d = a.closestPointToPoint( one3 ); + ok( d.equals( one3 ), "Passed!" ); }); test( "distanceToPoint", function() { var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) ); - // nearby the ray + // behind the ray var b = a.distanceToPoint( zero3 ); - ok( b == Math.sqrt( 2 ), "Passed!" ); + ok( b === Math.sqrt( 3 ), "Passed!" ); + + // front of the ray + var c = a.distanceToPoint( new THREE.Vector3( 0, 0, 50 ) ); + ok( c === Math.sqrt( 2 ), "Passed!" ); // exactly on the ray - var c = a.distanceToPoint( one3 ); - ok( c == 0, "Passed!" ); + var d = a.distanceToPoint( one3 ); + ok( d === 0, "Passed!" ); }); test( "isIntersectionSphere", function() { @@ -1864,16 +2072,75 @@ var f = new THREE.Sphere( two3, 1 ); ok( ! a.isIntersectionSphere( b ), "Passed!" ); - ok( a.isIntersectionSphere( c ), "Passed!" ); + ok( ! a.isIntersectionSphere( c ), "Passed!" ); ok( a.isIntersectionSphere( d ), "Passed!" ); ok( ! a.isIntersectionSphere( e ), "Passed!" ); ok( ! a.isIntersectionSphere( f ), "Passed!" ); }); + test( "intersectSphere", function() { + + var TOL = 0.0001; + + // ray a0 origin located at ( 0, 0, 0 ) and points outward in negative-z direction + var a0 = new THREE.Ray( zero3.clone(), new THREE.Vector3( 0, 0, -1 ) ); + // ray a1 origin located at ( 1, 1, 1 ) and points left in negative-x direction + var a1 = new THREE.Ray( one3.clone(), new THREE.Vector3( -1, 0, 0 ) ); + + // sphere (radius of 2) located behind ray a0, should result in null + var b = new THREE.Sphere( new THREE.Vector3( 0, 0, 3 ), 2 ); + ok( a0.intersectSphere( b ) === null, "Passed!" ); + + // sphere (radius of 2) located in front of, but too far right of ray a0, should result in null + var b = new THREE.Sphere( new THREE.Vector3( 3, 0, -1 ), 2 ); + ok( a0.intersectSphere( b ) === null, "Passed!" ); + + // sphere (radius of 2) located below ray a1, should result in null + var b = new THREE.Sphere( new THREE.Vector3( 1, -2, 1 ), 2 ); + ok( a1.intersectSphere( b ) === null, "Passed!" ); + + // sphere (radius of 1) located to the left of ray a1, should result in intersection at 0, 1, 1 + var b = new THREE.Sphere( new THREE.Vector3( -1, 1, 1 ), 1 ); + ok( a1.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 1, 1 ) ) < TOL, "Passed!" ); + + // sphere (radius of 1) located in front of ray a0, should result in intersection at 0, 0, -1 + var b = new THREE.Sphere( new THREE.Vector3( 0, 0, -2 ), 1 ); + ok( a0.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 0, -1 ) ) < TOL, "Passed!" ); + + // sphere (radius of 2) located in front & right of ray a0, should result in intersection at 0, 0, -1, or left-most edge of sphere + var b = new THREE.Sphere( new THREE.Vector3( 2, 0, -1 ), 2 ); + ok( a0.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 0, -1 ) ) < TOL, "Passed!" ); + + // same situation as above, but move the sphere a fraction more to the right, and ray a0 should now just miss + var b = new THREE.Sphere( new THREE.Vector3( 2.01, 0, -1 ), 2 ); + ok( a0.intersectSphere( b ) === null, "Passed!" ); + + // following tests are for situations where the ray origin is inside the sphere + + // sphere (radius of 1) center located at ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 1, + // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -1 + // thus keeping the intersection point always in front of the ray. + var b = new THREE.Sphere( zero3.clone(), 1 ); + ok( a0.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 0, -1 ) ) < TOL, "Passed!" ); + + // sphere (radius of 4) center located behind ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 5, + // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -3 + // thus keeping the intersection point always in front of the ray. + var b = new THREE.Sphere( new THREE.Vector3( 0, 0, 1 ), 4 ); + ok( a0.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 0, -3 ) ) < TOL, "Passed!" ); + + // sphere (radius of 4) center located in front of ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 3, + // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -5 + // thus keeping the intersection point always in front of the ray. + var b = new THREE.Sphere( new THREE.Vector3( 0, 0, -1 ), 4 ); + ok( a0.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 0, -5 ) ) < TOL, "Passed!" ); + + }); + test( "isIntersectionPlane", function() { var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) ); - // parallel plane behind + // parallel plane in front of the ray var b = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), one3.clone().sub( new THREE.Vector3( 0, 0, -1 ) ) ); ok( a.isIntersectionPlane( b ), "Passed!" ); @@ -1881,9 +2148,9 @@ var c = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), one3.clone().sub( new THREE.Vector3( 0, 0, 0 ) ) ); ok( a.isIntersectionPlane( c ), "Passed!" ); - // parallel plane infront + // parallel plane behind the ray var d = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), one3.clone().sub( new THREE.Vector3( 0, 0, 1 ) ) ); - ok( a.isIntersectionPlane( d ), "Passed!" ); + ok( ! a.isIntersectionPlane( d ), "Passed!" ); // perpendical ray that overlaps exactly var e = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 1, 0, 0 ), one3 ); @@ -1899,15 +2166,15 @@ // parallel plane behind var b = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 1, 1, -1 ) ); - ok( a.intersectPlane( b ).equals( new THREE.Vector3( 1, 1, -1 ) ), "Passed!" ); + ok( a.intersectPlane( b ) === null, "Passed!" ); // parallel plane coincident with origin var c = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 1, 1, 0 ) ); - ok( a.intersectPlane( c ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" ); + ok( a.intersectPlane( c ) === null, "Passed!" ); // parallel plane infront var d = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 1, 1, 1 ) ); - ok( a.intersectPlane( d ).equals( new THREE.Vector3( 1, 1, 1 ) ), "Passed!" ); + ok( a.intersectPlane( d ).equals( a.origin ), "Passed!" ); // perpendical ray that overlaps exactly var e = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 1, 0, 0 ), one3 ); @@ -1915,21 +2182,21 @@ // perpendical ray that doesn't overlap var f = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 1, 0, 0 ), zero3 ); - ok( a.intersectPlane( f ) === undefined, "Passed!" ); + ok( a.intersectPlane( f ) === null, "Passed!" ); }); test( "applyMatrix4", function() { var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) ); - var m = new THREE.Matrix4().identity(); + var m = new THREE.Matrix4(); ok( a.clone().applyMatrix4( m ).equals( a ), "Passed!" ); a = new THREE.Ray( zero3.clone(), new THREE.Vector3( 0, 0, 1 ) ); - m.makeRotationAxis( new THREE.Vector3( 0, 0, 1 ), Math.PI ); + m.makeRotationZ( Math.PI ); ok( a.clone().applyMatrix4( m ).equals( a ), "Passed!" ); - m.identity().makeRotationX( Math.PI ); + m.makeRotationX( Math.PI ); var b = a.clone(); b.direction.negate(); var a2 = a.clone().applyMatrix4( m ); @@ -1944,6 +2211,80 @@ }); + test( "distanceSqToSegment", function() { + var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) ); + var ptOnLine = new THREE.Vector3(); + var ptOnSegment = new THREE.Vector3(); + + //segment in front of the ray + var v0 = new THREE.Vector3( 3, 5, 50 ); + var v1 = new THREE.Vector3( 50, 50, 50 ); // just a far away point + var distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment ); + + ok( ptOnSegment.distanceTo( v0 ) < 0.0001, "Passed!" ); + ok( ptOnLine.distanceTo( new THREE.Vector3(1, 1, 50) ) < 0.0001, "Passed!" ); + // ((3-1) * (3-1) + (5-1) * (5-1) = 4 + 16 = 20 + ok( Math.abs( distSqr - 20 ) < 0.0001, "Passed!" ); + + //segment behind the ray + v0 = new THREE.Vector3( -50, -50, -50 ); // just a far away point + v1 = new THREE.Vector3( -3, -5, -4 ); + distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment ); + + ok( ptOnSegment.distanceTo( v1 ) < 0.0001, "Passed!" ); + ok( ptOnLine.distanceTo( one3 ) < 0.0001, "Passed!" ); + // ((-3-1) * (-3-1) + (-5-1) * (-5-1) + (-4-1) + (-4-1) = 16 + 36 + 25 = 77 + ok( Math.abs( distSqr - 77 ) < 0.0001, "Passed!" ); + + //exact intersection between the ray and the segment + v0 = new THREE.Vector3( -50, -50, -50 ); + v1 = new THREE.Vector3( 50, 50, 50 ); + distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment ); + + ok( ptOnSegment.distanceTo( one3 ) < 0.0001, "Passed!" ); + ok( ptOnLine.distanceTo( one3 ) < 0.0001, "Passed!" ); + ok( distSqr < 0.0001, "Passed!" ); + }); + + test( "intersectBox", function() { + + var TOL = 0.0001; + + var box = new THREE.Box3( new THREE.Vector3( -1, -1, -1 ), new THREE.Vector3( 1, 1, 1 ) ); + + var a = new THREE.Ray( new THREE.Vector3( -2, 0, 0 ), new THREE.Vector3( 1, 0, 0) ); + //ray should intersect box at -1,0,0 + ok( a.isIntersectionBox(box) === true, "Passed!" ); + ok( a.intersectBox(box).distanceTo( new THREE.Vector3( -1, 0, 0 ) ) < TOL, "Passed!" ); + + var b = new THREE.Ray( new THREE.Vector3( -2, 0, 0 ), new THREE.Vector3( -1, 0, 0) ); + //ray is point away from box, it should not intersect + ok( b.isIntersectionBox(box) === false, "Passed!" ); + ok( b.intersectBox(box) === null, "Passed!" ); + + var c = new THREE.Ray( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 1, 0, 0) ); + // ray is inside box, should return exit point + ok( c.isIntersectionBox(box) === true, "Passed!" ); + ok( c.intersectBox(box).distanceTo( new THREE.Vector3( 1, 0, 0 ) ) < TOL, "Passed!" ); + + var d = new THREE.Ray( new THREE.Vector3( 0, 2, 1 ), new THREE.Vector3( 0, -1, -1).normalize() ); + //tilted ray should intersect box at 0,1,0 + ok( d.isIntersectionBox(box) === true, "Passed!" ); + ok( d.intersectBox(box).distanceTo( new THREE.Vector3( 0, 1, 0 ) ) < TOL, "Passed!" ); + + var e = new THREE.Ray( new THREE.Vector3( 1, -2, 1 ), new THREE.Vector3( 0, 1, 0).normalize() ); + //handle case where ray is coplanar with one of the boxes side - box in front of ray + ok( e.isIntersectionBox(box) === true, "Passed!" ); + ok( e.intersectBox(box).distanceTo( new THREE.Vector3( 1, -1, 1 ) ) < TOL, "Passed!" ); + + var f = new THREE.Ray( new THREE.Vector3( 1, -2, 0 ), new THREE.Vector3( 0, -1, 0).normalize() ); + //handle case where ray is coplanar with one of the boxes side - box behind ray + ok( f.isIntersectionBox(box) === false, "Passed!" ); + ok( f.intersectBox(box) == null, "Passed!" ); + + }); + + // -------------------------------------------- Sphere test( "constructor", function() { var a = new THREE.Sphere(); ok( a.center.equals( zero3 ), "Passed!" ); @@ -2040,6 +2381,8 @@ ok( a.center.equals( zero3 ), "Passed!" ); }); + // -------------------------------------------- Triangle + test( "constructor", function() { var a = new THREE.Triangle(); ok( a.a.equals( zero3 ), "Passed!" ); @@ -2195,7 +2538,7 @@ ok( ! a.containsPoint( new THREE.Vector3( -1, -1, -1 ) ), "Passed!" ); }); - + // -------------------------------------------- Vector2 test( "constructor", function() { var a = new THREE.Vector2(); ok( a.x == 0, "Passed!" ); @@ -2316,6 +2659,32 @@ c.clamp( b, a ); ok( c.x == -x, "Passed!" ); ok( c.y == y, "Passed!" ); + + c.set(-2*x, 2*x); + c.clampScalar( -x, x ); + equal( c.x, -x, "scalar clamp x" ); + equal( c.y, x, "scalar clamp y" ); + }); + + test( "rounding", function() { + deepEqual( new THREE.Vector2( -0.1, 0.1 ).floor(), new THREE.Vector2( -1, 0 ), "floor .1" ); + deepEqual( new THREE.Vector2( -0.5, 0.5 ).floor(), new THREE.Vector2( -1, 0 ), "floor .5" ); + deepEqual( new THREE.Vector2( -0.9, 0.9 ).floor(), new THREE.Vector2( -1, 0 ), "floor .9" ); + + deepEqual( new THREE.Vector2( -0.1, 0.1 ).ceil(), new THREE.Vector2( 0, 1 ), "ceil .1" ); + deepEqual( new THREE.Vector2( -0.5, 0.5 ).ceil(), new THREE.Vector2( 0, 1 ), "ceil .5" ); + deepEqual( new THREE.Vector2( -0.9, 0.9 ).ceil(), new THREE.Vector2( 0, 1 ), "ceil .9" ); + + deepEqual( new THREE.Vector2( -0.1, 0.1 ).round(), new THREE.Vector2( 0, 0 ), "round .1" ); + deepEqual( new THREE.Vector2( -0.5, 0.5 ).round(), new THREE.Vector2( 0, 1 ), "round .5" ); + deepEqual( new THREE.Vector2( -0.9, 0.9 ).round(), new THREE.Vector2( -1, 1 ), "round .9" ); + + deepEqual( new THREE.Vector2( -0.1, 0.1 ).roundToZero(), new THREE.Vector2( 0, 0 ), "roundToZero .1" ); + deepEqual( new THREE.Vector2( -0.5, 0.5 ).roundToZero(), new THREE.Vector2( 0, 0 ), "roundToZero .5" ); + deepEqual( new THREE.Vector2( -0.9, 0.9 ).roundToZero(), new THREE.Vector2( 0, 0 ), "roundToZero .9" ); + deepEqual( new THREE.Vector2( -1.1, 1.1 ).roundToZero(), new THREE.Vector2( -1, 1 ), "roundToZero 1.1" ); + deepEqual( new THREE.Vector2( -1.5, 1.5 ).roundToZero(), new THREE.Vector2( -1, 1 ), "roundToZero 1.5" ); + deepEqual( new THREE.Vector2( -1.9, 1.9 ).roundToZero(), new THREE.Vector2( -1, 1 ), "roundToZero 1.9" ); }); test( "negate", function() { @@ -2427,7 +2796,7 @@ ok( b.equals( a ), "Passed!" ); }); - + // -------------------------------------------- Vector3 test( "constructor", function() { var a = new THREE.Vector3(); ok( a.x == 0, "Passed!" ); @@ -2700,18 +3069,19 @@ }); test( "reflect", function() { - var a = new THREE.Vector3( 1, 0, 0 ); - var normal = new THREE.Vector3( 1, 0, 0 ); - var b = new THREE.Vector3( 0, 0, 0 ); + var a = new THREE.Vector3(); + var normal = new THREE.Vector3( 0, 1, 0 ); + var b = new THREE.Vector3(); - ok( b.copy( a ).reflect( normal ).equals( new THREE.Vector3( 1, 0, 0 ) ), "Passed!" ); + a.set( 0, -1, 0 ); + ok( b.copy( a ).reflect( normal ).equals( new THREE.Vector3( 0, 1, 0 ) ), "Passed!" ); a.set( 1, -1, 0 ); ok( b.copy( a ).reflect( normal ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" ); a.set( 1, -1, 0 ); normal.set( 0, -1, 0 ); - ok( b.copy( a ).reflect( normal ).equals( new THREE.Vector3( -1, -1, 0 ) ), "Passed!" ); + ok( b.copy( a ).reflect( normal ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" ); }); test( "angleTo", function() { @@ -2768,7 +3138,7 @@ ok( b.equals( a ), "Passed!" ); }); - + // -------------------------------------------- Vector4 test( "constructor", function() { var a = new THREE.Vector4(); ok( a.x == 0, "Passed!" ); @@ -2897,9 +3267,9 @@ b.multiplyScalar( -2 ); ok( b.x == 2*x, "Passed!" ); - ok( b.y == 2*y, "Passed!" ); - ok( b.z == 2*z, "Passed!" ); - ok( b.w == 2*w, "Passed!" ); + ok( b.y == 2*y, "Passed!" ); + ok( b.z == 2*z, "Passed!" ); + ok( b.w == 2*w, "Passed!" ); a.divideScalar( -2 ); ok( a.x == x, "Passed!" ); @@ -3008,26 +3378,26 @@ }); /* - test( "distanceTo/distanceToSquared", function() { - var a = new THREE.Vector4( x, 0, 0, 0 ); - var b = new THREE.Vector4( 0, -y, 0, 0 ); - var c = new THREE.Vector4( 0, 0, z, 0 ); - var d = new THREE.Vector4( 0, 0, 0, -w ); - var e = new THREE.Vector4(); - - ok( a.distanceTo( e ) == x, "Passed!" ); - ok( a.distanceToSquared( e ) == x*x, "Passed!" ); + test( "distanceTo/distanceToSquared", function() { + var a = new THREE.Vector4( x, 0, 0, 0 ); + var b = new THREE.Vector4( 0, -y, 0, 0 ); + var c = new THREE.Vector4( 0, 0, z, 0 ); + var d = new THREE.Vector4( 0, 0, 0, -w ); + var e = new THREE.Vector4(); - ok( b.distanceTo( e ) == y, "Passed!" ); - ok( b.distanceToSquared( e ) == y*y, "Passed!" ); + ok( a.distanceTo( e ) == x, "Passed!" ); + ok( a.distanceToSquared( e ) == x*x, "Passed!" ); - ok( c.distanceTo( e ) == z, "Passed!" ); - ok( c.distanceToSquared( e ) == z*z, "Passed!" ); + ok( b.distanceTo( e ) == y, "Passed!" ); + ok( b.distanceToSquared( e ) == y*y, "Passed!" ); - ok( d.distanceTo( e ) == w, "Passed!" ); - ok( d.distanceToSquared( e ) == w*w, "Passed!" ); - }); - */ + ok( c.distanceTo( e ) == z, "Passed!" ); + ok( c.distanceToSquared( e ) == z*z, "Passed!" ); + + ok( d.distanceTo( e ) == w, "Passed!" ); + ok( d.distanceToSquared( e ) == w*w, "Passed!" ); + }); + */ test( "setLength", function() { diff --git a/threejs/tests/webgl/webgl_animation_skinning_morph.ts b/threejs/tests/webgl/webgl_animation_skinning_morph.ts new file mode 100644 index 000000000..ab588fad3 --- /dev/null +++ b/threejs/tests/webgl/webgl_animation_skinning_morph.ts @@ -0,0 +1,297 @@ +/// +/// + +// https://github.com/mrdoob/three.js/blob/master/examples/webgl_sprites.html + +() => { + // ------- variable definitions that does not exist in the original code. These are for typescript. + var material: THREE.SpriteMaterial; + var geometry: THREE.JSonLoaderResultGeometry; + var dat:any; + // ------- + + var SCREEN_WIDTH = window.innerWidth; + var SCREEN_HEIGHT = window.innerHeight; + var FLOOR = -250; + + var container,stats; + + var camera, scene; + var renderer; + + var mesh, helper; + + var mouseX = 0, mouseY = 0; + + var windowHalfX = window.innerWidth / 2; + var windowHalfY = window.innerHeight / 2; + + var clock = new THREE.Clock(); + + document.addEventListener( 'mousemove', onDocumentMouseMove, false ); + + init(); + animate(); + + function init() { + + container = document.getElementById( 'container' ); + + camera = new THREE.PerspectiveCamera( 30, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 ); + camera.position.z = 2200; + + scene = new THREE.Scene(); + + scene.fog = new THREE.Fog( 0xffffff, 2000, 10000 ); + + scene.add( camera ); + + // GROUND + + var groundMaterial = new THREE.MeshPhongMaterial( { emissive: 0xbbbbbb } ); + var planeGeometry = new THREE.PlaneGeometry( 16000, 16000 ); + + var ground = new THREE.Mesh( planeGeometry, groundMaterial ); + ground.position.set( 0, FLOOR, 0 ); + ground.rotation.x = -Math.PI/2; + scene.add( ground ); + + ground.receiveShadow = true; + + + // LIGHTS + + var ambient = new THREE.AmbientLight( 0x222222 ); + scene.add( ambient ); + + + var light = new THREE.DirectionalLight( 0xebf3ff, 1.6 ); + light.position.set( 0, 140, 500 ).multiplyScalar( 1.1 ); + scene.add( light ); + + light.castShadow = true; + + light.shadowMapWidth = 2048; + light.shadowMapHeight = 2048; + + var d = 390; + + light.shadowCameraLeft = -d * 2; + light.shadowCameraRight = d * 2; + light.shadowCameraTop = d * 1.5; + light.shadowCameraBottom = -d; + + light.shadowCameraFar = 3500; + //light.shadowCameraVisible = true; + + // + + var light = new THREE.DirectionalLight( 0x497f13, 1 ); + light.position.set( 0, -1, 0 ); + scene.add( light ); + + // RENDERER + + renderer = new THREE.WebGLRenderer( { antialias: true } ); + renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT ); + renderer.domElement.style.position = "relative"; + + renderer.setClearColor( scene.fog.color, 1 ); + + container.appendChild( renderer.domElement ); + + renderer.gammaInput = true; + renderer.gammaOutput = true; + + renderer.shadowMapEnabled = true; + + + // STATS + + stats = new Stats(); + container.appendChild( stats.domElement ); + + // + + var loader = new THREE.JSONLoader(); + loader.load( "models/skinned/knight.js", function ( geometry, materials ) { + + createScene( geometry, materials, 0, FLOOR, -300, 60 ) + + } ); + + // GUI + + initGUI(); + + // + + window.addEventListener( 'resize', onWindowResize, false ); + + } + + function onWindowResize() { + + windowHalfX = window.innerWidth / 2; + windowHalfY = window.innerHeight / 2; + + camera.aspect = window.innerWidth / window.innerHeight; + camera.updateProjectionMatrix(); + + renderer.setSize( window.innerWidth, window.innerHeight ); + + } + + function ensureLoop( animation ) { + + for ( var i = 0; i < animation.hierarchy.length; i ++ ) { + + var bone = animation.hierarchy[ i ]; + + var first = bone.keys[ 0 ]; + var last = bone.keys[ bone.keys.length - 1 ]; + + last.pos = first.pos; + last.rot = first.rot; + last.scl = first.scl; + + } + + } + + function createScene( geometry, materials, x, y, z, s ) { + + ensureLoop( geometry.animation ); + + geometry.computeBoundingBox(); + var bb = geometry.boundingBox; + + var path = "textures/cube/Park2/"; + var format = '.jpg'; + var urls = [ + path + 'posx' + format, path + 'negx' + format, + path + 'posy' + format, path + 'negy' + format, + path + 'posz' + format, path + 'negz' + format + ]; + + + //var envMap = THREE.ImageUtils.loadTextureCube( urls ); + + //var map = THREE.ImageUtils.loadTexture( "textures/UV_Grid_Sm.jpg" ); + + //var bumpMap = THREE.ImageUtils.generateDataTexture( 1, 1, new THREE.Color() ); + //var bumpMap = THREE.ImageUtils.loadTexture( "textures/water.jpg" ); + + for ( var i = 0; i < materials.length; i ++ ) { + + var m = materials[ i ]; + m.skinning = true; + m.morphTargets = true; + + m.specular.setHSL( 0, 0, 0.1 ); + + m.color.setHSL( 0.6, 0, 0.6 ); + m.ambient.copy( m.color ); + + //m.map = map; + //m.envMap = envMap; + //m.bumpMap = bumpMap; + //m.bumpScale = 2; + + //m.combine = THREE.MixOperation; + //m.reflectivity = 0.75; + + m.wrapAround = true; + + } + + mesh = new THREE.SkinnedMesh( geometry, new THREE.MeshFaceMaterial( materials ) ); + mesh.position.set( x, y - bb.min.y * s, z ); + mesh.scale.set( s, s, s ); + scene.add( mesh ); + + mesh.castShadow = true; + mesh.receiveShadow = true; + + helper = new THREE.SkeletonHelper( mesh ); + helper.material.linewidth = 3; + helper.visible = false; + scene.add( helper ); + + var animation = new THREE.Animation( mesh, geometry.animation ); + animation.play(); + + } + + function initGUI() { + + var API = { + 'show model' : true, + 'show skeleton' : false + }; + + var gui = new dat.GUI(); + + gui.add( API, 'show model' ).onChange( function() { mesh.visible = API[ 'show model' ]; } ); + + gui.add( API, 'show skeleton' ).onChange( function() { helper.visible = API[ 'show skeleton' ]; } ); + + } + + function onDocumentMouseMove( event ) { + + mouseX = ( event.clientX - windowHalfX ); + mouseY = ( event.clientY - windowHalfY ); + + } + + // + + function animate() { + + requestAnimationFrame( animate ); + + render(); + stats.update(); + + } + + function render() { + + var delta = 0.75 * clock.getDelta(); + + camera.position.x += ( mouseX - camera.position.x ) * .05; + camera.position.y = THREE.Math.clamp( camera.position.y + ( - mouseY - camera.position.y ) * .05, 0, 1000 ); + + camera.lookAt( scene.position ); + + // update skinning + + THREE.AnimationHandler.update( delta ); + + if ( helper !== undefined ) helper.update(); + + // update morphs + + if ( mesh ) { + + var time = Date.now() * 0.001; + + // mouth + + mesh.morphTargetInfluences[ 1 ] = ( 1 + Math.sin( 4 * time ) ) / 2; + + // frown ? + + mesh.morphTargetInfluences[ 2 ] = ( 1 + Math.sin( 2 * time ) ) / 2; + + // eyes + + mesh.morphTargetInfluences[ 3 ] = ( 1 + Math.cos( 4 * time ) ) / 2; + + } + + renderer.render( scene, camera ); + + } +} \ No newline at end of file diff --git a/threejs/tests/webgl/webgl_buffergeometry.ts b/threejs/tests/webgl/webgl_buffergeometry.ts index f8d455932..de4ad2aee 100644 --- a/threejs/tests/webgl/webgl_buffergeometry.ts +++ b/threejs/tests/webgl/webgl_buffergeometry.ts @@ -49,11 +49,6 @@ var geometry = new THREE.BufferGeometry(); - geometry.addAttribute('index', new Uint16Array(triangles * 3), 1); - geometry.addAttribute('position', new Float32Array(triangles * 3 * 3), 3); - geometry.addAttribute('normal', new Float32Array(triangles * 3 * 3), 3); - geometry.addAttribute('color', new Float32Array(triangles * 3 * 3), 3); - // break geometry into // chunks of 21,845 triangles (3 unique vertices per triangle) // for indices to fit into 16 bit integer number @@ -61,7 +56,7 @@ var chunkSize = 21845; - var indices = geometry.getAttribute('index').array; + var indices = new Uint16Array( triangles * 3 ); for (var i = 0; i < indices.length; i++) { @@ -69,9 +64,9 @@ } - var positions = geometry.getAttribute('position').array; - var normals = geometry.getAttribute('normal').array; - var colors = geometry.getAttribute('color').array; + var positions = new Float32Array( triangles * 3 * 3 ); + var normals = new Float32Array( triangles * 3 * 3 ); + var colors = new Float32Array( triangles * 3 * 3 ); var color = new THREE.Color(); @@ -167,6 +162,11 @@ } + geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) ); + geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) ); + geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) ); + geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) ); + var offsets = triangles / chunkSize; for (var i = 0; i < offsets; i++) { diff --git a/threejs/tests/webgl/webgl_camera.ts b/threejs/tests/webgl/webgl_camera.ts index 4bf35883c..531d97fc4 100644 --- a/threejs/tests/webgl/webgl_camera.ts +++ b/threejs/tests/webgl/webgl_camera.ts @@ -85,7 +85,7 @@ } - var particles = new THREE.ParticleSystem(geometry, new THREE.ParticleSystemMaterial({ color: 0x888888 })); + var particles = new THREE.PointCloud( geometry, new THREE.PointCloudMaterial( { color: 0x888888 } ) ); scene.add(particles); // diff --git a/threejs/tests/webgl/webgl_interactive_raycasting_pointcloud.ts b/threejs/tests/webgl/webgl_interactive_raycasting_pointcloud.ts new file mode 100644 index 000000000..330abd001 --- /dev/null +++ b/threejs/tests/webgl/webgl_interactive_raycasting_pointcloud.ts @@ -0,0 +1,335 @@ +/// +/// + +// https://github.com/mrdoob/three.js/blob/master/examples/webgl_sprites.html + +() => { + // ------- variable definitions that does not exist in the original code. These are for typescript. + var material: THREE.SpriteMaterial; + var intersection: THREE.Intersection; + var container: HTMLElement; + var pcBuffer: THREE.PointCloud; + var v: any; + // ------- + + if ( ! Detector.webgl ) Detector.addGetWebGLMessage(); + + var renderer, scene, camera, stats; + var pointclouds; + var projector, raycaster, intersects; + var mouse = { x: 1, y: 1 }; + var vector = new THREE.Vector3(); + intersection = null; + var spheres = []; + var spheresIndex = 0; + var clock; + + var threshold = 0.1; + var pointSize = 0.01; + var width = 150; + var length = 150; + var rotateY = new THREE.Matrix4().makeRotationY( 0.005 ); + + init(); + animate(); + + function generatePointCloudGeometry( color, width, length ){ + + var geometry = new THREE.BufferGeometry(); + var numPoints = width*length; + + var positions = new Float32Array( numPoints*3 ); + var colors = new Float32Array( numPoints*3 ); + + var k = 0; + + for( var i = 0; i < width; i++ ) { + + for( var j = 0; j < length; j++ ) { + + var u = i / width; + var v = j / length; + var x = u - 0.5; + var y = ( Math.cos( u * Math.PI * 8 ) + Math.sin( v * Math.PI * 8 ) ) / 20; + var z = v - 0.5; + + positions[ 3 * k ] = x; + positions[ 3 * k + 1 ] = y; + positions[ 3 * k + 2 ] = z; + + var intensity = ( y + 0.1 ) * 5; + colors[ 3 * k ] = color.r * intensity; + colors[ 3 * k + 1 ] = color.g * intensity; + colors[ 3 * k + 2 ] = color.b * intensity; + + k++; + + } + + } + + geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) ); + geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) ); + geometry.computeBoundingBox(); + + return geometry; + + } + + function generatePointcloud( color, width, length ) { + + var geometry = generatePointCloudGeometry( color, width, length ); + + var material = new THREE.PointCloudMaterial( { size: pointSize, vertexColors: THREE.VertexColors } ); + var pointcloud = new THREE.PointCloud( geometry, material ); + + return pointcloud; + + } + + function generateIndexedPointcloud( color, width, length ) { + + var geometry = generatePointCloudGeometry( color, width, length ); + var numPoints = width * length; + var indices = new Uint16Array( numPoints ); + + var k = 0; + + for( var i = 0; i < width; i++ ) { + + for( var j = 0; j < length; j++ ) { + + indices[ k ] = k; + k++; + + } + + } + + geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) ); + + var material = new THREE.PointCloudMaterial( { size: pointSize, vertexColors: THREE.VertexColors } ); + var pointcloud = new THREE.PointCloud( geometry, material ); + + return pointcloud; + + } + + function generateIndexedWithOffsetPointcloud( color, width, length ){ + + var geometry = generatePointCloudGeometry( color, width, length ); + var numPoints = width * length; + var indices = new Uint16Array( numPoints ); + + var k = 0; + + for( var i = 0; i < width; i++ ){ + + for( var j = 0; j < length; j++ ) { + + indices[ k ] = k; + k++; + + } + + } + + geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) ); + + var offset = { start: 0, count: indices.length, index: 0 }; + geometry.offsets.push( offset ); + + var material = new THREE.PointCloudMaterial( { size: pointSize, vertexColors: THREE.VertexColors } ); + var pointcloud = new THREE.PointCloud( geometry, material ); + + return pointcloud; + + } + + function generateRegularPointcloud( color, width, length ) { + + var geometry = new THREE.Geometry(); + var numPoints = width * length; + + var colors = []; + + var k = 0; + + for( var i = 0; i < width; i++ ) { + + for( var j = 0; j < length; j++ ) { + + var u = i / width; + v = j / length; + var x = u - 0.5; + var y = ( Math.cos( u * Math.PI * 8 ) + Math.sin( v * Math.PI * 8) ) / 20; + var z = v - 0.5; + v = new THREE.Vector3( x,y,z ); + + var intensity = ( y + 0.1 ) * 7; + colors[ 3 * k ] = color.r * intensity; + colors[ 3 * k + 1 ] = color.g * intensity; + colors[ 3 * k + 2 ] = color.b * intensity; + + geometry.vertices.push( v ); + colors[ k ] = ( color.clone().multiplyScalar( intensity ) ); + + k++; + + } + + } + + geometry.colors = colors; + geometry.computeBoundingBox(); + + var material = new THREE.PointCloudMaterial( { size: pointSize, vertexColors: THREE.VertexColors } ); + var pointcloud = new THREE.PointCloud( geometry, material ); + + return pointcloud; + + } + + function init() { + + container = document.getElementById( 'container' ); + + scene = new THREE.Scene(); + + clock = new THREE.Clock(); + + camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 ); + camera.applyMatrix( new THREE.Matrix4().makeTranslation( 0,0,20 ) ); + camera.applyMatrix( new THREE.Matrix4().makeRotationX( -0.5 ) ); + + // + + pcBuffer = generatePointcloud( new THREE.Color( 1,0,0 ), width, length ); + pcBuffer.scale.set( 10,10,10 ); + pcBuffer.position.set( -5,0,5 ); + scene.add( pcBuffer ); + + var pcIndexed = generateIndexedPointcloud( new THREE.Color( 0,1,0 ), width, length ); + pcIndexed.scale.set( 10,10,10 ); + pcIndexed.position.set( 5,0,5 ); + scene.add( pcIndexed ); + + var pcIndexedOffset = generateIndexedWithOffsetPointcloud( new THREE.Color( 0,1,1 ), width, length ); + pcIndexedOffset.scale.set( 10,10,10 ); + pcIndexedOffset.position.set( 5,0,-5 ); + scene.add( pcIndexedOffset ); + + var pcRegular = generateRegularPointcloud( new THREE.Color( 1,0,1 ), width, length ); + pcRegular.scale.set( 10,10,10 ); + pcRegular.position.set( -5,0,-5 ); + scene.add( pcRegular ); + + pointclouds = [ pcBuffer, pcIndexed, pcIndexedOffset, pcRegular ]; + + // + + var sphereGeometry = new THREE.SphereGeometry( 0.1, 32, 32 ); + var sphereMaterial = new THREE.MeshBasicMaterial( { color: 0xff0000, shading: THREE.FlatShading } ); + + for ( var i = 0; i < 40; i++ ) { + + var sphere = new THREE.Mesh( sphereGeometry, sphereMaterial ); + scene.add( sphere ); + spheres.push( sphere ); + + } + + // + + renderer = new THREE.WebGLRenderer(); + renderer.setSize( window.innerWidth, window.innerHeight ); + + container.appendChild( renderer.domElement ); + + // + + projector = new THREE.Projector(); + raycaster = new THREE.Raycaster(); + raycaster.params.PointCloud.threshold = threshold; + + // + + stats = new Stats(); + stats.domElement.style.position = 'absolute'; + stats.domElement.style.top = '0px'; + container.appendChild( stats.domElement ); + + // + + window.addEventListener( 'resize', onWindowResize, false ); + document.addEventListener( 'mousemove', onDocumentMouseMove, false ); + + } + + function onDocumentMouseMove( event ) { + + event.preventDefault(); + + mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1; + mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1; + + } + + function onWindowResize() { + + camera.aspect = window.innerWidth / window.innerHeight; + camera.updateProjectionMatrix(); + + renderer.setSize( window.innerWidth, window.innerHeight ); + + } + + function animate() { + + requestAnimationFrame( animate ); + + render(); + stats.update(); + + } + + var toggle = 0; + + function render() { + + camera.applyMatrix( rotateY ); + camera.updateMatrixWorld( true ); + + vector.set( mouse.x, mouse.y, 0.1 ); + + projector.unprojectVector( vector, camera ); + + raycaster.ray.set( camera.position, vector.sub( camera.position ).normalize() ); + + var intersections = raycaster.intersectObjects( pointclouds ); + intersection = ( intersections.length ) > 0 ? intersections[ 0 ] : null; + + if ( toggle > 0.02 && intersection !== null) { + + spheres[ spheresIndex ].position.copy( intersection.point ); + spheres[ spheresIndex ].scale.set( 1, 1, 1 ); + spheresIndex = ( spheresIndex + 1 ) % spheres.length; + + toggle = 0; + + } + + for ( var i = 0; i < spheres.length; i++ ) { + + var sphere = spheres[ i ]; + sphere.scale.multiplyScalar( 0.98 ); + sphere.scale.clampScalar( 0.01, 1 ); + + } + + toggle += clock.getDelta(); + + renderer.render( scene, camera ); + + } +} \ No newline at end of file diff --git a/threejs/tests/webgl/webgl_lensflares.ts b/threejs/tests/webgl/webgl_lensflares.ts index c8e1bfed4..bb99d701c 100644 --- a/threejs/tests/webgl/webgl_lensflares.ts +++ b/threejs/tests/webgl/webgl_lensflares.ts @@ -116,7 +116,7 @@ lensFlare.add(textureFlare3, 70, 1.0, THREE.AdditiveBlending); lensFlare.customUpdateCallback = lensFlareUpdateCallback; - lensFlare.position = light.position; + lensFlare.position.copy( light.position ); scene.add(lensFlare); diff --git a/threejs/tests/webgl/webgl_materials.ts b/threejs/tests/webgl/webgl_materials.ts index 1f1dab70c..da1c311da 100644 --- a/threejs/tests/webgl/webgl_materials.ts +++ b/threejs/tests/webgl/webgl_materials.ts @@ -12,7 +12,7 @@ var container, stats; var camera, scene, renderer, objects; - var particleLight, pointLight; + var particleLight; var materials = []; @@ -130,8 +130,8 @@ scene.add(directionalLight); - pointLight = new THREE.PointLight(0xffffff, 1); - scene.add(pointLight); + var pointLight = new THREE.PointLight(0xffffff, 1); + particleLight.add(pointLight); // @@ -228,10 +228,6 @@ particleLight.position.y = Math.cos(timer * 5) * 400; particleLight.position.z = Math.cos(timer * 3) * 300; - pointLight.position.x = particleLight.position.x; - pointLight.position.y = particleLight.position.y; - pointLight.position.z = particleLight.position.z; - renderer.render(scene, camera); } diff --git a/threejs/tests/webgl/webgl_particles_billboards.ts b/threejs/tests/webgl/webgl_particles_billboards.ts index 8e786303d..a2f62fc6a 100644 --- a/threejs/tests/webgl/webgl_particles_billboards.ts +++ b/threejs/tests/webgl/webgl_particles_billboards.ts @@ -42,10 +42,10 @@ } - material = new THREE.ParticleSystemMaterial({ size: 35, sizeAttenuation: false, map: sprite, transparent: true }); + material = new THREE.PointCloudMaterial({ size: 35, sizeAttenuation: false, map: sprite, transparent: true }); material.color.setHSL(1.0, 0.3, 0.7); - particles = new THREE.ParticleSystem(geometry, material); + particles = new THREE.PointCloud(geometry, material); particles.sortParticles = true; scene.add(particles); diff --git a/threejs/tests/webgl/webgl_postprocessing.ts b/threejs/tests/webgl/webgl_postprocessing.ts index e3aaff31a..707804c28 100644 --- a/threejs/tests/webgl/webgl_postprocessing.ts +++ b/threejs/tests/webgl/webgl_postprocessing.ts @@ -80,8 +80,6 @@ requestAnimationFrame(animate); - var time = Date.now(); - object.rotation.x += 0.005; object.rotation.y += 0.01; diff --git a/threejs/three-tests.ts b/threejs/three-tests.ts index 4ff78b618..46a563a6d 100644 --- a/threejs/three-tests.ts +++ b/threejs/three-tests.ts @@ -26,12 +26,14 @@ THE SOFTWARE. // webGL renderer test. /// +/// /// /// /// /// /// /// +/// /// /// /// @@ -54,3 +56,4 @@ THE SOFTWARE. /// /// /// + diff --git a/threejs/three.d.ts b/threejs/three.d.ts index 748900166..41a07f32b 100644 --- a/threejs/three.d.ts +++ b/threejs/three.d.ts @@ -1,4 +1,4 @@ -// Type definitions for three.js r67 +// Type definitions for three.js r68 // Project: http://mrdoob.github.com/three.js/ // Definitions by: Kon , Satoru Kimura // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -174,6 +174,15 @@ declare module THREE { clone(camera?: Camera): Camera; } + export class CubeCamera extends Object3D { + constructor( near?: number, far?: number, cubeResolution?: number); + + renderTarget: WebGLRenderTargetCube; + + updateCubeMap( renderer: Renderer, scene: Scene ): void; + + } + /** * Camera with orthographic projection * @@ -326,43 +335,64 @@ declare module THREE { // Core /////////////////////////////////////////////////////////////////////////////////////////////// export class BufferAttribute { - constructor(); + constructor(array: any, itemSize: number); - set(value: number): void; - setX(index: number, x: number): void; - setY(index: number, y: number): void; - setZ(index: number, z: number): void; - setXY(index: number, x: number, y: number): void; - setXYZ(index: number, x: number, y: number, z: number): void; - setXYZW(index: number, x: number, y: number, z: number, w: number): void; + array: any; + itemSize: number; + length: number; + + set(value: number): BufferAttribute; + setX(index: number, x: number): BufferAttribute; + setY(index: number, y: number): BufferAttribute; + setZ(index: number, z: number): BufferAttribute; + setXY(index: number, x: number, y: number): BufferAttribute; + setXYZ(index: number, x: number, y: number, z: number): BufferAttribute; + setXYZW(index: number, x: number, y: number, z: number, w: number): BufferAttribute; } + // deprecated export class Int8Attribute extends BufferAttribute{ - constructor(size: number, itemSize: number); + constructor(data: any[], itemSize: number); } + + // deprecated export class Uint8Attribute extends BufferAttribute { - constructor(size: number, itemSize: number); + constructor(data: any[], itemSize: number); } + + // deprecated export class Uint8ClampedAttribute extends BufferAttribute { - constructor(size: number, itemSize: number); + constructor(data: any[], itemSize: number); } + + // deprecated export class Int16Attribute extends BufferAttribute { - constructor(size: number, itemSize: number); + constructor(data: any[], itemSize: number); } + + // deprecated export class Uint16Attribute extends BufferAttribute { - constructor(size: number, itemSize: number); + constructor(data: any[], itemSize: number); } + + // deprecated export class Int32Attribute extends BufferAttribute { - constructor(size: number, itemSize: number); + constructor(data: any[], itemSize: number); } + + // deprecated export class Uint32Attribute extends BufferAttribute { - constructor(size: number, itemSize: number); + constructor(data: any[], itemSize: number); } + + // deprecated export class Float32Attribute extends BufferAttribute { - constructor(size: number, itemSize: number); + constructor(data: any[], itemSize: number); } + + // deprecated export class Float64Attribute extends BufferAttribute { - constructor(size: number, itemSize: number); + constructor(data: any[], itemSize: number); } /** @@ -401,6 +431,8 @@ declare module THREE { */ applyMatrix(matrix: Matrix4): void; + fromGeometry( geometry: Geometry, settings?: any ): BufferGeometry; + /** * Computes bounding box of the geometry, updating Geometry.boundingBox attribute. * Bounding boxes aren't computed by default. They need to be explicitly computed, otherwise they are null. @@ -639,7 +671,7 @@ declare module THREE { export interface MorphColor { name: string; - color: Color[]; + colors: Color[]; } export interface MorphNormals { @@ -758,6 +790,11 @@ declare module THREE { */ skinIndices: number[]; + /** + * + */ + lineDistances: number[]; + /** * Bounding box. */ @@ -823,13 +860,18 @@ declare module THREE { /** * */ - lineDistances: number[]; + groupsNeedUpdate: boolean; /** * Bakes matrix transform directly into vertex coordinates. */ applyMatrix(matrix: Matrix4): void; + /** + * + */ + center(): Vector3; + /** * Computes face normals. */ @@ -899,6 +941,11 @@ declare module THREE { */ id: number; + /** + * + */ + uuid: number; + /** * Optional name of the object (doesn't need to be unique). */ @@ -914,6 +961,11 @@ declare module THREE { */ children: Object3D[]; + /** + * Up direction. + */ + up: Vector3; + /** * Object's local position. */ @@ -925,10 +977,9 @@ declare module THREE { rotation: Euler; /** - * Order of axis for Euler angles. + * Global rotation. */ - eulerOrder: string; - // eulerOrder:EulerOrder; + quaternion: Quaternion; /** * Object's local scale. @@ -936,9 +987,14 @@ declare module THREE { scale: Vector3; /** - * Up direction. + * Override depth-sorting order if non null. */ - up: Vector3; + renderDepth: number; + + /** + * When this is set, then the rotationMatrix gets calculated every frame. + */ + rotationAutoUpdate: boolean; /** * Local transform. @@ -946,19 +1002,19 @@ declare module THREE { matrix: Matrix4; /** - * Global rotation. + * The global transform of the object. If the Object3d has no parent, then it's identical to the local transform. */ - quaternion: Quaternion; + matrixWorld: Matrix4; /** - * Use quaternion instead of Euler angles for specifying local rotation. + * When this is set, it calculates the matrix of position, (rotation or quaternion) and scale every frame and also recalculates the matrixWorld property. */ - useQuaternion: boolean; + matrixAutoUpdate: boolean; /** - * Override depth-sorting order if non null. + * When this is set, it calculates the matrixWorld in that frame and resets this property to false. */ - renderDepth: number; + matrixWorldNeedsUpdate: boolean; /** * Object gets rendered if true. @@ -980,54 +1036,95 @@ declare module THREE { */ frustumCulled: boolean; - /** - * When this is set, it calculates the matrix of position, (rotation or quaternion) and scale every frame and also recalculates the matrixWorld property. - */ - matrixAutoUpdate: boolean; - - /** - * When this is set, it calculates the matrixWorld in that frame and resets this property to false. - */ - matrixWorldNeedsUpdate: boolean; - - /** - * When this is set, then the rotationMatrix gets calculated every frame. - */ - rotationAutoUpdate: boolean; - /** * An object that can be used to store custom data about the Object3d. It should not hold references to functions as these will not be cloned. */ userData: any; /** - * The global transform of the object. If the Object3d has no parent, then it's identical to the local transform. + * */ - matrixWorld: Matrix4; + static DefaultUp: Vector3; + /** + * Order of axis for Euler angles. + */ + eulerOrder: string; + // eulerOrder:EulerOrder; + + /** + * Use quaternion instead of Euler angles for specifying local rotation. + */ + useQuaternion: boolean; + /** * This updates the position, rotation and scale with the matrix. */ applyMatrix(matrix: Matrix4): void; + /** + * + */ + setRotationFromAxisAngle(axis: Vector3, angle: number): void; + + /** + * + */ + setRotationFromEuler(euler: Euler ): void; + + /** + * + */ + setRotationFromMatrix(m: Matrix4): void; + + /** + * + */ + setRotationFromQuaternion( q: Quaternion ): void; + + /** + * + * @param angle + */ + rotateX(angle: number): Object3D; + + /** + * + * @param angle + */ + rotateY(angle: number): Object3D; + + /** + * + * @param angle + */ + rotateZ(angle: number): Object3D; + + /** + * + * @param distance + * @param axis + */ + translate( distance: number, axis: Vector3 ): Object3D; + /** * Translates object along x axis by distance. * @param distance Distance. */ - translateX(distance: number): void; + translateX(distance: number): Object3D; /** * Translates object along y axis by distance. * @param distance Distance. */ - translateY(distance: number): void; + translateY(distance: number): Object3D; /** * Translates object along z axis by distance. * @param distance Distance. */ - translateZ(distance: number): void; + translateZ(distance: number): Object3D; /** * Updates the vector from local space to world space. @@ -1057,6 +1154,11 @@ declare module THREE { */ remove(object: Object3D): void; + /** + * + */ + raycast(raycaster: Raycaster, intersects: any): void; + /** * Translates object along arbitrary axis by distance. * @param distance Distance. @@ -1065,10 +1167,22 @@ declare module THREE { traverse(callback: (object: Object3D) => any): void; /** - * Searches whole subgraph recursively to add all objects in the array. - * @param array optional argument that returns the the array with descendants. + * Searches through the object's children and returns the first with a matching id, optionally recursive. + * @param id Unique number of the object instance + * @param recursive Boolean whether to search through the children's children. Default is false. */ - getDescendants(array?: Object3D[]): Object3D[]; + getObjectById(id: string, recursive: boolean): Object3D; + + + /** + * Searches through the object's children and returns the first with a matching name, optionally recursive. + * @param name String to match to the children's Object3d.name property. + * @param recursive Boolean whether to search through the children's children. Default is false. + */ + getObjectByName(name: string, recursive: boolean): Object3D; + + + getChildByName( name: string, recursive: boolean ): Object3D; /** * Updates local transform. @@ -1080,22 +1194,13 @@ declare module THREE { */ updateMatrixWorld(force: boolean): void; + /** + * + * @param object + * @param recursive + */ clone(object?: Object3D, recursive?: boolean): Object3D; - /** - * Searches through the object's children and returns the first with a matching name, optionally recursive. - * @param name String to match to the children's Object3d.name property. - * @param recursive Boolean whether to search through the children's children. Default is false. - */ - getObjectByName(name: string, recursive: boolean): Object3D; - - /** - * Searches through the object's children and returns the first with a matching id, optionally recursive. - * @param id Unique number of the object instance - * @param recursive Boolean whether to search through the children's children. Default is false. - */ - getObjectById(id: string, recursive: boolean): Object3D; - /** * @param axis A normalized vector in object space. * @param distance The distance to translate. @@ -1148,12 +1253,22 @@ declare module THREE { object: Object3D; } + export interface RaycasterParameters { + Sprite?: any; + Mesh?: any; + PointCloud?: any; + LOD?: any; + Line?: any; + } + export class Raycaster { constructor(origin?: Vector3, direction?: Vector3, near?: number, far?: number); ray: Ray; near: number; far: number; + params: RaycasterParameters; precision: number; + linePrecision: number; set(origin: Vector3, direction: Vector3): void; intersectObject(object: Object3D, recursive?: boolean): Intersection[]; intersectObjects(objects: Object3D[], recursive?: boolean): Intersection[]; @@ -1609,17 +1724,34 @@ declare module THREE { initMaterials(materials: Material[], texturePath: string): Material[]; extractUrlBase(url: string): string; addStatusElement(): HTMLElement; + + static Handlers:LoaderHandler; + } + + export interface LoaderHandler{ + handlers:any[]; + add(regex:string, loader:Loader):void; + get(file: string):Loader; } export class BufferGeometryLoader { constructor(manager?: LoadingManager); - load(url: string, onLoad: (bufferGeometry: BufferGeometry) => void): void; + load(url: string, onLoad: (bufferGeometry: BufferGeometry) => void, onProgress?: (event: any) => void, onError?: (event: any) => void): void; setCrossOrigin(crossOrigin: string): void; parse(json: any): BufferGeometry; } + export class GeometryLoader { + constructor(manager?: LoadingManager); + + load(url: string, onLoad: (bufferGeometry: BufferGeometry) => void, onProgress?: (event: any) => void, onError?: (event: any) => void): void; + setCrossOrigin(crossOrigin: string): void; + parse(json: any): Geometry; + + } + export class Cache{ constructor(); @@ -1659,12 +1791,16 @@ declare module THREE { * @param callback. This function will be called with the loaded model as an instance of geometry when the load is completed. * @param texturePath If not specified, textures will be assumed to be in the same folder as the Javascript model file. */ - load(url: string, callback: (geometry: Geometry, materials: Material[]) => void , texturePath?: string): void; + load(url: string, callback: (geometry: JSonLoaderResultGeometry, materials: Material[]) => void , texturePath?: string): void; parse(json:string, texturePath:string): any; loadAjaxJSON(context: JSONLoader, url: string, callback: (geometry: Geometry, materials: Material[]) => void , texturePath?: string, callbackProgress?: (progress: Progress) => void ): void; } + export class JSonLoaderResultGeometry extends Geometry { + animation: AnimationData; + } + /** * Handles and keeps track of loaded and pending data. */ @@ -1713,76 +1849,6 @@ declare module THREE { parseObject(data: any, geometries: any[], materials: Material[]): T; } - interface SceneLoaderResult{ - scene: Scene; - geometries: {[id:string]:Geometry;}; - face_materials: {[id:string]:Material;}; - materials: {[id:string]:Material;}; - textures: {[id:string]:Texture;}; - objects: {[id:string]:Object3D;}; - cameras: {[id:string]:Camera;}; - lights: {[id:string]:Light;}; - fogs: {[id:string]:IFog;}; - empties: {[id:string]:any;}; - groups: {[id:string]:any;}; - } - - interface SceneLoaderProgress{ - totalModels: number; - totalTextures: number; - loadedModels: number; - loadedTextures: number; - } - - /** - * A loader for loading a complete scene out of a JSON file. - */ - export class SceneLoader { - constructor(); - - /** - * Will be called when load starts. - * The default is a function with empty body. - */ - onLoadStart: () => void; - - /** - * Will be called while load progresses. - * The default is a function with empty body. - */ - onLoadProgress: () => void; - - /** - * Will be called when each element in the scene completes loading. - * The default is a function with empty body. - */ - onLoadComplete: () => void; - - /** - * Will be called when load completes. - * The default is a function with empty body. - */ - callbackSync: (result: SceneLoaderResult) => void; - - /** - * Will be called as load progresses. - * The default is a function with empty body. - */ - callbackProgress: (progress: SceneLoaderProgress, result: SceneLoaderResult) => void; - hierarchyHandlers: any; - geometryHandlers: any; - - /** - * @param url - * @param callbackFinished This function will be called with the loaded model as an instance of scene when the load is completed. - */ - load(url: string, onLoad: (result: SceneLoaderResult) => void): void; - setCrossOrigin(crossOrigin: string): void; - addHierarchyHandler(typeID: string, loaderClass: any): void; - parse(json: any, callbackFinished: (result: SceneLoaderResult) => void, url: string): void; - addGeometryHandler(typeID: string, loaderClass: any): void; - } - /** * Class for loading a texture. * Unlike other loaders, this one emits events instead of using predefined callbacks. So if you're interested in getting notified when things happen, you need to add listeners to the object. @@ -1804,9 +1870,11 @@ declare module THREE { cache: Cache; crossOrigin: string; + responseType: string; load(url: string, onLoad?: (responseText: string) => void, onProgress?: (event: any) => void, onError?: (event: any) => void): void; setCrossOrigin(crossOrigin: string): void; + setResponseType(responseType: string): void; } // Materials ////////////////////////////////////////////////////////////////////////////////// @@ -1977,6 +2045,7 @@ declare module THREE { fog?: boolean; lightMap?: Texture; specularMap?: Texture; + alphaMap?: Texture; envMap?: Texture; skinning?: boolean; morphTargets?: boolean; @@ -1999,6 +2068,7 @@ declare module THREE { fog: boolean; lightMap: Texture; specularMap: Texture; + alphaMap: Texture; envMap: Texture; skinning: boolean; morphTargets: boolean; @@ -2044,6 +2114,7 @@ declare module THREE { map?: Texture; lightMap?: Texture; specularMap?: Texture; + alphaMap?: Texture; envMap?: Texture; reflectivity?: number; refractionRatio?: number; @@ -2070,6 +2141,7 @@ declare module THREE { map: Texture; lightMap: Texture; specularMap: Texture; + alphaMap: Texture; envMap: Texture; reflectivity: number; refractionRatio: number; @@ -2116,6 +2188,7 @@ declare module THREE { map?: Texture; lightMap?: Texture; specularMap?: Texture; + alphaMap?: Texture; envMap?: Texture; reflectivity?: number; refractionRatio?: number; @@ -2150,6 +2223,7 @@ declare module THREE { map: Texture; lightMap: Texture; specularMap: Texture; + alphaMap: Texture; envMap: Texture; reflectivity: number; refractionRatio: number; @@ -2169,17 +2243,17 @@ declare module THREE { clone(): MeshPhongMaterial; } - export interface ParticleSystemMaterialParameters { + export interface PointCloudMaterialParameters { color?: number; map?: Texture; size?: number; sizeAttenuation?: boolean; - vertexColors?: boolean; + vertexColors?: Colors; fog?: boolean; } - export class ParticleSystemMaterial extends Material { - constructor(parameters?: ParticleSystemMaterialParameters); + export class PointCloudMaterial extends Material { + constructor(parameters?: PointCloudMaterialParameters); color: Color; map: Texture; size: number; @@ -2187,7 +2261,17 @@ declare module THREE { vertexColors: boolean; fog: boolean; - clone(): ParticleSystemMaterial; + clone(): PointCloudMaterial; + } + + // deprecated + export class ParticleBasicMaterial extends PointCloudMaterial{ + + } + + // deprecated + export class ParticleSystemMaterial extends PointCloudMaterial{ + } export class RawShaderMaterial extends ShaderMaterial { @@ -2337,6 +2421,7 @@ declare module THREE { distanceToPoint(point: Vector3): number; containsPoint(point: Vector3): boolean; setFromCenterAndSize(center: Vector3, size: number): Box3; + setFromObject(object: Object3D): Box3; } export interface HSL { @@ -2466,6 +2551,157 @@ declare module THREE { clone(): Color; } + export class ColorKeywords { + static test2: string; + static aliceblue: string; + static antiquewhite: string; + static aqua: string; + static aquamarine: string; + static azure: string; + static beige: string; + static bisque: string; + static black: string; + static blanchedalmond: string; + static blue: string; + static blueviolet: string; + static brown: string; + static burlywood: string; + static cadetblue: string; + static chartreuse: string; + static chocolate: string; + static coral: string; + static cornflowerblue: string; + static cornsilk: string; + static crimson: string; + static cyan: string; + static darkblue: string; + static darkcyan: string; + static darkgoldenrod: string; + static darkgray: string; + static darkgreen: string; + static darkgrey: string; + static darkkhaki: string; + static darkmagenta: string; + static darkolivegreen: string; + static darkorange: string; + static darkorchid: string; + static darkred: string; + static darksalmon: string; + static darkseagreen: string; + static darkslateblue: string; + static darkslategray: string; + static darkslategrey: string; + static darkturquoise: string; + static darkviolet: string; + static deeppink: string; + static deepskyblue: string; + static dimgray: string; + static dimgrey: string; + static dodgerblue: string; + static firebrick: string; + static floralwhite: string; + static forestgreen: string; + static fuchsia: string; + static gainsboro: string; + static ghostwhite: string; + static gold: string; + static goldenrod: string; + static gray: string; + static green: string; + static greenyellow: string; + static grey: string; + static honeydew: string; + static hotpink: string; + static indianred: string; + static indigo: string; + static ivory: string; + static khaki: string; + static lavender: string; + static lavenderblush: string; + static lawngreen: string; + static lemonchiffon: string; + static lightblue: string; + static lightcoral: string; + static lightcyan: string; + static lightgoldenrodyellow: string; + static lightgray: string; + static lightgreen: string; + static lightgrey: string; + static lightpink: string; + static lightsalmon: string; + static lightseagreen: string; + static lightskyblue: string; + static lightslategray: string; + static lightslategrey: string; + static lightsteelblue: string; + static lightyellow: string; + static lime: string; + static limegreen: string; + static linen: string; + static magenta: string; + static maroon: string; + static mediumaquamarine: string; + static mediumblue: string; + static mediumorchid: string; + static mediumpurple: string; + static mediumseagreen: string; + static mediumslateblue: string; + static mediumspringgreen: string; + static mediumturquoise: string; + static mediumvioletred: string; + static midnightblue: string; + static mintcream: string; + static mistyrose: string; + static moccasin: string; + static navajowhite: string; + static navy: string; + static oldlace: string; + static olive: string; + static olivedrab: string; + static orange: string; + static orangered: string; + static orchid: string; + static palegoldenrod: string; + static palegreen: string; + static paleturquoise: string; + static palevioletred: string; + static papayawhip: string; + static peachpuff: string; + static peru: string; + static pink: string; + static plum: string; + static powderblue: string; + static purple: string; + static red: string; + static rosybrown: string; + static royalblue: string; + static saddlebrown: string; + static salmon: string; + static sandybrown: string; + static seagreen: string; + static seashell: string; + static sienna: string; + static silver: string; + static skyblue: string; + static slateblue: string; + static slategray: string; + static slategrey: string; + static snow: string; + static springgreen: string; + static steelblue: string; + static tan: string; + static teal: string; + static thistle: string; + static tomato: string; + static turquoise: string; + static violet: string; + static wheat: string; + static white: string; + static whitesmoke: string; + static yellow: string; + static yellowgreen: string; + } + export class Euler { constructor(x?: number, y?: number, z?: number, order?: string); @@ -2701,17 +2937,10 @@ declare module THREE { * m.multiply( m3 ); */ export class Matrix4 implements Matrix { - - /** - * Creates an identity matrix. - */ - constructor(); - - /** * Initialises the matrix with the supplied n11..n44 values. */ - constructor(n11: number, n12: number, n13: number, n14: number, n21: number, n22: number, n23: number, n24: number, n31: number, n32: number, n33: number, n34: number, n41: number, n42: number, n43: number, n44: number); + constructor(n11?: number, n12?: number, n13?: number, n14?: number, n21?: number, n22?: number, n23?: number, n24?: number, n31?: number, n32?: number, n33?: number, n34?: number, n41?: number, n42?: number, n43?: number, n44?: number); /** * Float32Array with matrix values. @@ -2936,11 +3165,11 @@ declare module THREE { * Copies values of q to this quaternion. */ copy(q: Quaternion): Quaternion; - setFromEuler(euler: Euler, update?: boolean): Quaternion; + /** * Sets this quaternion from rotation specified by Euler angles. */ - setFromEuler(v: Vector3, order: string): Quaternion; + setFromEuler(euler: Euler, update?: boolean): Quaternion; /** * Sets this quaternion from rotation specified by axis and angle. @@ -2997,6 +3226,8 @@ declare module THREE { equals(v: Quaternion): boolean; + dot(v: Vector3): number; + lengthSq(): number; fromArray(n: number[]): Quaternion; @@ -3021,10 +3252,12 @@ declare module THREE { equals(ray: Ray): boolean; intersectBox(box: Box3, optionalTarget?: Vector3): Vector3; intersectPlane(plane: Plane, optionalTarget?: Vector3): Vector3; + intersectSphere(sphere: Sphere, optionalTarget?: Vector3): Vector3; intersectTriangle(a: Vector3, b: Vector3, c: Vector3, backfaceCulling: boolean, optionalTarget?: Vector3): Vector3; isIntersectionBox(box: Box3): boolean; isIntersectionPlane(plane: Plane): boolean; isIntersectionSphere(sphere: Sphere): boolean; + recast(t: number): Ray; set(origin: Vector3, direction: Vector3): Ray; } @@ -3296,6 +3529,8 @@ declare module THREE { */ negate(): Vector2; + + /** * Computes dot product of this vector and v. */ @@ -3715,14 +3950,13 @@ declare module THREE { export class Bone extends Object3D { constructor(belongsToSkin: SkinnedMesh); - skinMatrix: Matrix4; skin: SkinnedMesh; accumulatedRotWeight: number; accumulatedPosWeight: number; accumulatedSclWeight: number; - update(parentSkinMatrix?: Matrix4, forceUpdate?: boolean): void; + update(forceUpdate?: boolean): void; } export class Line extends Object3D { @@ -3733,8 +3967,10 @@ declare module THREE { constructor(geometry?: BufferGeometry, material?: LineBasicMaterial, type?: number); constructor(geometry?: BufferGeometry, material?: ShaderMaterial, type?: number); geometry: Geometry; - material: Material; + material: LineBasicMaterial; type: LineType; + + raycast(raycaster: Raycaster, intersects: any): void; clone(object?: Line): Line; } @@ -3748,6 +3984,7 @@ declare module THREE { objects: any[]; addLevel(object: Object3D, distance?: number): void; getObjectForDistance(distance: number): Object3D; + raycast(raycaster: Raycaster, intersects: any): void; update(camera: Camera): void; clone(): LOD; } @@ -3761,6 +3998,7 @@ declare module THREE { getMorphTargetIndexByName(name: string): number; updateMorphTargets(): void; + raycast(raycaster: Raycaster, intersects: any): void; clone(object?: Mesh): Mesh; } @@ -3791,7 +4029,7 @@ declare module THREE { parseAnimations(): void; updateAnimation(delta: number): void; setAnimationLabel(label: string, start: number, end: number): void; - + interpolateTargets( a: number, b: number, t: number ): void; clone(object?: MorphAnimMesh): MorphAnimMesh; } @@ -3800,15 +4038,15 @@ declare module THREE { * * @see src/objects/ParticleSystem.js */ - export class ParticleSystem extends Object3D { + export class PointCloud extends Object3D { /** * @param geometry An instance of Geometry. * @param material An instance of Material (optional). */ - constructor(geometry: Geometry, material?: ParticleSystemMaterial); + constructor(geometry: Geometry, material?: PointCloudMaterial); constructor(geometry: Geometry, material?: ShaderMaterial); - constructor(geometry: BufferGeometry, material?: ParticleSystemMaterial); + constructor(geometry: BufferGeometry, material?: PointCloudMaterial); constructor(geometry: BufferGeometry, material?: ShaderMaterial); /** @@ -3821,24 +4059,21 @@ declare module THREE { */ material: Material; - /** - * Specifies whether the particle system will be culled if it's outside the camera's frustum. By default this is set to false. - */ - frustrumCulled: boolean; - sortParticles: boolean; - clone(object?: ParticleSystem): ParticleSystem; + raycast(raycaster: Raycaster, intersects: any): void; + clone(object?: PointCloud): PointCloud; } export class Skeleton extends Mesh { - constructor(boneList: Bone[], useVertexTexture: boolean); + constructor(bones: Bone[], boneInverses?: Matrix4[], useVertexTexture?: boolean); bones: Bone[]; useVertexTexture: boolean; boneMatrices: Float32Array; - addBone(bone: Bone): Bone; calculateInverses(bone: Bone): void; + pose(): void; + update(): void; } export class SkinnedMesh extends Mesh { @@ -3850,10 +4085,14 @@ declare module THREE { constructor(geometry?: Geometry, material?: MeshPhongMaterial, useVertexTexture?: boolean); constructor(geometry?: Geometry, material?: ShaderMaterial, useVertexTexture?: boolean); - identityMatrix: Matrix4; + bindMode: string; + bindMatrix: Matrix4; + bindMatrixInverse: Matrix4; + bind( skeleton: Skeleton, bindMatrix?: Matrix4 ): void; pose(): void; normalizeSkinWeights(): void; + updateMatrixWorld(force?: boolean): void; clone(object?: SkinnedMesh): SkinnedMesh; } @@ -3863,6 +4102,7 @@ declare module THREE { geometry: BufferGeometry; material: SpriteMaterial; + raycast(raycaster: Raycaster, intersects: any): void; updateMatrix(): void; clone(object?: Sprite): Sprite; } @@ -3899,6 +4139,8 @@ declare module THREE { supportsVertexTextures(): void; setSize(width: number, height: number, updateStyle?: boolean): void; setClearColorHex(hex: number, alpha?: number): void; + getClearColor(): Color; + getClearAlpha(): number; setViewport(x: number, y: number, width: number, height: number): void; } @@ -4319,6 +4561,7 @@ declare module THREE { copy(vertex: RenderableVertex): void; } + // Renderers / Shaders ///////////////////////////////////////////////////////////////////// // Renderers / Shaders ///////////////////////////////////////////////////////////////////// export interface ShaderChunk { [name: string]: string; @@ -4514,6 +4757,24 @@ declare module THREE { clone(): CompressedTexture; } + export class CubeTexture extends Texture { + constructor( + images: any[], // HTMLImageElement or HTMLCanvasElement + mapping?: Mapping, + wrapS?: Wrapping, + wrapT?: Wrapping, + magFilter?: TextureFilter, + minFilter?: TextureFilter, + format?: PixelFormat, + type?: TextureDataType, + anisotropy?: number + ); + + images: any[]; + + clone(texture?: CubeTexture): CubeTexture; + } + export class DataTexture extends Texture { constructor( data: ImageData, @@ -4601,6 +4862,9 @@ declare module THREE { clone(): Texture; dispose(): void; + + DEFAULT_IMAGE: any; + DEFAULT_MAPPING: any; } // Extras ///////////////////////////////////////////////////////////////////// @@ -4634,12 +4898,11 @@ declare module THREE { export var GeometryUtils: { // DEPRECATED merge(geometry1: Geometry, object2: Mesh, materialIndexOffset?: number): void; + // DEPRECATED merge(geometry1: Geometry, object2: Geometry, materialIndexOffset?: number): void; - randomPointInTriangle(vectorA: Vector3, vectorB: Vector3, vectorC: Vector3): Vector3; - randomPointInFace(face: Face3, geometry: Geometry, useCachedAreas: boolean): Vector3; - randomPointsInGeometry(geometry: Geometry, points: number): Vector3; - triangleArea(vectorA: Vector3, vectorB: Vector3, vectorC: Vector3): number; + + // DEPRECATED center(geometry: Geometry): Vector3; }; @@ -4647,12 +4910,9 @@ declare module THREE { crossOrigin: string; generateDataTexture(width: number, height: number, color: Color): DataTexture; - parseDDS(buffer: ArrayBuffer, loadMipmaps: boolean): { mipmaps: { data: Uint8Array; width: number; height: number; }[]; width: number; height: number; format: number; mipmapCount: number; }; - loadCompressedTexture(url: string, mapping?: Mapping, onLoad?: (texture: Texture) => void, onError?: (message: string) => void): Texture; loadTexture(url: string, mapping?: Mapping, onLoad?: (texture: Texture) => void, onError?: (message: string) => void): Texture; - getNormalMap(image: HTMLImageElement, depth?: number): HTMLCanvasElement; - loadCompressedTextureCube(array: string[], mapping?: Mapping, onLoad?: () => void, onError?: (message: string) => void): Texture; loadTextureCube(array: string[], mapping?: Mapping, onLoad?: () => void , onError?: (message: string) => void ): Texture; + getNormalMap(image: HTMLImageElement, depth?: number): HTMLCanvasElement; }; export var SceneUtils: { @@ -4684,7 +4944,7 @@ declare module THREE { } export class Animation { - constructor(root: Mesh, name: string); + constructor(root: Mesh, data: AnimationData); root: Mesh; data: AnimationData; @@ -4692,37 +4952,37 @@ declare module THREE { currentTime: number; timeScale: number; isPlaying: boolean; - isPaused: boolean; loop: boolean; weight: number; - interpolationType: AnimationInterpolation; keyTypes: string[]; play(startTime?: number, weight?: number): void; - pause(): void; stop(): void; reset(): void; update(deltaTimeMS: number): void; - interpolateCatmullRom(points: Vector3[], scale: number): Vector3[]; - interpolate(p0: number, p1: number, p2: number, p3: number, t: number, t2: number, t3: number): number; - getNextKeyWith(type: string, h: number, key: number): KeyFrame; // ???? + getNextKeyWith(type: string, h: number, key: number): KeyFrame; getPrevKeyWith(type: string, h: number, key: number): KeyFrame; } - export class AnimationInterpolation { } - export var AnimationHandler: { - CATMULLROM: AnimationInterpolation; - CATMULLROM_FORWARD: AnimationInterpolation; - LINEAR: AnimationInterpolation; + LINEAR: number; + CATMULLROM: number; + CATMULLROM_FORWARD: number; - remove(name: string): void; - removeFromUpdate(animation: Animation): void; - get(name: string): AnimationData; - update(deltaTimeMS: number): void; + animations: any[]; + + init(data: Animation): void; parse(root: Mesh): Object3D[]; + play(animation: Animation): void; + stop(animation: Animation): void; + update(deltaTimeMS: number): void; + + // deprecated add(data: AnimationData): void; - addToUpdate(animation: Animation): void; + // deprecated + get(name: string): AnimationData; + // deprecated + remove(name: string): void; }; export class MorphAnimation { @@ -4741,7 +5001,7 @@ declare module THREE { } export class KeyFrameAnimation { - constructor(root: Mesh, data: any, JITCompile?: boolean); + constructor(data: any); root: Mesh; data: Object; @@ -4753,55 +5013,13 @@ declare module THREE { loop: number; JITCompile: boolean; - play(loop?: number, startTimeMS?: number): void; - pause(): void; + play(startTime?: number): void; stop(): void; - update(deltaTimeMS: number): void; - interpolateCatmullRom(points: Vector3[], scale: number): Vector3[]; - getNextKeyWith(type: string, h: number, key: number): KeyFrame; // ???? + update(delta: number): void; + getNextKeyWith(type: string, h: number, key: number): KeyFrame; getPrevKeyWith(type: string, h: number, key: number): KeyFrame; } - // Extras / Cameras ///////////////////////////////////////////////////////////////////// - - export class CombinedCamera extends Camera { - constructor(width: number, height: number, fov: number, near: number, far: number, orthoNear: number, orthoFar: number); - - fov: number; - right: number; - bottom: number; - cameraP: PerspectiveCamera; - top: number; - zoom: number; - far: number; - near: number; - inPerspectiveMode: boolean; - cameraO: OrthographicCamera; - inOrthographicMode: boolean; - left: number; - - toBottomView(): void; - setFov(fov: number): void; - toBackView(): void; - setZoom(zoom: number): void; - setLens(focalLength: number, frameHeight?: number): number; - toFrontView(): void; - toLeftView(): void; - updateProjectionMatrix(): void; - toTopView(): void; - toOrthographic(): void; - setSize(width: number, height: number): void; - toPerspective(): void; - toRightView(): void; - } - - export class CubeCamera extends Object3D { - constructor(near: number, far: number, cubeResolution: number); - - renderTarget: WebGLRenderTargetCube; - updateCubeMap(renderer: Renderer, scene: Scene): void; - } - // Extras / Curves ///////////////////////////////////////////////////////////////////// export class ArcCurve extends EllipseCurve { constructor(aX: number, aY: number, xRadius: number, yRadius: number, aStartAngle: number, aEndAngle: number, aClockwise: boolean ); @@ -5310,11 +5528,13 @@ declare module THREE { } export class SkeletonHelper extends Line { - constructor(bone: Bone); + constructor(bone: Object3D); - skeleton: Skeleton; + bones: Bone[]; + root: Object3D; + matrixWorld: Matrix4; matrixAutoUpdate: boolean; - + getBoneList(object: Object3D): Bone[]; update(): void; } From 1086c1fac6fcbd8f7455aa78d4e7e66d6c1e9051 Mon Sep 17 00:00:00 2001 From: Evgenus Date: Sun, 3 Aug 2014 15:16:57 +0300 Subject: [PATCH 06/11] definitions for BigInt by Baird Leemon. distribution source: https://github.com/Evgenus/BigInt original source: http://www.leemon.com/crypto/BigInt.html --- CONTRIBUTORS.md | 1 + bigint/bigint-tests.ts | 81 ++++++++++++++ bigint/bigint.d.ts | 245 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 327 insertions(+) create mode 100644 bigint/bigint-tests.ts create mode 100644 bigint/bigint.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index af326634b..eab14f2c5 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -31,6 +31,7 @@ All definitions files include a header with the author and editors, so at some p * [Backbone.js](http://backbonejs.org/) (by [Boris Yankov](https://github.com/borisyankov)) * [Backbone Relational](http://backbonerelational.org/) (by [Eirik Hoem](https://github.com/eirikhm)) * [big.js](https://github.com/MikeMcl/big.js) (by [Steve Ognibene](https://github.com/nycdotnet)) +* [BigInt](https://github.com/Evgenus/BigInt) (by [Eugene Chernyshov](https://github.com/Evgenus)) * [BigInteger](https://github.com/peterolson/BigInteger.js) (by [Ingo Bürk](https://github.com/Airblader)) * [BigScreen](http://brad.is/coding/BigScreen/) (by [Douglas Eichelberger](https://github.com/dduugg)) * [Bluebird](https://github.com/petkaantonov/bluebird) (by [Bart van der Schoor](https://github.com/Bartvds)) diff --git a/bigint/bigint-tests.ts b/bigint/bigint-tests.ts new file mode 100644 index 000000000..8ccf2ba4b --- /dev/null +++ b/bigint/bigint-tests.ts @@ -0,0 +1,81 @@ +/// + +var bi: BigInt.BigInt; +var num: number; +var str: string; +var b: boolean; + +BigInt.setRandom(() => { return 0; }); + +bi = BigInt.add(bi, bi); +bi = BigInt.addInt(bi, num); +str = BigInt.bigInt2str(bi, num); +str = BigInt.bigInt2str(bi, str); +num = BigInt.bitSize(bi); +bi = BigInt.dup(bi); +b = BigInt.equals(bi, bi); +b = BigInt.equalsInt(bi, num); +bi = BigInt.expand(bi, num); +var nums: number[] = BigInt.findPrimes(num); +bi = BigInt.GCD(bi, bi); +b = BigInt.greater(bi, bi); +b = BigInt.greaterShift(bi, bi, num); +bi = BigInt.int2bigInt(0); +bi = BigInt.int2bigInt(0, 0); +bi = BigInt.int2bigInt(0, 0, 0); +bi = BigInt.inverseMod(bi, bi); +bi = BigInt.inverseModInt(num, num); +b = BigInt.isZero(bi); +b = BigInt.millerRabin(bi, bi); +b = BigInt.millerRabinInt(num, num); +bi = BigInt.mod(bi, bi); +num = BigInt.modInt(bi, num); +bi = BigInt.mult(bi, bi); +bi = BigInt.multMod(bi, bi, bi); +b = BigInt.negative(bi); +bi = BigInt.powMod(bi, bi, bi); +bi = BigInt.randBigInt(num, num); +bi = BigInt.randTruePrime(num); +bi = BigInt.randProbPrime(num); +bi = BigInt.str2bigInt(str, num); +bi = BigInt.str2bigInt(str, num, 0); +bi = BigInt.str2bigInt(str, num, 0, 0); +bi = BigInt.str2bigInt(str, str); +bi = BigInt.str2bigInt(str, str, 0); +bi = BigInt.str2bigInt(str, str, 0, 0); +bi = BigInt.sub(bi, bi); +bi = BigInt.trim(bi, num); + +BigInt.addInt_(bi, num); +BigInt.add_(bi, bi); +BigInt.copy_(bi, bi); +num = BigInt.copyInt_(bi, num); +BigInt.GCD_(bi, bi); +b = BigInt.inverseMod_(bi, bi); +BigInt.mod_(bi, bi); +BigInt.mult_(bi, bi); +BigInt.multMod_(bi, bi, bi); +BigInt.powMod_(bi, bi, bi); +BigInt.randBigInt_(bi, num, num); +BigInt.randTruePrime_(bi, num); +BigInt.sub_(bi, bi); +BigInt.addShift_(bi, bi, num); +BigInt.carry_(bi); +BigInt.divide_(bi, bi, bi, bi); +num = BigInt.divInt_(bi, num); +BigInt.eGCD_(bi, bi, bi, bi, bi); +BigInt.halve_(bi); +BigInt.leftShift_(bi, num); +BigInt.linComb_(bi, bi, num, num); +BigInt.linCombShift_(bi, bi, num, num); +BigInt.mont_(bi, bi, bi, num); +BigInt.multInt_(bi, num); +BigInt.rightShift_(bi, num); +BigInt.squareMod_(bi, bi); +BigInt.subShift_(bi, bi, num); + +function someRandomRealCode() { + bi = BigInt.int2bigInt(22, 5); + bi = BigInt.str2bigInt("FFFFFFFFFFFFFFFFC90FDAA2", 16); + str = BigInt.bigInt2str(bi, 16); +} diff --git a/bigint/bigint.d.ts b/bigint/bigint.d.ts new file mode 100644 index 000000000..61543b1c6 --- /dev/null +++ b/bigint/bigint.d.ts @@ -0,0 +1,245 @@ +// Type definitions for BigInt v5.5.1 +// Project: https://github.com/Evgenus/BigInt +// Definitions by: Eugene Chernyshov +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module BigInt { + export interface BigInt extends Array { + } + + export interface IRandom { + (): number; + } + + export function setRandom(random: IRandom): void; + + // bigInt add(x,y) + // return (x+y) for bigInts x and y. + export function add(x: BigInt, y: BigInt): BigInt; + + // bigInt addInt(x,n) + // return (x+n) where x is a bigInt and n is an integer. + export function addInt(x: BigInt, n: number): BigInt; + + // string bigInt2str(x,base) + // return a string form of bigInt x in a given base, with 2 <= base <= 95 + export function bigInt2str(x: BigInt, base: number): string; + export function bigInt2str(x: BigInt, base: string): string; + + // int bitSize(x) + // return how many bits long the bigInt x is, not counting leading zeros + export function bitSize(x: BigInt): number; + + // bigInt dup(x) + // return a copy of bigInt x + export function dup(x: BigInt): BigInt; + + // boolean equals(x,y) + // is the bigInt x equal to the bigint y? + export function equals(x: BigInt, y: BigInt): boolean; + + // boolean equalsInt(x,y) + // is bigint x equal to integer y? + export function equalsInt(x: BigInt, y: number): boolean; + + // bigInt expand(x,n) + // return a copy of x with at least n elements, adding leading zeros if needed + export function expand(value: BigInt, n: number): BigInt; + + // Array findPrimes(n) + // return array of all primes less than integer n + export function findPrimes(n: number): number[]; + + // bigInt GCD(x,y) + // return greatest common divisor of bigInts x and y (each with same number of elements). + export function GCD(x: BigInt, y: BigInt): BigInt; + + // boolean greater(x,y) + // is x>y? (x and y are nonnegative bigInts) + export function greater(x: BigInt, y: BigInt): boolean; + + // boolean greaterShift(x,y,shift) + // is (x <<(shift*bpe)) > y? + export function greaterShift(x: BigInt, y: BigInt, shift: number): boolean; + + // bigInt int2bigInt(t,n,m) + // return a bigInt equal to integer t, with at least n bits and m array elements + export function int2bigInt(t: number, n?: number, m?: number): BigInt; + + // bigInt inverseMod(x,n) + // return (x**(-1) mod n) for bigInts x and n. If no inverse exists, it returns null + export function inverseMod(x: BigInt, n: BigInt): BigInt; + + // int inverseModInt(x,n) + // return x**(-1) mod n, for integers x and n. Return 0 if there is no inverse + export function inverseModInt(x: number, n: number): BigInt; + + // boolean isZero(x) + // is the bigInt x equal to zero? + export function isZero(x: BigInt): boolean; + + // boolean millerRabin(x,b) + // does one round of Miller-Rabin base integer b say that bigInt x is possibly prime? (b is bigInt, 1=1). If s=1, then the most significant of those n bits is set to 1. + export function randBigInt(n: number, s: number): BigInt; + + // bigInt randTruePrime(k) + // return a new, random, k-bit, true prime bigInt using Maurer's algorithm. + export function randTruePrime(k: number): BigInt; + + // bigInt randProbPrime(k) + // return a new, random, k-bit, probable prime bigInt (probability it's composite less than 2^-80). + export function randProbPrime(k: number): BigInt; + + // bigInt str2bigInt(s,b,n,m) + // return a bigInt for number represented in string s in base b with at least n bits and m array elements + export function str2bigInt(s: string, b: number, n?: number, m?: number): BigInt; + export function str2bigInt(s: string, b: string, n?: number, m?: number): BigInt; + + // bigInt sub(x,y) + // return (x-y) for bigInts x and y. Negative answers will be 2s complement + export function sub(x: BigInt, y: BigInt): BigInt; + + // bigInt trim(x,k) + // return a copy of x with exactly k leading zero elements + export function trim(x: BigInt, k: number): BigInt; + + // void addInt_(x,n) + // do x=x+n where x is a bigInt and n is an integer + export function addInt_(x: BigInt, n: number): void; + + // void add_(x,y) + // do x=x+y for bigInts x and y + export function add_(x: BigInt, y: BigInt): void; + + // void copy_(x,y) + // do x=y on bigInts x and y + export function copy_(x: BigInt, y: BigInt): void; + + // void copyInt_(x,n) + // do x=n on bigInt x and integer n + export function copyInt_(x: BigInt, n: number): number; + + // void GCD_(x,y) + // set x to the greatest common divisor of bigInts x and y, (y is destroyed). (This never overflows its array). + export function GCD_(x: BigInt, y: BigInt): void; + + // boolean inverseMod_(x,n) + // do x=x**(-1) mod n, for bigInts x and n. Returns 1 (0) if inverse does (doesn't) exist + export function inverseMod_(x: BigInt, n: BigInt): boolean; + + // void mod_(x,n) + // do x=x mod n for bigInts x and n. (This never overflows its array). + export function mod_(x: BigInt, n: BigInt): void; + + // void mult_(x,y) + // do x=x*y for bigInts x and y. + export function mult_(x: BigInt, y: BigInt): void; + + // void multMod_(x,y,n) + // do x=x*y mod n for bigInts x,y,n. + export function multMod_(x: BigInt, y: BigInt, n: BigInt): void; + + // void powMod_(x,y,n) + // do x=x**y mod n, where x,y,n are bigInts (n is odd) and ** is exponentiation. 0**0=1. + export function powMod_(x: BigInt, y: BigInt, n: BigInt): void; + + // void randBigInt_(b,n,s) + // do b = an n-bit random BigInt. if s=1, then nth bit (most significant bit) is set to 1. n>=1. + export function randBigInt_(b: BigInt, n: number, s: number): void; + + // void randTruePrime_(ans,k) + // do ans = a random k-bit true random prime (not just probable prime) with 1 in the msb. + export function randTruePrime_(ans: BigInt, k: number): void; + + // void sub_(x,y) + // do x=x-y for bigInts x and y. Negative answers will be 2s complement. + export function sub_(x: BigInt, y: BigInt): void; + + // void addShift_(x,y,ys) + // do x=x+(y<<(ys*bpe)) + export function addShift_(x: BigInt, y: BigInt, ys: number): void; + + // void carry_(x) + // do carries and borrows so each element of the bigInt x fits in bpe bits. + export function carry_(x: BigInt): void; + + // void divide_(x,y,q,r) + // divide x by y giving quotient q and remainder r + export function divide_(x: BigInt, y: BigInt, q: BigInt, r: BigInt): void; + + // int divInt_(x,n) + // do x=floor(x/n) for bigInt x and integer n, and return the remainder. (This never overflows its array). + export function divInt_(x: BigInt, n: number): number; + + // void eGCD_(x,y,d,a,b) + // sets a,b,d to positive bigInts such that d = GCD_(x,y) = a*x-b*y + export function eGCD_(x: BigInt, y: BigInt, d: BigInt, a: BigInt, b: BigInt): void; + + // void halve_(x) + // do x=floor(|x|/2)*sgn(x) for bigInt x in 2's complement. (This never overflows its array). + export function halve_(x: BigInt): void; + + // void leftShift_(x,n) + // left shift bigInt x by n bits. n Date: Sun, 3 Aug 2014 15:43:21 +0300 Subject: [PATCH 07/11] definitions for Stanford Javascript Crypto Library --- CONTRIBUTORS.md | 1 + sjcl/sjcl-tests.ts | 267 ++++++++++++++++++++++ sjcl/sjcl.d.ts | 556 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 824 insertions(+) create mode 100644 sjcl/sjcl-tests.ts create mode 100644 sjcl/sjcl.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index af326634b..bf47e04a9 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -306,6 +306,7 @@ All definitions files include a header with the author and editors, so at some p * [SignalR](http://www.asp.net/signalr) (by [Boris Yankov](https://github.com/borisyankov)) * [simple-cw-node](https://github.com/astronaughts/simple-cw-node) (by [vvakame](https://github.com/vvakame)) * [Sinon](http://sinonjs.org/) (by [William Sears](https://github.com/mrbigdog2u)) +* [sjcl](http://crypto.stanford.edu/sjcl/) (by [Eugene Chernyshov](https://github.com/Evgenus)) * [SlickGrid](https://github.com/mleibman/SlickGrid) (by [Josh Baldwin](https://github.com/jbaldwin)) * [smoothie](https://github.com/joewalnes/smoothie) (by [Mike H. Hawley](https://github.com/mikehhawley) and [Drew Noakes](https://drewnoakes.com)) * [socket.io](http://socket.io) (by [William Orr](https://github.com/worr)) diff --git a/sjcl/sjcl-tests.ts b/sjcl/sjcl-tests.ts new file mode 100644 index 000000000..4ff603203 --- /dev/null +++ b/sjcl/sjcl-tests.ts @@ -0,0 +1,267 @@ +/// + +var b: boolean; +var n: number; +var s: string; +var bn: sjcl.BigNumber; +var ba: sjcl.BitArray; + +function testBigNumber() { + bn = new sjcl.bn(); + bn = new sjcl.bn(0); + bn = new sjcl.bn("0"); + bn = new sjcl.bn(bn); + + bn = bn.initWith(0); + bn = bn.initWith("0"); + bn = bn.initWith(bn); + + bn = bn.addM(0); + bn = bn.addM("0"); + bn = bn.addM(bn); + + bn = bn.subM(0); + bn = bn.subM("0"); + bn = bn.subM(bn); + + bn = bn.mod(0); + bn = bn.mod("0"); + bn = bn.mod(bn); + + bn = bn.inverseMod(0); + bn = bn.inverseMod("0"); + bn = bn.inverseMod(bn); + + bn = bn.add(0); + bn = bn.add("0"); + bn = bn.add(bn); + + bn = bn.sub(0); + bn = bn.sub("0"); + bn = bn.sub(bn); + + bn = bn.mul(0); + bn = bn.mul("0"); + bn = bn.mul(bn); + + bn = bn.mulmod(0, 0); + bn = bn.mulmod(0, "0"); + bn = bn.mulmod(0, bn); + bn = bn.mulmod("0", 0); + bn = bn.mulmod("0", "0"); + bn = bn.mulmod("0", bn); + bn = bn.mulmod(bn, 0); + bn = bn.mulmod(bn, "0"); + bn = bn.mulmod(bn, bn); + + bn = bn.powermod(0, 0); + bn = bn.powermod(0, "0"); + bn = bn.powermod(0, bn); + bn = bn.powermod("0", 0); + bn = bn.powermod("0", "0"); + bn = bn.powermod("0", bn); + bn = bn.powermod(bn, 0); + bn = bn.powermod(bn, "0"); + bn = bn.powermod(bn, bn); + + bn = bn.copy(); + + b = bn.equals(0); + b = bn.equals(bn); + + b = bn.greaterEquals(0); + b = bn.greaterEquals(bn); + + n = bn.getLimb(0); + + s = bn.toString(); + + bn = bn.doubleM(); + + bn = bn.halveM(); + + bn = bn.square(); + + bn = bn.power(1); + bn = bn.power([1, 1]); + bn = bn.power(bn); + + bn = bn.trim(); + + bn = bn.reduce(); + + bn = bn.fullReduce(); + + bn = bn.normalize(); + + bn = bn.cnormalize(); + + ba = bn.toBits(); + ba = bn.toBits(1); + + n = bn.bitLength(); + + bn = sjcl.bn.fromBits(ba); +} + +function testBitArray() { + ba = sjcl.bitArray.bitSlice(ba, 0, 1); + + n = sjcl.bitArray.extract(ba, 0, 1); + + ba = sjcl.bitArray.concat(ba, ba); + + n = sjcl.bitArray.bitLength(ba); + + ba = sjcl.bitArray.clamp(ba, 0); + + n = sjcl.bitArray.partial(1, 1); + n = sjcl.bitArray.partial(1, 1, 0); + + n = sjcl.bitArray.getPartial(0); + + b = sjcl.bitArray.equal(ba, ba); + + ba = sjcl.bitArray._shiftRight(ba, 0); + ba = sjcl.bitArray._shiftRight(ba, 0, 0); + ba = sjcl.bitArray._shiftRight(ba, 0, 0, ba); +} + +function testCodecs() { + s = sjcl.codec.base64.fromBits(ba); + ba = sjcl.codec.base64.toBits(s); + + s = sjcl.codec.base64url.fromBits(ba); + ba = sjcl.codec.base64url.toBits(s); + + s = sjcl.codec.hex.fromBits(ba); + ba = sjcl.codec.hex.toBits(s); + + s = sjcl.codec.utf8String.fromBits(ba); + ba = sjcl.codec.utf8String.toBits(s); + + var bytes: number[] = sjcl.codec.bytes.fromBits(ba); + ba = sjcl.codec.bytes.toBits(bytes); +} + +function testHashes() { + var hash: sjcl.SjclHash; + ba = hash.reset().update("xxx").update(ba).finalize(); + + hash = new sjcl.hash.sha1(); + hash = new sjcl.hash.sha1(hash); + ba = sjcl.hash.sha1.hash(ba); + ba = sjcl.hash.sha1.hash("xxx"); + + hash = new sjcl.hash.sha256(); + hash = new sjcl.hash.sha256(hash); + ba = sjcl.hash.sha256.hash(ba); + ba = sjcl.hash.sha256.hash("xxx"); + + hash = new sjcl.hash.sha512(); + hash = new sjcl.hash.sha512(hash); + ba = sjcl.hash.sha512.hash(ba); + ba = sjcl.hash.sha512.hash("xxx"); +} + +function testSymetric() { + var aes = new sjcl.cipher.aes([0, 0, 0, 0]); + + ba = sjcl.mode.cbc.encrypt(aes, ba, ba); + ba = sjcl.mode.cbc.encrypt(aes, ba, ba, ba); + + ba = sjcl.mode.gcm.encrypt(aes, ba, ba); + ba = sjcl.mode.gcm.encrypt(aes, ba, ba, ba); + ba = sjcl.mode.gcm.encrypt(aes, ba, ba, ba, 128); + + ba = sjcl.mode.ccm.encrypt(aes, ba, ba); + ba = sjcl.mode.ccm.encrypt(aes, ba, ba, ba); + ba = sjcl.mode.ccm.encrypt(aes, ba, ba, ba, 128); + + ba = sjcl.mode.ocb2.encrypt(aes, ba, ba); + ba = sjcl.mode.ocb2.encrypt(aes, ba, ba, ba); + ba = sjcl.mode.ocb2.encrypt(aes, ba, ba, ba, 128); + ba = sjcl.mode.ocb2.encrypt(aes, ba, ba, ba, 128, false); +} + +function testHmacPbdkf2() { + ba = sjcl.misc.pbkdf2("xxx", "xxx"); + ba = sjcl.misc.pbkdf2("xxx", "xxx", 1000); + ba = sjcl.misc.pbkdf2("xxx", "xxx", 1000, 12); + ba = sjcl.misc.pbkdf2("xxx", "xxx", 1000, 12, sjcl.misc.hmac); + + ba = sjcl.misc.pbkdf2("xxx", ba); + ba = sjcl.misc.pbkdf2("xxx", ba, 1000); + ba = sjcl.misc.pbkdf2("xxx", ba, 1000, 12); + ba = sjcl.misc.pbkdf2("xxx", ba, 1000, 12, sjcl.misc.hmac); + + ba = sjcl.misc.pbkdf2(ba, "xxx"); + ba = sjcl.misc.pbkdf2(ba, "xxx", 1000); + ba = sjcl.misc.pbkdf2(ba, "xxx", 1000, 12); + ba = sjcl.misc.pbkdf2(ba, "xxx", 1000, 12, sjcl.misc.hmac); + + ba = sjcl.misc.pbkdf2(ba, ba); + ba = sjcl.misc.pbkdf2(ba, ba, 1000); + ba = sjcl.misc.pbkdf2(ba, ba, 1000, 12); + ba = sjcl.misc.pbkdf2(ba, ba, 1000, 12, sjcl.misc.hmac); + + var hmac: sjcl.SjclHmac; + hmac = new sjcl.misc.hmac(ba); + hmac = new sjcl.misc.hmac(ba, sjcl.hash.sha512); + + ba = hmac.mac("xxx"); + ba = hmac.mac(ba); + + ba = hmac.encrypt("xxx"); + ba = hmac.encrypt(ba); + + hmac.reset(); + + hmac.update("xxx"); + hmac.update(ba); + + ba = hmac.digest(); +} + +function testECC() { + var keys = sjcl.ecc.elGamal.generateKeys(192, 0); + + var ciphertext = sjcl.encrypt(keys.pub, "hello world"); + var plaintext = sjcl.decrypt(keys.sec, ciphertext); + + // TODO: Maybe deeper testing required. Let me know +} + +function testRandom() { + b = sjcl.random.isReady(); + ba = sjcl.random.randomWords(8); + ba = sjcl.random.randomWords(8, 6); + + var rnd = new sjcl.prng(1); + ba = rnd.randomWords(16); + ba = rnd.randomWords(16, 6); +} + +function testSRP() { + var group = sjcl.keyexchange.srp.knownGroup(1024); + ba = sjcl.codec.hex.toBits(s); + ba = sjcl.keyexchange.srp.makeX(s, s, ba); + ba = sjcl.keyexchange.srp.makeVerifier(s, s, ba, group); +} + +function testConvenince() { + var x: sjcl.SjclCipherEncrypted; + x = sjcl.encrypt("xxx", "text"); + s = sjcl.decrypt(ba, x); + + x = sjcl.encrypt("xxx", "text", { iv: ba, salt: ba }); + s = sjcl.decrypt(ba, x, { iv: ba, salt: ba }); + + var y: sjcl.SjclCipherDecrypted; + + sjcl.encrypt("xxx", "text", { iv: ba, salt: ba, mode: "gcm" }, x); + s = sjcl.decrypt(ba, x, { iv: ba, salt: ba, mode: "gcm" }, y); + + sjcl.encrypt("xxx", "text", { iv: ba, salt: ba, mode: "gcm", iter: 200 }, x); + s = sjcl.decrypt(ba, x, { iv: ba, salt: ba, mode: "gcm", iter: 200 }, y); +} \ No newline at end of file diff --git a/sjcl/sjcl.d.ts b/sjcl/sjcl.d.ts new file mode 100644 index 000000000..8413edb2f --- /dev/null +++ b/sjcl/sjcl.d.ts @@ -0,0 +1,556 @@ +// Type definitions for sjcl v1.0.1 +// Project: http://crypto.stanford.edu/sjcl/ +// Definitions by: Eugene Chernyshov +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module sjcl { + + export var bn: BigNumberStatic; + export var bitArray: BitArrayStatic; + export var codec: SjclCodecs; + export var hash: SjclHashes; + export var exception: SjclExceptions; + export var cipher: SjclCiphers; + export var mode: SjclModes; + export var misc: SjclMisc; + export var ecc: SjclEllipticCurveCryptography; + export var random: SjclRandom; + export var prng: SjclRandomStatic; + export var keyexchange: SjclKeyExchange; + export var json: SjclJson; + export var encrypt: SjclConveninceEncryptor; + export var decrypt: SjclConveninceDecryptor; + + // ________________________________________________________________________ + + interface BigNumber { + radix: number; + maxMul: number; + + copy(): BigNumber; + + /// Initializes this with it, either as a bn, a number, or a hex string. + initWith: TypeHelpers.BigNumberBinaryOperator; + + /// Returns true if "this" and "that" are equal. Calls fullReduce(). + /// Equality test is in constant time. + equals(that: number): boolean; + equals(that: BigNumber): boolean; + + /// Get the i'th limb of this, zero if i is too large. + getLimb(index: number): number; + + /// Constant time comparison function. + /// Returns 1 if this >= that, or zero otherwise. + greaterEquals(that: number): boolean; + greaterEquals(that: BigNumber): boolean; + + /// Convert to a hex string. + toString(): string; + + /// this += that. Does not normalize. + addM: TypeHelpers.BigNumberBinaryOperator; + + /// this *= 2. Requires normalized; ends up normalized. + doubleM(): BigNumber; + + /// this /= 2, rounded down. Requires normalized; ends up normalized. + halveM(): BigNumber; + + /// this -= that. Does not normalize. + subM: TypeHelpers.BigNumberBinaryOperator; + + mod: TypeHelpers.BigNumberBinaryOperator; + + /// return inverse mod prime p. p must be odd. Binary extended Euclidean algorithm mod p. + inverseMod: TypeHelpers.BigNumberBinaryOperator; + + /// this + that. Does not normalize. + add: TypeHelpers.BigNumberBinaryOperator; + + /// this - that. Does not normalize. + sub: TypeHelpers.BigNumberBinaryOperator; + + /// this * that. Normalizes and reduces. + mul: TypeHelpers.BigNumberBinaryOperator; + + /// this ^ 2. Normalizes and reduces. + square(): BigNumber; + + /// this ^ n. Uses square-and-multiply. Normalizes and reduces. + power(n: number): BigNumber; + power(n: BigNumber): BigNumber; + power(a: number[]): BigNumber; + + /// this * that mod N + mulmod: TypeHelpers.BigNumberTrinaryOperator; + + /// this ^ x mod N + powermod: TypeHelpers.BigNumberTrinaryOperator; + + trim(): BigNumber; + + /// Reduce mod a modulus. Stubbed for subclassing. + reduce(): BigNumber; + + /// Reduce and normalize. + fullReduce(): BigNumber; + + /// Propagate carries. + normalize(): BigNumber; + + /// Constant-time normalize. Does not allocate additional space. + cnormalize(): BigNumber; + + /// Serialize to a bit array + toBits(len?: number): BitArray; + + /// Return the length in bits, rounded up to the nearest byte. + bitLength(): number; + } + + interface BigNumberStatic { + new (): BigNumber; + new (n: string): BigNumber; + new (n: number): BigNumber; + new (n: BigNumber): BigNumber; + + fromBits(bits: BitArray): BigNumber; + random: TypeHelpers.Bind1; + prime: { + p127: PseudoMersennePrimeStatic; + // Bernstein's prime for Curve25519 + p25519: PseudoMersennePrimeStatic; + // Koblitz primes + p192k: PseudoMersennePrimeStatic; + p224k: PseudoMersennePrimeStatic; + p256k: PseudoMersennePrimeStatic; + // NIST primes + p192: PseudoMersennePrimeStatic; + p224: PseudoMersennePrimeStatic; + p256: PseudoMersennePrimeStatic; + p384: PseudoMersennePrimeStatic; + p521: PseudoMersennePrimeStatic; + }; + + pseudoMersennePrime(exponent: number, coeff: number[][]): PseudoMersennePrimeStatic; + } + + interface PseudoMersennePrime extends BigNumber { + reduce(): PseudoMersennePrime; + fullReduce(): PseudoMersennePrime; + inverse(): PseudoMersennePrime; + } + + interface PseudoMersennePrimeStatic extends BigNumberStatic { + new (): PseudoMersennePrime; + new (n: string): PseudoMersennePrime; + new (n: number): PseudoMersennePrime; + new (n: BigNumber): PseudoMersennePrime; + } + + // ________________________________________________________________________ + + interface BitArray extends Array { + } + + interface BitArrayStatic { + /// Array slices in units of bits. + bitSlice(a: BitArray, bstart: number, bend: number): BitArray; + + /// Extract a number packed into a bit array. + extract(a: BitArray, bstart: number, blenth: number): number; + + /// Concatenate two bit arrays. + concat(a1: BitArray, a2: BitArray): BitArray + + /// Find the length of an array of bits. + bitLength(a: BitArray): number; + + /// Truncate an array. + clamp(a: BitArray, len: number): BitArray; + + /// Make a partial word for a bit array. + partial(len: number, x: number, _end?: number): number; + + /// Get the number of bits used by a partial word. + getPartial(x: number): number; + + /// Compare two arrays for equality in a predictable amount of time. + equal(a: BitArray, b: BitArray): boolean; + + /// Shift an array right. + _shiftRight(a: BitArray, shift: number, carry?: number, out?: BitArray): BitArray; + + /// xor a block of 4 words together. + _xor4(x: number[], y: number[]): number[]; + } + + // ________________________________________________________________________ + + interface SjclCodec { + fromBits(bits: BitArray): T; + toBits(value: T): BitArray; + } + + interface SjclCodecs { + utf8String: SjclCodec; + hex: SjclCodec; + bytes: SjclCodec; + base64: SjclCodec; + base64url: SjclCodec; + } + + // ________________________________________________________________________ + + interface SjclHash { + reset(): SjclHash; + update(data: string): SjclHash; + update(data: BitArray): SjclHash; + finalize(): BitArray; + } + + interface SjclHashStatic { + new (hash?: SjclHash): SjclHash; + hash(data: string): BitArray; + hash(data: BitArray): BitArray; + } + + interface SjclHashes { + sha1: SjclHashStatic; + sha256: SjclHashStatic; + sha512: SjclHashStatic; + } + + // ________________________________________________________________________ + + interface SjclExceptions { + corrupt: SjclExceptionFactory; + invalid: SjclExceptionFactory; + bug: SjclExceptionFactory; + notReady: SjclExceptionFactory; + } + + interface SjclExceptionFactory { + new (message: string): Error; + } + + // ________________________________________________________________________ + + interface SjclCiphers { + aes: SjclCipherStatic; + } + + interface SjclCipher { + encrypt(data: number[]): number[]; + decrypt(data: number[]): number[]; + } + + interface SjclCipherStatic { + new (key: number[]): SjclCipher; + } + + // ________________________________________________________________________ + + interface SjclModes { + gcm: SjclGCMMode; + ccm: SjclCCMMode; + ocb2: SjclOCB2Mode; + cbc: SjclCBCMode; + } + + interface SjclGCMMode { + encrypt(prp: SjclCipher, plaintext: BitArray, iv: BitArray, adata?: BitArray, tlen?: number): BitArray; + decrypt(prp: SjclCipher, ciphertext: BitArray, iv: BitArray, adata?: BitArray, tlen?: number): BitArray; + } + + interface SjclCCMMode { + encrypt(prp: SjclCipher, plaintext: BitArray, iv: BitArray, adata?: BitArray, tlen?: number): BitArray; + decrypt(prp: SjclCipher, ciphertext: BitArray, iv: BitArray, adata?: BitArray, tlen?: number): BitArray; + } + + interface SjclOCB2Mode { + encrypt(prp: SjclCipher, plaintext: BitArray, iv: BitArray, adata?: BitArray, tlen?: number, premac?: boolean): BitArray; + decrypt(prp: SjclCipher, ciphertext: BitArray, iv: BitArray, adata?: BitArray, tlen?: number, premac?: boolean): BitArray; + pmac(prp: SjclCipher, adata: BitArray): number[]; + } + + interface SjclCBCMode { + encrypt(prp: SjclCipher, plaintext: BitArray, iv: BitArray, adata?: BitArray): BitArray; + decrypt(prp: SjclCipher, ciphertext: BitArray, iv: BitArray, adata?: BitArray): BitArray; + } + + // ________________________________________________________________________ + + interface Pbkdf2Params { + iter?: number; + salt?: BitArray; + } + + interface SjclMisc { + pbkdf2(password: string, salt: string, count?: number, length?: number, Prff?: SjclPseudorandomFunctionFamilyStatic): BitArray; + pbkdf2(password: BitArray, salt: string, count?: number, length?: number, Prff?: SjclPseudorandomFunctionFamilyStatic): BitArray; + pbkdf2(password: BitArray, salt: BitArray, count?: number, length?: number, Prff?: SjclPseudorandomFunctionFamilyStatic): BitArray; + pbkdf2(password: string, salt: BitArray, count?: number, length?: number, Prff?: SjclPseudorandomFunctionFamilyStatic): BitArray; + hmac: SjclHmacStatic; + cachedPbkdf2(password: string, obj?: Pbkdf2Params): { + key: BitArray; + salt: BitArray; + }; + } + + class SjclPseudorandomFunctionFamily { + encrypt(data: string): BitArray; + encrypt(data: BitArray): BitArray; + } + + interface SjclHmac extends SjclPseudorandomFunctionFamily { + mac(data: string): BitArray; + mac(data: BitArray): BitArray; + reset(): void; + update(data: string): void; + update(data: BitArray): void; + digest(): BitArray; + } + + interface SjclPseudorandomFunctionFamilyStatic { + new (key: BitArray): SjclPseudorandomFunctionFamily; + } + + interface SjclHmacStatic { + new (key: BitArray, Hash?: SjclHashStatic): SjclHmac; + } + + // ________________________________________________________________________ + + interface SjclEllipticCurveCryptography { + point: SjclEllipticalPointStatic; + pointJac: SjclPointJacobianStatic; + curve: SjclEllipticalCurveStatic; + curves: { + c192: SjclEllipticalCurve; + c224: SjclEllipticalCurve; + c256: SjclEllipticalCurve; + c384: SjclEllipticalCurve; + k192: SjclEllipticalCurve; + k224: SjclEllipticalCurve; + k256: SjclEllipticalCurve; + }; + basicKey: SjclECCBasic; + elGamal: SjclElGamal; + ecdsa: SjclEcdsa; + } + + interface SjclEllipticalPoint { + toJac(): SjclPointJacobian; + mult(k: BigNumber): SjclEllipticalPoint; + mult2(k: BigNumber, k2: BigNumber, affine2: SjclEllipticalPoint): SjclEllipticalPoint; + multiples(): Array; + isValid(): boolean; + toBits(): BitArray; + } + + interface SjclEllipticalPointStatic { + new (curve: SjclEllipticalCurve, x?: BigNumber, y?: BigNumber): SjclEllipticalPoint; + } + + interface SjclPointJacobian { + add(T: SjclEllipticalPoint): SjclPointJacobian; + doubl(): SjclPointJacobian; + toAffine(): SjclEllipticalPoint; + mult(k: BigNumber, affine: SjclEllipticalPoint): SjclPointJacobian; + mult2(k1: BigNumber, affine: SjclEllipticalPoint, k2: BigNumber, affine2: SjclEllipticalPoint): SjclPointJacobian; + isValid(): boolean; + } + + interface SjclPointJacobianStatic { + new (curve: SjclEllipticalCurve, x?: BigNumber, y?: BigNumber, z?: BigNumber):SjclPointJacobian; + } + + interface SjclEllipticalCurve { + fromBits(bits: BitArray): SjclEllipticalPoint; + } + + interface SjclEllipticalCurveStatic { + new (Field: BigNumber, r: BigNumber, a: BigNumber, b: BigNumber, x: BigNumber, y: BigNumber): SjclEllipticalCurve; + } + + interface SjclKeyPair

{ + pub: P; + sec: S; + } + + interface SjclKeysGenerator

{ + (curve: SjclEllipticalCurve, paranoia: number, sec?: BigNumber): SjclKeyPair; + (curve: number, paranoia: number, sec?: BigNumber): SjclKeyPair; + } + + interface SjclECCPublicKeyData { + x: BitArray; + y: BitArray; + } + + class SjclECCPublicKey { + get(): SjclECCPublicKeyData; + } + + class SjclECCSecretKey { + get(): BitArray; + } + + interface SjclECCPublicKeyFactory { + new (curve: SjclEllipticalCurve, point: SjclEllipticalPoint): T; + new (curve: SjclEllipticalCurve, point: BitArray): T; + } + + interface SjclECCSecretKeyFactory { + new (curve: SjclEllipticalCurve, exponent: BigNumber): T; + } + + interface SjclECCBasic { + publicKey: SjclECCPublicKeyFactory; + secretKey: SjclECCSecretKeyFactory; + generateKeys(cn: string): SjclKeysGenerator; + } + + class SjclElGamalPublicKey extends SjclECCPublicKey { + kem(paranoia: number): { + key: BitArray; + tag: BitArray; + }; + } + + class SjclElGamalSecretKey extends SjclECCSecretKey { + unkem(tag: BitArray): BitArray; + dh(pk: SjclECCPublicKey): BitArray; + } + + interface SjclElGamal { + publicKey: SjclECCPublicKeyFactory; + secretKey: SjclECCSecretKeyFactory; + generateKeys: SjclKeysGenerator; + } + + class SjclEcdsaPublicKey extends SjclECCPublicKey { + verify(hash: BitArray, rs: BitArray, fakeLegacyVersion: boolean): boolean; + } + + class SjclEcdsaSecretKey extends SjclECCSecretKey { + sign(hash: BitArray, paranoia: number, fakeLegacyVersion: boolean, fixedKForTesting?: BigNumber): BitArray; + } + + interface SjclEcdsa { + publicKey: SjclECCPublicKeyFactory; + secretKey: SjclECCSecretKeyFactory; + generateKeys: SjclKeysGenerator; + } + + // ________________________________________________________________________ + + interface SjclRandom { + randomWords(nwords: number, paranoia?: number): BitArray; + setDefaultParanoia(paranoia: number, allowZeroParanoia: string): void; + addEntropy(data: number, estimatedEntropy: number, source: string): void; + addEntropy(data: number[], estimatedEntropy: number, source: string): void; + addEntropy(data: string, estimatedEntropy: number, source: string): void; + isReady(paranoia?: number): boolean; + getProgress(paranoia?: number): number; + startCollectors(): void; + stopCollectors(): void; + addEventListener(name: string, cb: Function): void; + removeEventListener(name: string, cb: Function): void; + } + + interface SjclRandomStatic { + new (defaultParanoia: number): SjclRandom; + } + + // ________________________________________________________________________ + + interface SjclKeyExchange { + srp: SecureRemotePassword; + } + + interface SjclSRPGroup { + N: BigNumber; + g: BigNumber; + } + + interface SecureRemotePassword { + makeVerifier(username: string, password: string, salt: BitArray, group: SjclSRPGroup): BitArray; + makeX(username: string, password: string, salt: BitArray): BitArray; + knownGroup(i: string): SjclSRPGroup; + knownGroup(i: number): SjclSRPGroup; + } + + // ________________________________________________________________________ + + interface SjclCipherParams { + v?: number; + iter?: number; + ks?: number; + ts?: number; + mode?: string; + adata?: string; + cipher?: string; + } + + interface SjclCipherEncryptParams extends SjclCipherParams { + salt: BitArray; + iv: BitArray; + } + + interface SjclCipherDecryptParams extends SjclCipherParams { + salt?: BitArray; + iv?: BitArray; + } + + interface SjclCipherEncrypted extends SjclCipherEncryptParams { + kemtag?: BitArray; + ct: BitArray; + } + + interface SjclCipherDecrypted extends SjclCipherEncrypted { + key: BitArray; + } + + interface SjclConveninceEncryptor { + (password: string, plaintext: string, params?: SjclCipherEncryptParams, rp?: SjclCipherEncrypted): SjclCipherEncrypted; + (password: BitArray, plaintext: string, params?: SjclCipherEncryptParams, rp?: SjclCipherEncrypted): SjclCipherEncrypted; + (password: SjclElGamalPublicKey, plaintext: string, params?: SjclCipherEncryptParams, rp?: SjclCipherEncrypted): SjclCipherEncrypted; + } + + interface SjclConveninceDecryptor { + (password: string, ciphertext: SjclCipherEncrypted, params?: SjclCipherDecryptParams, rp?: SjclCipherDecrypted): string; + (password: BitArray, ciphertext: SjclCipherEncrypted, params?: SjclCipherDecryptParams, rp?: SjclCipherDecrypted): string; + (password: SjclElGamalSecretKey, ciphertext: SjclCipherEncrypted, params?: SjclCipherDecryptParams, rp?: SjclCipherDecrypted): string; + } + + interface SjclJson { + encrypt: SjclConveninceEncryptor; + decrypt: SjclConveninceDecryptor; + encode(obj: Object): string; + decode(obj: string): Object; + } + + // ________________________________________________________________________ + + module TypeHelpers { + interface One { + (value: T): BigNumber; + } + + interface BigNumberBinaryOperator extends One, One, One { + } + + interface Two { + (x: T1, N: T2): BigNumber; + } + + interface Bind1 extends Two, Two, Two { + } + + interface BigNumberTrinaryOperator extends Bind1, Bind1, Bind1 { + } + } +} From 56bb95a53205c4d38436436109bd12255394c662 Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Mon, 4 Aug 2014 10:48:11 +0200 Subject: [PATCH 08/11] MomentJs: Fixed some return values and made parameters optional --- moment/moment.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/moment/moment.d.ts b/moment/moment.d.ts index f14c7d4be..344885f1b 100644 --- a/moment/moment.d.ts +++ b/moment/moment.d.ts @@ -1,6 +1,6 @@ // Type definitions for Moment.js 2.5.0 // Project: https://github.com/timrwood/moment -// Definitions by: Michael Lakerveld , Aaron King , Hiroki Horiuchi +// Definitions by: Michael Lakerveld , Aaron King , Hiroki Horiuchi , Dick van den Brink // Definitions: https://github.com/borisyankov/DefinitelyTyped interface MomentInput { @@ -203,9 +203,9 @@ interface Moment { isSame(b: Date, granularity: string): boolean; isSame(b: number[], granularity: string): boolean; - lang(language: string): void; - lang(reset: boolean): void; - lang(): string; + lang(language: string): Moment; + lang(reset: boolean): Moment; + lang(): MomentLanguage; max(date: Date): Moment; max(date: number): Moment; @@ -313,8 +313,8 @@ interface MomentStatic { isMoment(): boolean; isMoment(m: any): boolean; - lang(language: string): any; - lang(language: string, definition: MomentLanguage): any; + lang(language?: string): string; + lang(language?: string, definition?: MomentLanguage): string; longDateFormat: any; relativeTime: any; meridiem: (hour: number, minute: number, isLowercase: boolean) => string; From 5c2007a539bb4f244b6ce61899c4bedd9b58bde8 Mon Sep 17 00:00:00 2001 From: Antoine Pultier Date: Mon, 4 Aug 2014 11:20:14 +0200 Subject: [PATCH 09/11] TypeScript validity --- leaflet/leaflet.d.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/leaflet/leaflet.d.ts b/leaflet/leaflet.d.ts index 7f7b8dc9a..bc4e7be90 100644 --- a/leaflet/leaflet.d.ts +++ b/leaflet/leaflet.d.ts @@ -1244,7 +1244,7 @@ declare module L { enabled(): boolean; } - export class Handler extends Class implements IHandler { + export class Handler extends Class { initialize(map: Map): void; } } @@ -1269,10 +1269,8 @@ declare module L { } declare module L { - export var Mixin: any; - - module Mixin { - export interface LeafletMixinEvents implements IEventPowered { + export module Mixin { + export interface LeafletMixinEvents extends IEventPowered { } export var Events: LeafletMixinEvents; @@ -2418,8 +2416,9 @@ declare module L { * * Default value: true. */ - scrollWheelZoom?: boolean; scrollWheelZoom?: string; + //scrollWheelZoom?: boolean; + //scrollWheelZoom?: string; /** * Whether the map can be zoomed in by double clicking on it and zoomed out @@ -2429,8 +2428,9 @@ declare module L { * * Default value: true. */ - doubleClickZoom?: boolean; doubleClickZoom?: string; + //doubleClickZoom?: boolean; + //doubleClickZoom?: string; /** * Whether the map can be zoomed to a rectangular area specified by dragging @@ -3428,12 +3428,9 @@ declare module L { /** * Returns the content of the popup. */ - getContent(): string; - - /** - * Returns the content of the popup. - */ - getContent(): HTMLElement; + getContent(): any; + //getContent(): string; + //getContent(): HTMLElement; //////////// //////////// From bc1961484a80a021716600123785cedfb1376cc9 Mon Sep 17 00:00:00 2001 From: Antoine Pultier Date: Mon, 4 Aug 2014 13:08:49 +0200 Subject: [PATCH 10/11] [leaflet] small adjustments --- leaflet/leaflet.d.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/leaflet/leaflet.d.ts b/leaflet/leaflet.d.ts index bc4e7be90..3332f9000 100644 --- a/leaflet/leaflet.d.ts +++ b/leaflet/leaflet.d.ts @@ -2183,7 +2183,7 @@ declare module L { /** * Closes the popup previously opened with openPopup (or the given one). */ - closePopup(): Map; + closePopup(popup?: Popup): Map; /** * Adds the given control to the map. @@ -2416,7 +2416,7 @@ declare module L { * * Default value: true. */ - scrollWheelZoom?: string; + scrollWheelZoom?: any; //scrollWheelZoom?: boolean; //scrollWheelZoom?: string; @@ -2739,7 +2739,12 @@ declare module L { /** * Returns a GeoJSON representation of the marker (GeoJSON Point Feature). */ - toGeoJSON(popup: Popup, options?: PopupOptions): any; + toGeoJSON(): any; + + /** + * Marker dragging handler (by both mouse and touch). + */ + dragging: IHandler; //////////// //////////// @@ -3428,9 +3433,8 @@ declare module L { /** * Returns the content of the popup. */ - getContent(): any; + getContent(): HTMLElement; //getContent(): string; - //getContent(): HTMLElement; //////////// //////////// From 1cbee878f7753f66ee562789bb5acc9a063b86c2 Mon Sep 17 00:00:00 2001 From: Antoine Pultier Date: Mon, 4 Aug 2014 13:09:19 +0200 Subject: [PATCH 11/11] [leaflet] Brand new test file --- leaflet/leaflet-tests.ts | 301 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 leaflet/leaflet-tests.ts diff --git a/leaflet/leaflet-tests.ts b/leaflet/leaflet-tests.ts new file mode 100644 index 000000000..c07a651d8 --- /dev/null +++ b/leaflet/leaflet-tests.ts @@ -0,0 +1,301 @@ +/// + +// initialize the map on the "map" div with a given center and zoom + +var div = document.getElementById('map'); + +var map : L.Map = L.map(div, { + center: L.latLng([51.505, -0.09]), + zoom: 13, + minZoom: 3, + maxZoom: 8, + maxBounds: L.latLngBounds([L.latLng(-60, -60), L.latLng(60, 60)]), + dragging: true, + touchZoom: true, + scrollWheelZoom: true, + boxZoom: true, + tap: true, + + tapTolerance: 30, + trackResize: true, + worldCopyJump: false, + closePopupOnClick: true, + bounceAtZoomLimits: true, + + keyboard: true, + keyboardPanOffset: 80, + keyboardZoomOffset: 1, + + inertia: true, + inertiaDeceleration: 3000, + inertiaMaxSpeed: 1500, + inertiaThreshold: 32, + + zoomControl: true, + attributionControl: true, + + fadeAnimation: true, + zoomAnimation: true, + zoomAnimationThreshold: 4, + markerZoomAnimation: true + +}); + +map.dragging.enable(); +map.touchZoom.enable(); +map.scrollWheelZoom.enable(); +map.doubleClickZoom.enable(); +map.boxZoom.enable(); +map.tap.enable(); + +map.setView(new L.LatLng(42, 51)); +map.setView(L.latLng(42, 51)); + +map.setView(L.latLng(42, 51), 12); +map.setView(L.latLng(42, 51), 12, { + reset: true, + pan: { + animate: true, + duration: 0.25, + easeLinearity: 0.25, + noMoveStart: false + }, + zoom: { + animate: true + } +}); + +map.setZoom(50); +map.setZoom(50, {}); + +map.zoomIn(); +map.zoomOut(); + +map.zoomIn(2); +map.zoomOut(2); + +map.zoomIn(2, { animate: true }); +map.zoomOut(2, { animate: true }); + +map.setZoomAround(L.latLng(42, 51), 8, { animate: false }); + +map.fitBounds(L.latLngBounds(L.latLng(10, 10), L.latLng(20, 20))); +map.fitBounds(L.latLngBounds(L.latLng(10, 10), L.latLng(20, 20)), { + paddingTopLeft: L.point(20, 20), + paddingBottomRight: L.point(20, 20), + padding: L.point(0, 0), + maxZoom: null +}); + +map.fitWorld(); + +map.fitWorld({ + animate: false +}); + +map.panTo(L.latLng(42, 42)); +map.panTo(L.latLng(42, 42), { + animate: true +}); + +map.invalidateSize(true); +map.invalidateSize({ reset: true }); + +map.setMaxBounds(L.latLngBounds(L.latLng(10, 10), L.latLng(20, 20))); + +map.locate(); +map.locate({ + watch: false, + setView: false, + maxZoom: 18, + timeout: 10000, + maximumAge: 0, + enableHighAccuracy: false +}); + +map.stopLocate(); + +map.remove(); + +var center : L.LatLng = map.getCenter(); +var zoom : number = map.getZoom(); +var minZoom: number = map.getMinZoom(); +var maxZoom: number = map.getMaxZoom(); +var bounds: L.LatLngBounds = map.getBounds(); +var boundsZoom: number = map.getBoundsZoom(bounds, true); +var size: L.Point = map.getSize(); +var pixelBounds: L.Bounds = map.getPixelBounds(); +var pixelOrigin: L.Point = map.getPixelOrigin(); + +var layer = L.tileLayer("http://{s}.example.net/{x}/{y}/{z}.png"); + +map.addLayer(layer); +map.addLayer(layer, false); + +map.removeLayer(layer); +map.hasLayer(layer); + +map.openPopup("canard", L.latLng(42, 51)); + +var popup = L.popup({ + autoPan: true +}); + +map.openPopup(popup); +map.closePopup(popup); +map.closePopup(); + +map.addControl(L.control.attribution({position: 'bottomright'})); +map.removeControl(L.control.attribution({ position: 'bottomright' })); + +map.latLngToLayerPoint(map.layerPointToLatLng(L.point(0, 0))); +map.latLngToContainerPoint(map.containerPointToLatLng(L.point(0, 0))); +map.containerPointToLayerPoint(L.point(0, 0)); +map.layerPointToContainerPoint(L.point(0, 0)); + +map.project(map.unproject(L.point(10, 20))); +map.project(map.unproject(L.point(10, 20), 12), 12); + +var mouseEvent: L.LeafletMouseEvent; +map.mouseEventToContainerPoint(mouseEvent); +map.mouseEventToLayerPoint(mouseEvent); +map.mouseEventToLatLng(mouseEvent); + +map.getContainer().classList.add('roger'); +map.getPanes().mapPane.classList.add('roger'); +map.getPanes().markerPane.classList.add('roger'); +map.getPanes().objectsPane.classList.add('roger'); +map.getPanes().overlayPane.classList.add('roger'); +map.getPanes().popupPane.classList.add('roger'); +map.getPanes().shadowPane.classList.add('roger'); +map.getPanes().tilePane.classList.add('roger'); + +map.whenReady((m: L.Map) => { + m.zoomOut(); +}); + +map.on('click', () => { + map.zoomOut(); +}); + +map.off('dblclick', L.Util.falseFn); + +map.once('contextmenu', (e: L.LeafletMouseEvent) => { + map.openPopup('contextmenu', e.latlng); +}); + +var marker = L.marker(L.latLng(42, 51), { + icon: L.icon({ + iconURl: 'roger.png', + iconRetinaUrl: 'roger-retina.png', + iconSize: L.point(40, 40), + iconAnchor: L.point(20, 0), + shadowUrl: 'roger-shadow.png', + shadowRetinaUrl: 'roger-shadow-retina.png', + shadowSize: L.point(44, 44), + shadowAnchor: L.point(22, 0), + popupAnchor: L.point(0, 0), + className: 'roger-icon' + }), + clickable: true, + draggable: false, + keyboard: true, + title: 'this is an icon', + alt: '', + zIndexOffset: 0, + opacity: 1.0, + riseOnHover: false, + riseOffset: 250 +}); + +marker.addTo(map); + +marker.on('click', (e: L.LeafletMouseEvent) => { + map.setView(e.latlng); +}); + +marker.once('mouseover', () => { + marker.openPopup(); +}) + +marker.setLatLng(marker.getLatLng()); + +marker.setIcon(L.icon({})); + +marker.setZIndexOffset(30); +marker.setOpacity(0.8); + +marker.bindPopup(popup); +marker.unbindPopup(); +marker.bindPopup('hello', { + closeOnClick: true +}); + +marker.openPopup(); +marker.closePopup(); +marker.togglePopup(); +marker.togglePopup(); +marker.setPopupContent('hello 3') +marker.getPopup().setContent('hello 2'); +marker.update(); + +marker.toGeoJSON(); + +marker.dragging.enable(); + +popup = L.popup({ + maxWidth: 300, + minWidth: 50, + maxHeight: null, + autoPan: true, + keepInView: false, + closeButton: true, + offset: L.point(0, 6), + autoPanPaddingTopLeft: null, + autoPanPaddingBottomRight: L.point(20, 20), + autoPanPadding: L.point(5, 5), + zoomAnimation: true, + closeOnClick: null, + className: 'roger' +}); + +popup.setLatLng(L.latLng(12, 54)).setContent('this is nice popup').openOn(map); + +popup.update(); + +var tileLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png?{foo}', { + foo: 'bar', + minZoom: 0, + maxZoom: 18, + maxNativeZoom: 17, + tileSize: 256, + subdomains: ['a','b','c'], + errorTileUrl: '', + attribution: '', + tms: false, + continuousWorld: false, + noWrap: false, + zoomOffset: 0, + zoomReverse: false, + opacity: 1.0, + zIndex: null, + unloadInvisibleTiles: false, + updateWhenIdle: false, + detectRetina: true, + reuseTiles: true, + bounds: null +}); + +tileLayer.on('loading', L.Util.falseFn) + .off('loading', L.Util.falseFn) + .once('tileload', L.Util.falseFn); + +tileLayer.addTo(map); + +tileLayer.bringToBack() + .bringToFront() + .setOpacity(0.7) + .setZIndex(9) + .redraw() + .setUrl('http://perdu.com') + .getContainer();