From ac463e55d20d8eb26b207133b4cfd6810ae5617a Mon Sep 17 00:00:00 2001 From: thothbot Date: Wed, 21 Jan 2015 01:52:06 +0300 Subject: [PATCH 01/75] Updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d2ebea51..7daa68b8 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The aim of the project is to use GWT which helps maintaining complex pieces of c Parallax supports WebGL-canvas renderer only. -### Download - Parallax v1.3 ### +### Download - new Parallax v1.4 ### [Download JAR](http://github.com/thothbot/parallax/wiki/Download) | [Change log](http://github.com/thothbot/parallax/wiki/Change-log) From d6d981aef8c0ec4dd896730a5cb65d1d7e57f4f8 Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 23 Jan 2015 19:18:11 +0300 Subject: [PATCH 02/75] Fixed some issues in geometry --- .../core/client/renderers/WebGLRenderer.java | 7 +- .../core/shared/geometries/BoxGeometry.java | 22 ++--- .../shared/geometries/CylinderGeometry.java | 30 +++--- .../core/shared/geometries/LatheGeometry.java | 75 +++++++++----- .../geometries/PlaneBufferGeometry.java | 8 +- .../core/shared/geometries/RingGeometry.java | 98 +++++++++++++++++++ 6 files changed, 180 insertions(+), 60 deletions(-) create mode 100644 src/thothbot/parallax/core/shared/geometries/RingGeometry.java diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index fd28e0df..73b0f9aa 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -832,7 +832,7 @@ private void setupMorphTargets ( Material material, WebGLGeometry geometrybuffer // set base Map attributes = material.getShader().getAttributesLocations(); Map uniforms = material.getShader().getUniforms(); - Log.error(attributes); + if ( object.morphTargetBase != - 1 && attributes.get("position") >= 0) { getGL().bindBuffer( BufferTarget.ARRAY_BUFFER, geometrybuffer.__webglMorphTargetsBuffers.get( object.morphTargetBase ) ); @@ -1857,10 +1857,9 @@ public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget } - Log.error("render", opaqueObjects.size(), transparentObjects.size(), this._webglObjects, _webglObjectsImmediate.size()); if ( scene.overrideMaterial != null ) { - Log.error("render(): override material"); + Log.debug("render(): override material"); Material material = scene.overrideMaterial; @@ -2396,7 +2395,7 @@ private Shader setProgram( Camera camera, List lights, AbstractFog fog, M refreshMaterial = true; refreshLights = true; - Log.error("program != _currentProgram"); + Log.warn("program != _currentProgram"); } if ( material.getId() != this._currentMaterialId ) diff --git a/src/thothbot/parallax/core/shared/geometries/BoxGeometry.java b/src/thothbot/parallax/core/shared/geometries/BoxGeometry.java index feffe6c0..4dfbb4de 100644 --- a/src/thothbot/parallax/core/shared/geometries/BoxGeometry.java +++ b/src/thothbot/parallax/core/shared/geometries/BoxGeometry.java @@ -62,12 +62,12 @@ public BoxGeometry( double width, double height, double depth, int segmentsWidth double height_half = height / 2.0; double depth_half = depth / 2.0; - buildPlane( "z", "y", - 1, - 1, depth, height, width_half, 0 ); - buildPlane( "z", "y", 1, - 1, depth, height, - width_half, 1 ); - buildPlane( "x", "z", 1, 1, width, depth, height_half, 2 ); - buildPlane( "x", "z", 1, - 1, width, depth, - height_half, 3 ); - buildPlane( "x", "y", 1, - 1, width, height, depth_half, 4 ); - buildPlane( "x", "y", - 1, - 1, width, height, - depth_half, 5 ); + buildPlane( "z", "y", - 1, - 1, depth, height, width_half, 0 ); // px + buildPlane( "z", "y", 1, - 1, depth, height, - width_half, 1 ); // nx + buildPlane( "x", "z", 1, 1, width, depth, height_half, 2 ); // py + buildPlane( "x", "z", 1, - 1, width, depth, - height_half, 3 ); // ny + buildPlane( "x", "y", 1, - 1, width, height, depth_half, 4 ); // pz + buildPlane( "x", "y", - 1, - 1, width, height, - depth_half, 5 ); // nz this.mergeVertices(); } @@ -79,7 +79,7 @@ private void buildPlane( String u, String v, int udir, int vdir, double width, d double width_half = width / 2.0; double height_half = height / 2.0; - int offset = getVertices().size(); + int offset = this.getVertices().size(); String w = ""; @@ -155,10 +155,10 @@ else if(w.equals("z")) int c = ( ix + 1 ) + gridX1 * ( iy + 1 ); int d = ( ix + 1 ) + gridX1 * iy; - Vector2 uva = new Vector2( ix / gridX, 1.0 - iy / gridY ); - Vector2 uvb = new Vector2( ix / gridX, 1.0 - ( iy + 1.0 ) / gridY ); - Vector2 uvc = new Vector2( ( ix + 1.0 ) / gridX, 1.0 - ( iy + 1.0 ) / gridY ); - Vector2 uvd = new Vector2( ( ix + 1.0 ) / gridX, 1.0 - iy / gridY ); + Vector2 uva = new Vector2( ix / (double)gridX, 1.0 - iy / (double)gridY ); + Vector2 uvb = new Vector2( ix / (double)gridX, 1.0 - ( iy + 1.0 ) / (double)gridY ); + Vector2 uvc = new Vector2( ( ix + 1.0 ) / (double)gridX, 1.0 - ( iy + 1.0 ) / (double)gridY ); + Vector2 uvd = new Vector2( ( ix + 1.0 ) / (double)gridX, 1.0 - iy / (double)gridY ); Face3 face = new Face3( a + offset, b + offset, d + offset ); face.getNormal().copy( normal ); diff --git a/src/thothbot/parallax/core/shared/geometries/CylinderGeometry.java b/src/thothbot/parallax/core/shared/geometries/CylinderGeometry.java index 651b2b19..60f0ef64 100644 --- a/src/thothbot/parallax/core/shared/geometries/CylinderGeometry.java +++ b/src/thothbot/parallax/core/shared/geometries/CylinderGeometry.java @@ -45,44 +45,44 @@ public CylinderGeometry() public CylinderGeometry(double radiusTop, double radiusBottom, double height, int segmentsRadius, int segmentsHeight) { - this(radiusTop, radiusBottom, height, segmentsRadius, segmentsHeight, false); + this(radiusTop, radiusBottom, height, segmentsRadius, segmentsHeight, false, 0, Math.PI * 2); } - public CylinderGeometry(double radiusTop, double radiusBottom, double height, int segmentsRadius, int segmentsHeight, boolean openEnded) + public CylinderGeometry(double radiusTop, double radiusBottom, double height, int radialSegments, int heightSegments, boolean openEnded, double thetaStart, double thetaLength) { super(); double heightHalf = height / 2.0; - int segmentsX = segmentsRadius; - int segmentsY = segmentsHeight; +// int segmentsX = radialSegments; +// int segmentsY = heightSegments; int x = 0, y = 0; List> vertices = new ArrayList>(); List> uvs = new ArrayList>(); - for ( y = 0; y <= segmentsY; y ++ ) + for ( y = 0; y <= heightSegments; y ++ ) { List verticesRow = new ArrayList(); List uvsRow = new ArrayList(); - double v = y / (double)segmentsY; + double v = (double)y / (double)heightSegments; double radius = v * ( radiusBottom - radiusTop ) + radiusTop; - for ( x = 0; x <= segmentsX; x ++ ) + for ( x = 0; x <= radialSegments; x ++ ) { - double u = x / (double)segmentsX; + double u = (double)x / (double)radialSegments; Vector3 vertex = new Vector3(); - vertex.setX(radius * Math.sin( u * Math.PI * 2.0 )); + vertex.setX(radius * Math.sin( u * thetaLength + thetaStart )); vertex.setY(- v * height + heightHalf); - vertex.setZ(radius * Math.cos( u * Math.PI * 2.0 )); + vertex.setZ(radius * Math.cos( u * thetaLength + thetaStart )); getVertices().add( vertex ); verticesRow.add( getVertices().size() - 1 ); - uvsRow.add( new Vector2( u, v ) ); + uvsRow.add( new Vector2( u, 1 - v ) ); } @@ -93,7 +93,7 @@ public CylinderGeometry(double radiusTop, double radiusBottom, double height, in double tanTheta = ( radiusBottom - radiusTop ) / height; Vector3 na, nb; - for ( x = 0; x < segmentsX; x ++ ) + for ( x = 0; x < radialSegments; x ++ ) { if ( radiusTop != 0 ) { @@ -111,7 +111,7 @@ public CylinderGeometry(double radiusTop, double radiusBottom, double height, in nb.setY( Math.sqrt( nb.getX() * nb.getX() + nb.getZ() * nb.getZ() ) * tanTheta ); nb.normalize(); - for ( y = 0; y < segmentsY; y ++ ) + for ( y = 0; y < heightSegments; y ++ ) { int v1 = vertices.get( y ).get( x ); int v2 = vertices.get( y + 1 ).get( x ); @@ -144,7 +144,7 @@ public CylinderGeometry(double radiusTop, double radiusBottom, double height, in { getVertices().add( new Vector3( 0.0, heightHalf, 0.0 ) ); - for ( x = 0; x < segmentsX; x ++ ) + for ( x = 0; x < radialSegments; x ++ ) { int v1 = vertices.get( 0 ).get( x ); int v2 = vertices.get( 0 ).get( x + 1 ); @@ -169,7 +169,7 @@ public CylinderGeometry(double radiusTop, double radiusBottom, double height, in { getVertices().add( new Vector3( 0, - heightHalf, 0 ) ); - for ( x = 0; x < segmentsX; x ++ ) + for ( x = 0; x < radialSegments; x ++ ) { int v1 = vertices.get( y ).get( x + 1 ); int v2 = vertices.get( y ).get( x ); diff --git a/src/thothbot/parallax/core/shared/geometries/LatheGeometry.java b/src/thothbot/parallax/core/shared/geometries/LatheGeometry.java index 79a7c5cf..dce67c77 100644 --- a/src/thothbot/parallax/core/shared/geometries/LatheGeometry.java +++ b/src/thothbot/parallax/core/shared/geometries/LatheGeometry.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.List; +import thothbot.parallax.core.shared.core.Face3; import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.math.Matrix4; import thothbot.parallax.core.shared.math.Vector2; @@ -37,50 +38,72 @@ public LatheGeometry ( List points) public LatheGeometry ( List points, int steps) { - this(points, steps, 2.0 * Math.PI); + this(points, steps, 0, 2.0 * Math.PI); } - public LatheGeometry ( List points, int steps, double angle ) + public LatheGeometry ( List points, int segments, double phiStart, double phiLength ) { super(); - List newV = new ArrayList(); + double inversePointLength = 1.0 / ( points.size() - 1 ); + double inverseSegments = 1.0 / segments; - Matrix4 matrix = new Matrix4().makeRotationZ( angle / steps ); - for ( int j = 0; j < points.size(); j ++ ) + for ( int i = 0; i <= segments; i ++ ) { - newV.add( j , points.get( j ).clone()); - getVertices().add( newV.get( j ) ); - } + double phi = phiStart + i * inverseSegments * phiLength; - for ( int i = 0; i <= steps; i ++ ) - { - for ( int j = 0; j < newV.size(); j ++ ) + double c = Math.cos( phi ), + s = Math.sin( phi ); + + for ( int j = 0; j < points.size(); j ++ ) { -// newV.set( j , (Vector3) matrix.multiply( newV.get( j ).clone() )); - getVertices().add( newV.get( j ) ); + Vector3 pt = points.get( j ); + + Vector3 vertex = new Vector3(); + + vertex.setX( c * pt.getX() - s * pt.getY() ); + vertex.setY( s * pt.getX() + c * pt.getY() ); + vertex.setZ( pt.getZ() ); + + getVertices().add( vertex ); } } + + int np = points.size(); - for ( int i = 0; i < steps; i ++ ) + for ( int i = 0; i < segments; i ++ ) { - for ( int k = 0, kl = points.size(); k < kl - 1; k ++ ) + for ( int j = 0, jl = points.size(); j < jl - 1; j ++ ) { - int a = i * kl + k; - int b = ( ( i + 1 ) % (steps + 1) ) * kl + k; - int c = ( ( i + 1 ) % (steps + 1) ) * kl + ( k + 1 ) % kl; - int d = i * kl + ( k + 1 ) % kl; + int base = j + np * i; + int a = base; + int b = base + np; + int c = base + 1 + np; + int d = base + 1; + + double u0 = i * inverseSegments; + double v0 = j * inversePointLength; + double u1 = u0 + inverseSegments; + double v1 = v0 + inversePointLength; -// getFaces().add( new Face4( a, b, c, d ) ); + getFaces().add( new Face3( a, b, d ) ); - double stepsf = steps / 1.0; getFaceVertexUvs().get( 0 ).add( Arrays.asList( - new Vector2( (1.0 - i / (double)stepsf), k / (double)kl ), - new Vector2( (1.0 - ( i + 1.0 ) / (double)stepsf), k / (double)kl ), - new Vector2( (1.0 - ( i + 1.0 ) / (double)stepsf), ( k + 1.0 ) / (double)kl ), - new Vector2( (1.0 - i / (double)stepsf), ( k + 1.0 ) / (double)kl ) - + new Vector2( u0, v0 ), + new Vector2( u1, v0 ), + new Vector2( u0, v1 ) + + ) ); + + getFaces().add( new Face3( b, c, d ) ); + + getFaceVertexUvs().get( 0 ).add( Arrays.asList( + + new Vector2( u1, v0 ), + new Vector2( u1, v1 ), + new Vector2( u0, v1 ) + ) ); } } diff --git a/src/thothbot/parallax/core/shared/geometries/PlaneBufferGeometry.java b/src/thothbot/parallax/core/shared/geometries/PlaneBufferGeometry.java index 98722fed..9d9c6536 100644 --- a/src/thothbot/parallax/core/shared/geometries/PlaneBufferGeometry.java +++ b/src/thothbot/parallax/core/shared/geometries/PlaneBufferGeometry.java @@ -56,15 +56,15 @@ public PlaneBufferGeometry(int width, int height, int widthSegments, int heightS for ( int ix = 0; ix < gridX1; ix ++ ) { - double x = ix * segment_width - width_half; + double x = (double)(ix * segment_width) - width_half; vertices.set( offset, x); vertices.set( offset + 1, - y); - normals.set( offset + 2, 1); + normals.set( offset + 2, 1.0); - uvs.set( offset2, ix / gridX); - uvs.set( offset2 + 1, 1 - ( iy / gridY )); + uvs.set( offset2, ix / (double)gridX); + uvs.set( offset2 + 1, 1.0 - ( iy / (double)gridY )); offset += 3; offset2 += 2; diff --git a/src/thothbot/parallax/core/shared/geometries/RingGeometry.java b/src/thothbot/parallax/core/shared/geometries/RingGeometry.java new file mode 100644 index 00000000..1e9f8b31 --- /dev/null +++ b/src/thothbot/parallax/core/shared/geometries/RingGeometry.java @@ -0,0 +1,98 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.geometries; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import thothbot.parallax.core.shared.core.Face3; +import thothbot.parallax.core.shared.core.Geometry; +import thothbot.parallax.core.shared.math.Sphere; +import thothbot.parallax.core.shared.math.Vector2; +import thothbot.parallax.core.shared.math.Vector3; + +public class RingGeometry extends Geometry { + + public RingGeometry(double innerRadius, double outerRadius) { + this(innerRadius, outerRadius, 8, 8, 0, Math.PI * 2.0); + } + + public RingGeometry( double innerRadius, double outerRadius, int thetaSegments, int phiSegments, double thetaStart, double thetaLength ) { + + super(); + + thetaSegments = Math.max( 3, thetaSegments ); + phiSegments = Math.max( 1, phiSegments ); + + double radius = innerRadius; + double radiusStep = ( ( outerRadius - innerRadius ) / phiSegments ); + + List uvs = new ArrayList(); + + for ( int i = 0; i < phiSegments + 1; i ++ ) { // concentric circles inside ring + + for ( int o = 0; o < thetaSegments + 1; o ++ ) { // number of segments per circle + + Vector3 vertex = new Vector3(); + double segment = thetaStart + (double)o / thetaSegments * thetaLength; + vertex.setX( radius * Math.cos( segment ) ); + vertex.setY( radius * Math.sin( segment ) ); + + this.getVertices().add( vertex ); + uvs.add( new Vector2( ( vertex.getX() / outerRadius + 1.0 ) / 2.0, ( vertex.getY() / outerRadius + 1.0 ) / 2.0 ) ); + } + + radius += radiusStep; + + } + + Vector3 n = new Vector3( 0, 0, 1 ); + + for ( int i = 0; i < phiSegments; i ++ ) { // concentric circles inside ring + + int thetaSegment = i * (thetaSegments + 1); + + for ( int o = 0; o < thetaSegments ; o ++ ) { // number of segments per circle + + int segment = o + thetaSegment; + + int v1 = segment; + int v2 = segment + thetaSegments + 1; + int v3 = segment + thetaSegments + 2; + + this.getFaces().add( new Face3( v1, v2, v3, Arrays.asList( n.clone(), n.clone(), n.clone() ) ) ); + this.getFaceVertexUvs().get( 0 ).add( Arrays.asList( uvs.get( v1 ).clone(), uvs.get( v2 ).clone(), uvs.get( v3 ).clone() )); + + v1 = segment; + v2 = segment + thetaSegments + 2; + v3 = segment + 1; + + this.getFaces().add( new Face3( v1, v2, v3, Arrays.asList( n.clone(), n.clone(), n.clone() ) ) ); + this.getFaceVertexUvs().get( 0 ).add( Arrays.asList( uvs.get( v1 ).clone(), uvs.get( v2 ).clone(), uvs.get( v3 ).clone() )); + + } + } + + this.computeFaceNormals(); + + this.boundingSphere = new Sphere( new Vector3(), radius ); + + } +} From 7b67f8229497c0ef7fd7e8b18154469da32027de Mon Sep 17 00:00:00 2001 From: thothbot Date: Sat, 24 Jan 2015 02:35:29 +0300 Subject: [PATCH 03/75] Organized imports --- .../client/gl2/WebGLRenderingContext.java | 1 - .../core/client/renderers/ShadowMap.java | 1 - .../core/client/renderers/WebGLRenderer.java | 1 - .../client/renderers/WebGlRendererInfo.java | 2 + .../core/client/shaders/DepthShader.java | 1 - .../textures/RenderTargetCubeTexture.java | 1 - .../parallax/core/shared/cameras/Camera.java | 1 - .../core/shared/core/DimensionalObject.java | 224 ---------------- .../parallax/core/shared/core/Geometry.java | 2 - .../core/shared/core/GeometryGroup.java | 11 +- .../parallax/core/shared/core/Raycaster.java | 8 - .../parallax/core/shared/curves/Shape.java | 2 - .../core/shared/geometries/LatheGeometry.java | 2 - .../shared/geometries/PolyhedronGeometry.java | 2 +- .../core/shared/geometries/TubeGeometry.java | 1 - .../core/shared/helpers/ArrowHelper.java | 1 - .../core/shared/lights/SpotLight.java | 4 - .../core/shared/materials/Material.java | 1 - .../shared/materials/MeshNormalMaterial.java | 2 - .../parallax/core/shared/math/Box3.java | 1 - .../parallax/core/shared/math/Euler.java | 1 - .../parallax/core/shared/math/Frustum.java | 2 - .../core/shared/math/Mathematics.java | 1 - .../parallax/core/shared/math/Matrix4.java | 2 - .../parallax/core/shared/math/Quaternion.java | 1 - .../parallax/core/shared/objects/Bone.java | 36 --- .../parallax/core/shared/objects/Mesh.java | 2 +- .../core/shared/objects/MorphAnimMesh.java | 11 +- .../core/shared/objects/PointCloud.java | 3 - .../core/shared/objects/SkinnedMesh.java | 1 - .../parallax/core/shared/scenes/Scene.java | 247 +----------------- .../core/shared/utils/SceneUtils.java | 4 +- .../core/shared/utils/ShapeUtils.java | 4 +- .../core/shared/utils/UniformsUtils.java | 4 +- .../loader/shared/collada/DaeIdElement.java | 2 - .../loader/shared/collada/DaeMesh.java | 1 - .../loader/shared/collada/DaeNode.java | 1 - .../loader/shared/collada/DaePrimitive.java | 3 - .../loader/shared/collada/DaeTriangles.java | 2 - .../loader/shared/json/JsoObject.java | 2 - .../plugins/lensflare/LensFlarePlugin.java | 3 +- .../postprocessing/Postprocessing.java | 2 +- .../parallax/plugins/sprite/Sprite.java | 1 - .../parallax/plugins/sprite/SpritePlugin.java | 3 +- .../plugins/sprite/shaders/SpriteShader.java | 3 - 45 files changed, 19 insertions(+), 592 deletions(-) delete mode 100644 src/thothbot/parallax/core/shared/core/DimensionalObject.java diff --git a/src/thothbot/parallax/core/client/gl2/WebGLRenderingContext.java b/src/thothbot/parallax/core/client/gl2/WebGLRenderingContext.java index 2fd14d4a..a5e6447c 100644 --- a/src/thothbot/parallax/core/client/gl2/WebGLRenderingContext.java +++ b/src/thothbot/parallax/core/client/gl2/WebGLRenderingContext.java @@ -54,7 +54,6 @@ import thothbot.parallax.core.client.gl2.enums.TextureParameterName; import thothbot.parallax.core.client.gl2.enums.TextureTarget; import thothbot.parallax.core.client.gl2.enums.TextureUnit; -import thothbot.parallax.core.shared.Log; import com.google.gwt.canvas.dom.client.Context; import com.google.gwt.canvas.dom.client.ImageData; diff --git a/src/thothbot/parallax/core/client/renderers/ShadowMap.java b/src/thothbot/parallax/core/client/renderers/ShadowMap.java index 1564c6df..07291f63 100644 --- a/src/thothbot/parallax/core/client/renderers/ShadowMap.java +++ b/src/thothbot/parallax/core/client/renderers/ShadowMap.java @@ -54,7 +54,6 @@ import thothbot.parallax.core.shared.math.Matrix4; import thothbot.parallax.core.shared.math.Vector2; import thothbot.parallax.core.shared.math.Vector3; -import thothbot.parallax.core.shared.objects.Mesh; import thothbot.parallax.core.shared.objects.SkinnedMesh; import thothbot.parallax.core.shared.scenes.Scene; diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index 73b0f9aa..31195b2c 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -19,7 +19,6 @@ package thothbot.parallax.core.client.renderers; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; diff --git a/src/thothbot/parallax/core/client/renderers/WebGlRendererInfo.java b/src/thothbot/parallax/core/client/renderers/WebGlRendererInfo.java index a0bb6e4d..0a23160e 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGlRendererInfo.java +++ b/src/thothbot/parallax/core/client/renderers/WebGlRendererInfo.java @@ -19,6 +19,8 @@ package thothbot.parallax.core.client.renderers; import thothbot.parallax.core.client.debugger.Debugger; +import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.scenes.Scene; import com.google.gwt.core.client.Duration; diff --git a/src/thothbot/parallax/core/client/shaders/DepthShader.java b/src/thothbot/parallax/core/client/shaders/DepthShader.java index 426074f9..d1aeedcc 100644 --- a/src/thothbot/parallax/core/client/shaders/DepthShader.java +++ b/src/thothbot/parallax/core/client/shaders/DepthShader.java @@ -23,7 +23,6 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.resources.client.TextResource; -import com.google.gwt.resources.client.ClientBundle.Source; /** * Simple depth shader. diff --git a/src/thothbot/parallax/core/client/textures/RenderTargetCubeTexture.java b/src/thothbot/parallax/core/client/textures/RenderTargetCubeTexture.java index d53b0fae..2b64d54e 100644 --- a/src/thothbot/parallax/core/client/textures/RenderTargetCubeTexture.java +++ b/src/thothbot/parallax/core/client/textures/RenderTargetCubeTexture.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.List; -import thothbot.parallax.core.client.gl2.WebGLConstants; import thothbot.parallax.core.client.gl2.WebGLFramebuffer; import thothbot.parallax.core.client.gl2.WebGLRenderbuffer; import thothbot.parallax.core.client.gl2.WebGLRenderingContext; diff --git a/src/thothbot/parallax/core/shared/cameras/Camera.java b/src/thothbot/parallax/core/shared/cameras/Camera.java index 13a21e6c..a1ffd0cb 100644 --- a/src/thothbot/parallax/core/shared/cameras/Camera.java +++ b/src/thothbot/parallax/core/shared/cameras/Camera.java @@ -21,7 +21,6 @@ import thothbot.parallax.core.client.events.HasEventBus; import thothbot.parallax.core.client.events.ViewportResizeEvent; import thothbot.parallax.core.client.events.ViewportResizeHandler; -import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.shared.core.Object3D; import thothbot.parallax.core.shared.math.Matrix4; import thothbot.parallax.core.shared.math.Quaternion; diff --git a/src/thothbot/parallax/core/shared/core/DimensionalObject.java b/src/thothbot/parallax/core/shared/core/DimensionalObject.java deleted file mode 100644 index a5f1609b..00000000 --- a/src/thothbot/parallax/core/shared/core/DimensionalObject.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright 2012 Alex Usachev, thothbot@gmail.com - * - * This file is part of Parallax project. - * - * Parallax is free software: you can redistribute it and/or modify it - * under the terms of the Creative Commons Attribution 3.0 Unported License. - * - * Parallax is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution - * 3.0 Unported License. for more details. - * - * You should have received a copy of the the Creative Commons Attribution - * 3.0 Unported License along with Parallax. - * If not, see http://creativecommons.org/licenses/by/3.0/. - */ - -package thothbot.parallax.core.shared.core; - -import java.util.Collection; -import java.util.List; - -import thothbot.parallax.core.shared.math.Matrix4; -import thothbot.parallax.core.shared.math.Quaternion; -import thothbot.parallax.core.shared.math.Vector3; - -/** - * Abstract Dimensional Object - * - * @author thothbot - */ -public interface DimensionalObject -{ - /** - * Gets object ID. - * - * @return the object ID - */ - public int getId(); - - /** - * Gets name of the current object. - * - * @return the name of the object - */ - public String getName(); - - /** - * Adds child object to the current object - * - * @param child - * the Child DimensionalObject - */ - public void add(E child); - - /** - * Removes child DimensionalObject from the current object - * - * @param child - * the Child DimensionalObject - */ - public void remove(E child); - - /** - * Gets list of children DimensionalObject associated with the current - * object. - * - * @return the list of children DimensionalObject - */ - public List getChildren(); - - /** - * Gets child DimensionalObject associated with the current object by its - * name. - * - * @param name - * the name of child DimensionalObject - * @param recursive - * flag to search in children objects - * - * @return the child DimensionalObject - */ - public DimensionalObject getChildByName(String name, boolean recursive); - - public List getChildrenByClass(Class clazz, boolean recursive); - - /** - * Gets parent DimensionalObject in which this object is included. - * - * @return the parent DimensionalObject - */ - public DimensionalObject getParent(); - - public boolean isDynamic(); - - public boolean isMatrixAutoUpdate(); - - public void setMatrixAutoUpdate(boolean autoUpdate); - - public boolean isMatrixWorldNeedsUpdate(); - - public void setMatrixWorldNeedsUpdate(boolean needsUpdate); - - public boolean isRotationAutoUpdate(); - - public void setRotationAutoUpdate(boolean rotationAutoUpdate); - - public boolean isUseQuaternion(); - - public void setUseQuaternion(boolean use); - - /** - * Chicks if the DimensionalObject visible or not - */ - public boolean isVisible(); - - /** - * Sets object visibility. - * - * @param visible the visibility: true of false - */ - public void setVisible(boolean visible); - - public double getBoundRadius(); - - public double getBoundRadiusScale(); - - public Matrix4 getMatrix(); - - public Matrix4 getMatrixRotationWorld(); - - public Matrix4 getMatrixWorld(); - - public Vector3 getPosition(); - - public Quaternion getQuaternion(); - - public Vector3 getRotation(); - - public Vector3 getScale(); - - public Vector3 getUp(); - - /** - * Looks at specific point - * @param vector - the point to look at - */ - public void lookAt(Vector3 vector); - - public void setBoundRadius(double boundRadius); - - public void setBoundRadiusScale(double scale); - - public void setChildren(Collection children); - - public void setDynamic(boolean dynamic); - - public void setMatrix(Matrix4 matrix); - - public void setMatrixRotationWorld(Matrix4 rotation); - - public void setMatrixWorld(Matrix4 matrixWorld); - - public void setName(String name); - - public void setParent(DimensionalObject parent); - - public void setPosition(Vector3 position); - - public void setQuaternion(Quaternion quaternion); - - public void setRotation(Vector3 rotation); - - public void setScale(Vector3 scale); - - public void setUp(Vector3 up); - - public void applyMatrix(Matrix4 matrix); - - /** - * Moves object on XYZ-axis by defined distance. - * - * @param distance the moving distance - * @param axis the axis - */ - public void translate(double distance, Vector3 axis); - - /** - * Moves object on X-axis by defined distance. - * - * @param distance the moving distance - */ - public void translateX(double distance); - - /** - * Moves object on Y-axis by defined distance. - * - * @param distance the moving distance - */ - public void translateY(double distance); - - /** - * Moves object on Z-axis by defined distance. - * - * @param distance the moving distance - */ - public void translateZ(double distance); - - public Vector3 localToWorld( Vector3 vector ); - - public Vector3 worldToLocal( Vector3 vector ); - - public List getDescendants(); - - /** - * Does update of the object's matrix - */ - public void updateMatrix(); - - public void updateMatrixWorld(boolean force); - - public DimensionalObject clone(); -} diff --git a/src/thothbot/parallax/core/shared/core/Geometry.java b/src/thothbot/parallax/core/shared/core/Geometry.java index 9f2a4360..b5b9579f 100644 --- a/src/thothbot/parallax/core/shared/core/Geometry.java +++ b/src/thothbot/parallax/core/shared/core/Geometry.java @@ -26,8 +26,6 @@ import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.client.gl2.arrays.Uint16Array; -import thothbot.parallax.core.shared.Log; -import thothbot.parallax.core.shared.materials.Material; import thothbot.parallax.core.shared.math.Box3; import thothbot.parallax.core.shared.math.Color; import thothbot.parallax.core.shared.math.Matrix3; diff --git a/src/thothbot/parallax/core/shared/core/GeometryGroup.java b/src/thothbot/parallax/core/shared/core/GeometryGroup.java index 985c8e63..c16ada6a 100644 --- a/src/thothbot/parallax/core/shared/core/GeometryGroup.java +++ b/src/thothbot/parallax/core/shared/core/GeometryGroup.java @@ -23,18 +23,11 @@ import java.util.List; import java.util.Map; -import com.google.gwt.core.client.GWT; - -import thothbot.parallax.core.client.gl2.WebGLBuffer; -import thothbot.parallax.core.client.gl2.WebGLRenderingContext; import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.client.gl2.arrays.Uint16Array; -import thothbot.parallax.core.client.renderers.WebGLExtensions; import thothbot.parallax.core.client.renderers.WebGLGeometry; -import thothbot.parallax.core.client.renderers.WebGLExtensions.Id; -import thothbot.parallax.core.client.shaders.Shader; -import thothbot.parallax.core.shared.materials.MeshFaceMaterial; -import thothbot.parallax.core.shared.scenes.Scene; + +import com.google.gwt.core.client.GWT; public class GeometryGroup extends WebGLGeometry { diff --git a/src/thothbot/parallax/core/shared/core/Raycaster.java b/src/thothbot/parallax/core/shared/core/Raycaster.java index 9efcecc9..55526872 100644 --- a/src/thothbot/parallax/core/shared/core/Raycaster.java +++ b/src/thothbot/parallax/core/shared/core/Raycaster.java @@ -22,16 +22,8 @@ import java.util.Collections; import java.util.List; -import thothbot.parallax.core.shared.materials.Material; -import thothbot.parallax.core.shared.materials.MeshFaceMaterial; -import thothbot.parallax.core.shared.math.Matrix4; -import thothbot.parallax.core.shared.math.Plane; import thothbot.parallax.core.shared.math.Ray; -import thothbot.parallax.core.shared.math.Sphere; -import thothbot.parallax.core.shared.math.Triangle; import thothbot.parallax.core.shared.math.Vector3; -import thothbot.parallax.core.shared.objects.Mesh; -import thothbot.parallax.core.shared.objects.PointCloud; public class Raycaster { diff --git a/src/thothbot/parallax/core/shared/curves/Shape.java b/src/thothbot/parallax/core/shared/curves/Shape.java index 375020a0..8a3dace1 100644 --- a/src/thothbot/parallax/core/shared/curves/Shape.java +++ b/src/thothbot/parallax/core/shared/curves/Shape.java @@ -21,9 +21,7 @@ import java.util.ArrayList; import java.util.List; -import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.core.ExtrudeGeometry; -import thothbot.parallax.core.shared.math.Vector; import thothbot.parallax.core.shared.math.Vector2; /** diff --git a/src/thothbot/parallax/core/shared/geometries/LatheGeometry.java b/src/thothbot/parallax/core/shared/geometries/LatheGeometry.java index dce67c77..99dfb174 100644 --- a/src/thothbot/parallax/core/shared/geometries/LatheGeometry.java +++ b/src/thothbot/parallax/core/shared/geometries/LatheGeometry.java @@ -18,13 +18,11 @@ package thothbot.parallax.core.shared.geometries; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import thothbot.parallax.core.shared.core.Face3; import thothbot.parallax.core.shared.core.Geometry; -import thothbot.parallax.core.shared.math.Matrix4; import thothbot.parallax.core.shared.math.Vector2; import thothbot.parallax.core.shared.math.Vector3; diff --git a/src/thothbot/parallax/core/shared/geometries/PolyhedronGeometry.java b/src/thothbot/parallax/core/shared/geometries/PolyhedronGeometry.java index 9038cc59..480f5028 100644 --- a/src/thothbot/parallax/core/shared/geometries/PolyhedronGeometry.java +++ b/src/thothbot/parallax/core/shared/geometries/PolyhedronGeometry.java @@ -199,6 +199,6 @@ protected Vector2 correctUV( Vector2 uv, Vector3 vector, double azimuth ) if ( (vector.getX() == 0) && (vector.getZ() == 0) ) uv = new Vector2( azimuth / 2.0 / Math.PI + 0.5, uv.getY() ); - return uv; + return uv.clone(); } } diff --git a/src/thothbot/parallax/core/shared/geometries/TubeGeometry.java b/src/thothbot/parallax/core/shared/geometries/TubeGeometry.java index 650be7ca..15599098 100644 --- a/src/thothbot/parallax/core/shared/geometries/TubeGeometry.java +++ b/src/thothbot/parallax/core/shared/geometries/TubeGeometry.java @@ -25,7 +25,6 @@ import thothbot.parallax.core.shared.core.Face3; import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.curves.Curve; -import thothbot.parallax.core.shared.helpers.ArrowHelper; import thothbot.parallax.core.shared.math.Vector2; import thothbot.parallax.core.shared.math.Vector3; diff --git a/src/thothbot/parallax/core/shared/helpers/ArrowHelper.java b/src/thothbot/parallax/core/shared/helpers/ArrowHelper.java index bd4f44d8..6d427acc 100644 --- a/src/thothbot/parallax/core/shared/helpers/ArrowHelper.java +++ b/src/thothbot/parallax/core/shared/helpers/ArrowHelper.java @@ -25,7 +25,6 @@ import thothbot.parallax.core.shared.materials.MeshBasicMaterial; import thothbot.parallax.core.shared.math.Color; import thothbot.parallax.core.shared.math.Matrix4; -import thothbot.parallax.core.shared.math.Quaternion; import thothbot.parallax.core.shared.math.Vector3; import thothbot.parallax.core.shared.objects.Line; import thothbot.parallax.core.shared.objects.Mesh; diff --git a/src/thothbot/parallax/core/shared/lights/SpotLight.java b/src/thothbot/parallax/core/shared/lights/SpotLight.java index 75f0f513..c7ce0c86 100644 --- a/src/thothbot/parallax/core/shared/lights/SpotLight.java +++ b/src/thothbot/parallax/core/shared/lights/SpotLight.java @@ -23,12 +23,8 @@ import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.client.renderers.RendererLights; import thothbot.parallax.core.client.shaders.Uniform; -import thothbot.parallax.core.client.textures.RenderTargetTexture; -import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.materials.MeshLambertMaterial; import thothbot.parallax.core.shared.materials.MeshPhongMaterial; -import thothbot.parallax.core.shared.math.Matrix4; -import thothbot.parallax.core.shared.math.Vector2; import thothbot.parallax.core.shared.math.Vector3; /** diff --git a/src/thothbot/parallax/core/shared/materials/Material.java b/src/thothbot/parallax/core/shared/materials/Material.java index 2e2bf361..d875f650 100644 --- a/src/thothbot/parallax/core/shared/materials/Material.java +++ b/src/thothbot/parallax/core/shared/materials/Material.java @@ -36,7 +36,6 @@ import thothbot.parallax.core.client.textures.Texture; import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; -import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.core.GeometryGroup; import thothbot.parallax.core.shared.core.GeometryObject; import thothbot.parallax.core.shared.math.Color; diff --git a/src/thothbot/parallax/core/shared/materials/MeshNormalMaterial.java b/src/thothbot/parallax/core/shared/materials/MeshNormalMaterial.java index 3029fd29..59e55eff 100644 --- a/src/thothbot/parallax/core/shared/materials/MeshNormalMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/MeshNormalMaterial.java @@ -18,8 +18,6 @@ package thothbot.parallax.core.shared.materials; -import com.google.gwt.safehtml.client.HasSafeHtml; - import thothbot.parallax.core.client.shaders.NormalShader; import thothbot.parallax.core.client.shaders.Shader; import thothbot.parallax.core.shared.cameras.Camera; diff --git a/src/thothbot/parallax/core/shared/math/Box3.java b/src/thothbot/parallax/core/shared/math/Box3.java index a742ebf7..a9e19024 100644 --- a/src/thothbot/parallax/core/shared/math/Box3.java +++ b/src/thothbot/parallax/core/shared/math/Box3.java @@ -18,7 +18,6 @@ package thothbot.parallax.core.shared.math; -import java.util.Arrays; import java.util.List; import thothbot.parallax.core.client.gl2.arrays.Float32Array; diff --git a/src/thothbot/parallax/core/shared/math/Euler.java b/src/thothbot/parallax/core/shared/math/Euler.java index 095ddc27..3ebedc71 100644 --- a/src/thothbot/parallax/core/shared/math/Euler.java +++ b/src/thothbot/parallax/core/shared/math/Euler.java @@ -20,7 +20,6 @@ import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.shared.Log; -import thothbot.parallax.core.shared.math.Quaternion.QuaternionChangeHandler; public class Euler { diff --git a/src/thothbot/parallax/core/shared/math/Frustum.java b/src/thothbot/parallax/core/shared/math/Frustum.java index 4412d4a4..776f85a4 100644 --- a/src/thothbot/parallax/core/shared/math/Frustum.java +++ b/src/thothbot/parallax/core/shared/math/Frustum.java @@ -22,9 +22,7 @@ import java.util.List; import thothbot.parallax.core.client.gl2.arrays.Float32Array; -import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.core.AbstractGeometry; -import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.core.GeometryObject; /** diff --git a/src/thothbot/parallax/core/shared/math/Mathematics.java b/src/thothbot/parallax/core/shared/math/Mathematics.java index bf81aa02..4044e08e 100644 --- a/src/thothbot/parallax/core/shared/math/Mathematics.java +++ b/src/thothbot/parallax/core/shared/math/Mathematics.java @@ -18,7 +18,6 @@ package thothbot.parallax.core.shared.math; -import java.lang.reflect.Array; /** * Class implements some mathematical helpers methods. diff --git a/src/thothbot/parallax/core/shared/math/Matrix4.java b/src/thothbot/parallax/core/shared/math/Matrix4.java index 34bd0741..67a1c11f 100644 --- a/src/thothbot/parallax/core/shared/math/Matrix4.java +++ b/src/thothbot/parallax/core/shared/math/Matrix4.java @@ -18,8 +18,6 @@ package thothbot.parallax.core.shared.math; -import com.google.gwt.core.client.JsArrayNumber; - import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.shared.Log; diff --git a/src/thothbot/parallax/core/shared/math/Quaternion.java b/src/thothbot/parallax/core/shared/math/Quaternion.java index 3ddef0a0..f4daf470 100644 --- a/src/thothbot/parallax/core/shared/math/Quaternion.java +++ b/src/thothbot/parallax/core/shared/math/Quaternion.java @@ -19,7 +19,6 @@ package thothbot.parallax.core.shared.math; import thothbot.parallax.core.client.gl2.arrays.Float32Array; -import thothbot.parallax.core.client.textures.Texture; /** * Implementation of Quaternion which provide a convenient mathematical notation diff --git a/src/thothbot/parallax/core/shared/objects/Bone.java b/src/thothbot/parallax/core/shared/objects/Bone.java index 3df8732b..8e658308 100644 --- a/src/thothbot/parallax/core/shared/objects/Bone.java +++ b/src/thothbot/parallax/core/shared/objects/Bone.java @@ -18,52 +18,16 @@ package thothbot.parallax.core.shared.objects; -import thothbot.parallax.core.shared.core.DimensionalObject; import thothbot.parallax.core.shared.core.Object3D; -import thothbot.parallax.core.shared.math.Matrix4; public class Bone extends Object3D { public Object3D skin; -// public Matrix4 skinMatrix; -// public Matrix4 identityMatrix; -// -// public Bone() -// { -// this.skinMatrix = new Matrix4(); -// } public Bone(Object3D belongsToSkin) { -// this(); this.skin = belongsToSkin; } -// public void update( Matrix4 parentSkinMatrix, boolean forceUpdate ) -// { -// // update local -// if ( this.matrixAutoUpdate ) -// this.updateMatrix(); -// -// // update skin matrix -// if ( forceUpdate || this.matrixWorldNeedsUpdate ) -// { -// -// if( parentSkinMatrix != null ) -// this.skinMatrix.multiply( parentSkinMatrix, this.matrix ); -// else -// this.skinMatrix.copy( this.matrix ); -// -// this.matrixWorldNeedsUpdate = false; -// forceUpdate = true; -// } -// -// // update children -// for ( DimensionalObject children : this.getChildren()) -// { -// Bone bone = (Bone) children; -// bone.update( this.skinMatrix, forceUpdate ); -// } -// } } diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index f99cd026..a0d315fe 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -41,9 +41,9 @@ import thothbot.parallax.core.shared.core.Face3; import thothbot.parallax.core.shared.core.FastMap; import thothbot.parallax.core.shared.core.Geometry; -import thothbot.parallax.core.shared.core.GeometryGroup; import thothbot.parallax.core.shared.core.Geometry.MorphNormal; import thothbot.parallax.core.shared.core.Geometry.MorphTarget; +import thothbot.parallax.core.shared.core.GeometryGroup; import thothbot.parallax.core.shared.core.GeometryObject; import thothbot.parallax.core.shared.core.Raycaster; import thothbot.parallax.core.shared.materials.HasSkinning; diff --git a/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java b/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java index 54d51234..5351f4a4 100644 --- a/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java +++ b/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java @@ -21,14 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import com.google.gwt.core.client.GWT; -import com.google.gwt.regexp.shared.MatchResult; -import com.google.gwt.regexp.shared.RegExp; - -import thothbot.parallax.core.client.shaders.Shader; import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.core.FastMap; import thothbot.parallax.core.shared.core.Geometry; @@ -36,6 +29,10 @@ import thothbot.parallax.core.shared.materials.Material; import thothbot.parallax.core.shared.math.Mathematics; +import com.google.gwt.core.client.GWT; +import com.google.gwt.regexp.shared.MatchResult; +import com.google.gwt.regexp.shared.RegExp; + public class MorphAnimMesh extends Mesh { public class Animation { diff --git a/src/thothbot/parallax/core/shared/objects/PointCloud.java b/src/thothbot/parallax/core/shared/objects/PointCloud.java index dcb93d18..90352785 100644 --- a/src/thothbot/parallax/core/shared/objects/PointCloud.java +++ b/src/thothbot/parallax/core/shared/objects/PointCloud.java @@ -20,8 +20,6 @@ import java.util.List; -import com.gargoylesoftware.htmlunit.javascript.host.Console; - import thothbot.parallax.core.client.gl2.WebGLRenderingContext; import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.client.gl2.arrays.Uint16Array; @@ -34,7 +32,6 @@ import thothbot.parallax.core.client.shaders.Attribute; import thothbot.parallax.core.client.shaders.Attribute.BOUND_TO; import thothbot.parallax.core.client.shaders.Attribute.TYPE; -import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.BufferGeometry; import thothbot.parallax.core.shared.core.BufferGeometry.DrawCall; diff --git a/src/thothbot/parallax/core/shared/objects/SkinnedMesh.java b/src/thothbot/parallax/core/shared/objects/SkinnedMesh.java index 8e5f063e..dc6e336f 100644 --- a/src/thothbot/parallax/core/shared/objects/SkinnedMesh.java +++ b/src/thothbot/parallax/core/shared/objects/SkinnedMesh.java @@ -27,7 +27,6 @@ import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.materials.Material; -import thothbot.parallax.core.shared.math.Euler; import thothbot.parallax.core.shared.math.Matrix4; import thothbot.parallax.core.shared.math.Quaternion; import thothbot.parallax.core.shared.math.Vector3; diff --git a/src/thothbot/parallax/core/shared/scenes/Scene.java b/src/thothbot/parallax/core/shared/scenes/Scene.java index c50c2a7a..2d7cf117 100644 --- a/src/thothbot/parallax/core/shared/scenes/Scene.java +++ b/src/thothbot/parallax/core/shared/scenes/Scene.java @@ -19,13 +19,12 @@ package thothbot.parallax.core.shared.scenes; import thothbot.parallax.core.shared.cameras.Camera; -import thothbot.parallax.core.shared.core.DimensionalObject; import thothbot.parallax.core.shared.core.Object3D; import thothbot.parallax.core.shared.materials.Material; /** * 3D Scene. The basic class for rendering. - * To use this Object in rendering you should add at least one {@link DimensionalObject} + * To use this Object in rendering you should add at least one {@link Object3D} * and {@link Camera}. * Also you may want to add Lights and {@link AbstractFog} to the Scene Object. * @@ -34,34 +33,6 @@ */ public final class Scene extends Object3D { -// /** -// * Here are stored cameras, geometries and other DimensionalObject -// */ -// private ArrayList objects; -// -// /** -// * History list of added DimensionalObject to the Scene. -// * This list needed to recalculate buffers from -// * the renderer -// */ -// private ArrayList objectsAdded; -// -// /** -// * History list of removed DimensionalObject from the Scene. -// * This list needed to recalculate buffers from -// * the renderer -// */ -// private ArrayList objectsRemoved; -// -// public List __webglObjects; -// -// public Material overrideMaterial; -// -// /** -// * Here are stored lights associated with the Scene -// */ -// private ArrayList lights; - /** * Here is stored fog */ @@ -77,13 +48,6 @@ public final class Scene extends Object3D public Scene() { super(); -// this.fogAbstract = null; -// this.objects = new ArrayList(); -// this.lights = new ArrayList(); -// this.objectsAdded = new ArrayList(); -// this.objectsRemoved = new ArrayList(); -// -// this.__webglObjects = new ArrayList(); } public Scene clone() { @@ -106,26 +70,6 @@ public Scene clone(Scene object ) { }; -// /** -// * Get DimensionalObject associated with the Scene. -// * -// * @return the list of DimensionalObject -// */ -// public ArrayList getObjects() -// { -// return this.objects; -// } -// -// /** -// * Get list of lights associated with the Scene. -// * -// * @return the list of lights. -// */ -// public ArrayList getLights() -// { -// return this.lights; -// } - /** * Get fogAbstract associated with the Scene. * @@ -145,193 +89,4 @@ public void setFog(AbstractFog fog) { this.fog = fog; } - -// -// /** -// * Return the history list of Dimensional objects added to the list. -// * -// * @return the list of DimensionalObject -// */ -// public ArrayList getObjectsAdded() -// { -// return this.objectsAdded; -// } -// -// /** -// * Return the history list of Dimensional objects removed to the list. -// * -// * @return the list of DimensionalObject -// */ -// public ArrayList getObjectsRemoved() -// { -// return this.objectsRemoved; -// } -// -// /** -// * Adding child DimensionalObject to the Scene -// * -// * @param child the DimensionalObject -// */ -// public void addSceneItem(E child) -// { -// if (child instanceof Light) -// { -// Light light = (Light)child; -// if (this.lights.indexOf(light) == -1) -// this.lights.add(light); -// } -// else if (!(child instanceof Camera || child instanceof Bone)) -// { -// if (this.objects.indexOf(child) == -1) -// { -// this.objects.add(child); -// this.objectsAdded.add(child); -// } -// } -// -// for (DimensionalObject item : child.getChildren()) -// this.addSceneItem(item); -// } -// -// /** -// * Removing child DimensionalObject from the Scene -// * -// * @param child the DimensionalObject -// */ -// public void removeSceneItem(E child) -// { -// if (child instanceof Light) -// { -// Light light = (Light)child; -// if (this.lights.indexOf(light) != -1) -// this.lights.remove(light); -// } -// else if (!(child instanceof Camera || child instanceof Bone)) -// { -// if (this.objects.indexOf(child) != -1){ -// this.objects.remove(child); -// this.objectsRemoved.add(child); -// } -// } -// -// for (DimensionalObject item : child.getChildren()) -// this.removeSceneItem(item); -// } -// -// /** -// * Refresh Scene's objects -// * -// * @param renderer the renderer instance -// */ -// public void initWebGLObjects(WebGLRenderer renderer) -// { -// Log.debug("initWebGLObjects() objectsAdded=" + getObjectsAdded().size() -// + ", objectsRemoved=" + getObjectsRemoved().size() -// + ", update=" + this.__webglObjects.size()); -// -// while ( getObjectsAdded().size() > 0 ) -// { -// // object.createBuffer()->initBuffer(), + __webglObject -// addObject( renderer, (Object3D) getObjectsAdded().get( 0 ) ); -// getObjectsAdded().remove(0); -// } -// -// while ( getObjectsRemoved().size() > 0 ) -// { -// removeObject( (Object3D) getObjectsRemoved().get( 0 ) ); -// getObjectsRemoved().remove(0); -// } -// -// // update must be called after objects adding / removal -// for(RendererObject object: this.__webglObjects) -// { -// object.object.setBuffer(renderer); -// } -// } -// -// /** -// * Adds objects -// */ -// private void addObject ( WebGLRenderer renderer, Object3D object ) -// { -// Log.debug("addObject() object=" + object.getClass().getName()); -// -// if ( object instanceof GeometryObject && ! object.isWebglInit ) -// { -// object.isWebglInit = true; -// -// Log.debug("addObject() initBuffer()"); -// ((GeometryObject)object).initBuffer(renderer); -// } -// -// if ( ! object.isWebglActive ) -// { -// object.isWebglActive = true; -// -// Log.debug("addObject() addObjectAddBuffer()"); -// addObjectAddBuffer( object ); -// } -// } -// -// /* -// * Objects removal -// */ -// private void removeObject ( Object3D object ) -// { -// if ( object instanceof GeometryObject) -// { -// for ( int o = this.__webglObjects.size() - 1; o >= 0; o -- ) -// if ( this.__webglObjects.get( o ).object == object ) -// this.__webglObjects.remove(o); -// } -// -// object.isWebglActive = false; -// } -// -// private void addObjectAddBuffer(Object3D object) -// { -// if(object instanceof GeometryObject) -// { -// if ( object instanceof Mesh ) -// { -// Mesh mesh = (Mesh)object; -// Geometry geometry = mesh.getGeometry(); -// -// if(mesh.getGeometryBuffer() != null) -// { -// addBuffer( mesh.getGeometryBuffer(), (GeometryObject)object ); -// } -// else -// { -// for ( GeometryGroup geometryGroup : geometry.getGeometryGroups()) -// { -// addBuffer( geometryGroup, (GeometryObject)object ); -// } -// } -// } -// if ( object instanceof ParticleSystem ) -// { -// if(((GeometryObject)object).getGeometryBuffer() != null) -// { -// addBuffer( ((GeometryObject)object).getGeometryBuffer(), (GeometryObject)object ); -// } -// else -// { -// addBuffer( ((GeometryObject)object).getGeometry(), (GeometryObject)object ); -// } -// } -// else if ( object instanceof Ribbon || -// object instanceof Line -// ) { -// -// Geometry geometry = ((GeometryObject)object).getGeometry(); -// addBuffer( geometry, (GeometryObject)object ); -// } -// } -// } -// -// private void addBuffer (BufferGeometry buffer, GeometryObject object ) -// { -// this.__webglObjects.add(new RendererObject(buffer, object, null, null)); -// } } diff --git a/src/thothbot/parallax/core/shared/utils/SceneUtils.java b/src/thothbot/parallax/core/shared/utils/SceneUtils.java index aaa23fa5..f6e030ec 100644 --- a/src/thothbot/parallax/core/shared/utils/SceneUtils.java +++ b/src/thothbot/parallax/core/shared/utils/SceneUtils.java @@ -20,9 +20,7 @@ import java.util.List; -import thothbot.parallax.core.shared.core.DimensionalObject; import thothbot.parallax.core.shared.core.Geometry; -import thothbot.parallax.core.shared.core.GeometryObject; import thothbot.parallax.core.shared.core.Object3D; import thothbot.parallax.core.shared.materials.Material; import thothbot.parallax.core.shared.math.Matrix4; @@ -48,7 +46,7 @@ public class SceneUtils * @param geometry the input geometry. * @param list the list of materials. * - * @return the new instance of {@link DimensionalObject} + * @return the new instance of {@link Object3D} */ public static Object3D createMultiMaterialObject( Geometry geometry, List materials ) { diff --git a/src/thothbot/parallax/core/shared/utils/ShapeUtils.java b/src/thothbot/parallax/core/shared/utils/ShapeUtils.java index 01affb89..6b16f1c7 100644 --- a/src/thothbot/parallax/core/shared/utils/ShapeUtils.java +++ b/src/thothbot/parallax/core/shared/utils/ShapeUtils.java @@ -24,12 +24,12 @@ import java.util.List; import java.util.Map; -import com.google.gwt.core.client.GWT; - import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.core.FastMap; import thothbot.parallax.core.shared.math.Vector2; +import com.google.gwt.core.client.GWT; + /** * The class implements some 3D Shape related helper methods diff --git a/src/thothbot/parallax/core/shared/utils/UniformsUtils.java b/src/thothbot/parallax/core/shared/utils/UniformsUtils.java index a95460a9..22658232 100644 --- a/src/thothbot/parallax/core/shared/utils/UniformsUtils.java +++ b/src/thothbot/parallax/core/shared/utils/UniformsUtils.java @@ -21,11 +21,11 @@ import java.util.HashMap; import java.util.Map; -import com.google.gwt.core.client.GWT; - import thothbot.parallax.core.client.shaders.Uniform; import thothbot.parallax.core.shared.core.FastMap; +import com.google.gwt.core.client.GWT; + /** * The class implements some Uniform related helper methods * diff --git a/src/thothbot/parallax/loader/shared/collada/DaeIdElement.java b/src/thothbot/parallax/loader/shared/collada/DaeIdElement.java index fb6581da..a235cd4f 100644 --- a/src/thothbot/parallax/loader/shared/collada/DaeIdElement.java +++ b/src/thothbot/parallax/loader/shared/collada/DaeIdElement.java @@ -18,8 +18,6 @@ package thothbot.parallax.loader.shared.collada; -import thothbot.parallax.core.shared.Log; - import com.google.gwt.xml.client.Node; public class DaeIdElement extends DaeElement diff --git a/src/thothbot/parallax/loader/shared/collada/DaeMesh.java b/src/thothbot/parallax/loader/shared/collada/DaeMesh.java index 1c96635d..972dc7a6 100644 --- a/src/thothbot/parallax/loader/shared/collada/DaeMesh.java +++ b/src/thothbot/parallax/loader/shared/collada/DaeMesh.java @@ -26,7 +26,6 @@ import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.math.Vector3; -import thothbot.parallax.core.shared.objects.Mesh; import com.google.gwt.xml.client.Node; import com.google.gwt.xml.client.NodeList; diff --git a/src/thothbot/parallax/loader/shared/collada/DaeNode.java b/src/thothbot/parallax/loader/shared/collada/DaeNode.java index 3ec42d68..05dfcdac 100644 --- a/src/thothbot/parallax/loader/shared/collada/DaeNode.java +++ b/src/thothbot/parallax/loader/shared/collada/DaeNode.java @@ -23,7 +23,6 @@ import thothbot.parallax.core.shared.Log; -import com.google.gwt.xml.client.Element; import com.google.gwt.xml.client.Node; import com.google.gwt.xml.client.NodeList; diff --git a/src/thothbot/parallax/loader/shared/collada/DaePrimitive.java b/src/thothbot/parallax/loader/shared/collada/DaePrimitive.java index 6f97c01c..4a11437f 100644 --- a/src/thothbot/parallax/loader/shared/collada/DaePrimitive.java +++ b/src/thothbot/parallax/loader/shared/collada/DaePrimitive.java @@ -18,9 +18,6 @@ package thothbot.parallax.loader.shared.collada; -import java.util.HashMap; -import java.util.Map; - import thothbot.parallax.core.shared.Log; import com.google.gwt.xml.client.Node; diff --git a/src/thothbot/parallax/loader/shared/collada/DaeTriangles.java b/src/thothbot/parallax/loader/shared/collada/DaeTriangles.java index 43dd2446..5813fa33 100644 --- a/src/thothbot/parallax/loader/shared/collada/DaeTriangles.java +++ b/src/thothbot/parallax/loader/shared/collada/DaeTriangles.java @@ -21,8 +21,6 @@ import java.util.ArrayList; import java.util.List; -import thothbot.parallax.core.shared.Log; - import com.google.gwt.xml.client.Node; import com.google.gwt.xml.client.NodeList; diff --git a/src/thothbot/parallax/loader/shared/json/JsoObject.java b/src/thothbot/parallax/loader/shared/json/JsoObject.java index 274ef888..7d5f24c7 100644 --- a/src/thothbot/parallax/loader/shared/json/JsoObject.java +++ b/src/thothbot/parallax/loader/shared/json/JsoObject.java @@ -20,8 +20,6 @@ import java.util.List; -import thothbot.parallax.core.shared.objects.Bone; - public interface JsoObject { JsoMetadata getMetadata(); diff --git a/src/thothbot/parallax/plugins/lensflare/LensFlarePlugin.java b/src/thothbot/parallax/plugins/lensflare/LensFlarePlugin.java index 8e3d06df..de39ab70 100644 --- a/src/thothbot/parallax/plugins/lensflare/LensFlarePlugin.java +++ b/src/thothbot/parallax/plugins/lensflare/LensFlarePlugin.java @@ -40,14 +40,13 @@ import thothbot.parallax.core.client.gl2.enums.TextureParameterName; import thothbot.parallax.core.client.gl2.enums.TextureTarget; import thothbot.parallax.core.client.gl2.enums.TextureUnit; -import thothbot.parallax.core.shared.Log; -import thothbot.parallax.core.shared.lights.Light; import thothbot.parallax.core.client.renderers.Plugin; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.shaders.Attribute; import thothbot.parallax.core.client.shaders.Uniform; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.core.FastMap; +import thothbot.parallax.core.shared.lights.Light; import thothbot.parallax.core.shared.math.Vector2; import thothbot.parallax.core.shared.math.Vector3; import thothbot.parallax.core.shared.scenes.Scene; diff --git a/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java b/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java index 143f73da..67700968 100644 --- a/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java +++ b/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java @@ -28,7 +28,6 @@ import thothbot.parallax.core.client.gl2.enums.StencilFunction; import thothbot.parallax.core.client.gl2.enums.TextureMagFilter; import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; -import thothbot.parallax.core.shared.lights.Light; import thothbot.parallax.core.client.renderers.Plugin; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.textures.RenderTargetTexture; @@ -36,6 +35,7 @@ import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.OrthographicCamera; import thothbot.parallax.core.shared.geometries.PlaneGeometry; +import thothbot.parallax.core.shared.lights.Light; import thothbot.parallax.core.shared.objects.Mesh; import thothbot.parallax.core.shared.scenes.Scene; import thothbot.parallax.plugins.postprocessing.shaders.CopyShader; diff --git a/src/thothbot/parallax/plugins/sprite/Sprite.java b/src/thothbot/parallax/plugins/sprite/Sprite.java index 1a06a043..afb2dbe8 100644 --- a/src/thothbot/parallax/plugins/sprite/Sprite.java +++ b/src/thothbot/parallax/plugins/sprite/Sprite.java @@ -27,7 +27,6 @@ import thothbot.parallax.core.shared.math.Color; import thothbot.parallax.core.shared.math.Euler; import thothbot.parallax.core.shared.math.Vector2; -import thothbot.parallax.core.shared.math.Vector3; public class Sprite extends Object3D implements Comparable { diff --git a/src/thothbot/parallax/plugins/sprite/SpritePlugin.java b/src/thothbot/parallax/plugins/sprite/SpritePlugin.java index 6c46cd08..33ca2a3c 100644 --- a/src/thothbot/parallax/plugins/sprite/SpritePlugin.java +++ b/src/thothbot/parallax/plugins/sprite/SpritePlugin.java @@ -37,11 +37,10 @@ import thothbot.parallax.core.client.renderers.Plugin; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.shaders.Uniform; -import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.lights.Light; import thothbot.parallax.core.shared.scenes.Scene; import thothbot.parallax.plugins.sprite.shaders.SpriteShader; -import thothbot.parallax.core.shared.lights.Light; public final class SpritePlugin extends Plugin { diff --git a/src/thothbot/parallax/plugins/sprite/shaders/SpriteShader.java b/src/thothbot/parallax/plugins/sprite/shaders/SpriteShader.java index 98bf81a8..566aead4 100644 --- a/src/thothbot/parallax/plugins/sprite/shaders/SpriteShader.java +++ b/src/thothbot/parallax/plugins/sprite/shaders/SpriteShader.java @@ -20,12 +20,9 @@ import thothbot.parallax.core.client.shaders.Shader; import thothbot.parallax.core.client.shaders.Uniform; -import thothbot.parallax.core.client.shaders.Shader.DefaultResources; -import thothbot.parallax.core.client.shaders.Uniform.TYPE; import thothbot.parallax.core.shared.math.Color; import thothbot.parallax.core.shared.math.Vector2; import thothbot.parallax.core.shared.math.Vector3; -import thothbot.parallax.core.shared.math.Vector4; import com.google.gwt.core.client.GWT; import com.google.gwt.resources.client.TextResource; From 62eabaa09fb74c8fd660140f3c443b1a25428f26 Mon Sep 17 00:00:00 2001 From: thothbot Date: Sat, 24 Jan 2015 03:11:03 +0300 Subject: [PATCH 04/75] Updated documentation --- .../core/shared/core/AbstractGeometry.java | 9 +- .../parallax/core/shared/core/Geometry.java | 202 +++++++----------- .../core/shared/core/GeometryObject.java | 9 + .../parallax/core/shared/core/Object3D.java | 163 +++++++++++++- .../parallax/core/shared/core/Raycaster.java | 59 +++-- 5 files changed, 281 insertions(+), 161 deletions(-) diff --git a/src/thothbot/parallax/core/shared/core/AbstractGeometry.java b/src/thothbot/parallax/core/shared/core/AbstractGeometry.java index 2ee01273..7e7f6d9e 100644 --- a/src/thothbot/parallax/core/shared/core/AbstractGeometry.java +++ b/src/thothbot/parallax/core/shared/core/AbstractGeometry.java @@ -37,7 +37,6 @@ public abstract class AbstractGeometry extends WebGLGeometry protected Sphere boundingSphere = null; // update flags - public boolean verticesNeedUpdate = false; public boolean elementsNeedUpdate = false; public boolean normalsNeedUpdate = false; @@ -57,10 +56,18 @@ public AbstractGeometry() { this.name = ""; } + /** + * Name for this geometry. Default is an empty string. + * @return Name + */ public String getName() { return this.name; } + /** + * Set name for this geometry. + * @param name + */ public void setName(String name) { this.name = name; } diff --git a/src/thothbot/parallax/core/shared/core/Geometry.java b/src/thothbot/parallax/core/shared/core/Geometry.java index b5b9579f..7d719dca 100644 --- a/src/thothbot/parallax/core/shared/core/Geometry.java +++ b/src/thothbot/parallax/core/shared/core/Geometry.java @@ -41,7 +41,8 @@ import com.google.gwt.core.client.GWT; /** - * Base class for geometries + * Base class for geometries. A geometry holds all data necessary to describe a 3D model. + * *
  * {@code
  * Geometry geometry = new Geometry();
@@ -101,41 +102,24 @@ public class MorphTarget
 	private List skinWeights;
 	private List skinIndices;
 
+	/*
+	 * An array containing distances between vertices for Line geometries. 
+	 * This is required for LinePieces/LineDashedMaterial to render correctly.
+	 * Line distances can also be generated with computeLineDistances.
+	 */
 	private List lineDistances;
 	
+	/*
+	 * True if geometry has tangents. Set in Geometry.computeTangents.
+	 */
 	public boolean hasTangents = false;
 
-	public boolean dynamic = true; // the intermediate typed arrays will be deleted when set to false
-	
-//	//
-//	
-//	// one-to-one vertex normals, used in Ribbon
-//	private List normals;
-//
-//	
-//	private List> faceUvs;	
-//
-//
-//	private boolean isLineDistancesNeedUpdate;
-	
-	// Array of materials.
-//	public List materials;
-//	
-//	private List skinVerticesA;
-//	private List skinVerticesB;
-//
+	/*
+	 * The intermediate typed arrays will be deleted when set to false
+	 */
+	private boolean dynamic = true; 
+
 	private List bones;
-//
-//	public List> sortArray;
-//	
-//	private boolean isMorphTargetsNeedUpdate;
-//	
-//	private List geometryGroups;
-//	private Map geometryGroupsCache;
-//		
-//	private Object3D debug;
-//	
-//	private ArrayList __tmpVertices;
 	
 	public Geometry() 
 	{
@@ -157,35 +141,22 @@ public Geometry()
 		this.skinIndices = new ArrayList();
 		
 		this.lineDistances = new ArrayList();
-		//
+	}
+	
+	/**
+	 * Set to true if attribute buffers will need to change in runtime (using "dirty" flags).
+	 * Unless set to true internal typed arrays corresponding to buffers will be deleted once sent to GPU.
+	 * Defaults to true.
+	 * @return
+	 */
+	public boolean isDynamic() {
+		return dynamic;
+	}
 
-//		this.faceUvs = new ArrayList>();
-//
-//
-//
-//		this.debug = new Object3D();
+	public void setDynamic(boolean dynamic) {
+		this.dynamic = dynamic;
 	}
-		
-//	public Map getGeometryGroupsCache() {
-//		return this.geometryGroupsCache;
-//	}
-//	
-//	public void setGeometryGroupsCache(Map geometryGroups) {
-//		this.geometryGroupsCache = geometryGroups;
-//	}
-//	
-//	public List getGeometryGroups() {
-//		return this.geometryGroups;
-//	}
-//	
-//	public void setGeometryGroups(List geometryGroupsList) {
-//		this.geometryGroups = geometryGroupsList;
-//	}
-//	
-//	public Object3D getDebug() {
-//		return this.debug;
-//	}
-//	
+
 	/**
 	 * Gets the List of skinning weights, matching number and order of vertices.
 	 */
@@ -200,44 +171,6 @@ public List getSkinIndices() {
 		return this.skinIndices;
 	}
 	
-	
-	
-//	public List getSkinVerticesA() {
-//		return this.skinVerticesA;
-//	}
-//	
-//	public void setSkinVerticesA(List skinVerticesA) {
-//		this.skinVerticesA = skinVerticesA;
-//	}
-//	
-//	public List getSkinVerticesB() {
-//		return this.skinVerticesB;
-//	}
-//	
-//	public void setSkinVerticesB(List  skinVerticesB) {
-//		this.skinVerticesB = skinVerticesB;
-//	}
-//
-//	public boolean isMorphTargetsNeedUpdate() {
-//		return isMorphTargetsNeedUpdate;
-//	}
-//
-//	public void setMorphTargetsNeedUpdate(boolean isMorphTargetsNeedUpdate) {
-//		this.isMorphTargetsNeedUpdate = isMorphTargetsNeedUpdate;
-//	}
-//
-//	public void setFaceUvs(List> faceUvs) {
-//		this.faceUvs = faceUvs;
-//	}
-
-//	/**
-//	 * Gets the List of face {@link UV} layers.
-//	 * Each UV layer is an List of {@link UV} matching order and number of faces.
-//	 */
-//	public List> getFaceUvs() {
-//		return faceUvs;
-//	}
-
 	public List getLineDistances() {
 		return lineDistances;
 	}
@@ -249,8 +182,9 @@ public void setColors(List colors) {
 	/**
 	 * Gets List of vertex {@link Color}s, matching number and order of vertices.
 	 * 

- * Used in {@link ParticleSystem}, {@link Line} and {@link Ribbon}.
+ * Used in {@link PointCloud}, {@link Line}.
* {@link Mesh}es use per-face-use-of-vertex colors embedded directly in faces. + * To signal an update in this array, Geometry.colorsNeedUpdate needs to be set to true. */ public List getColors() { return colors; @@ -261,32 +195,21 @@ public void setFaces(List faces) { } /** - * Gets the List of triangles: {@link Face3} or/and quads: {@link Face4} + * Gets the List of triangles: {@link Face3}. The array of faces describe how each vertex in the model is connected with each other. + * To signal an update in this array, Geometry.elementsNeedUpdate needs to be set to true. */ public List getFaces() { return faces; } -// /** -// * Gets the List of {@link Material}s. -// */ -// public List getMaterials() -// { -// return this.materials; -// } -// -// public void setMaterials(List materials) -// { -// this.materials = materials; -// } - public void setVertices(List vertices) { this.vertices = vertices; } /** - * Gets List of {@link Vector3}. + * Gets List of {@link Vector3}. The array of vertices holds every position of points in the model. + * To signal an update in this array, Geometry.verticesNeedUpdate needs to be set to true. */ public List getVertices() { @@ -301,6 +224,11 @@ public List getMorphTargets() { return morphTargets; } + /** + * Get the List of {@link Geometry.MorphNormal}. + * Morph normals have similar structure as morph targets + * @return + */ public List getMorphNormals() { return morphNormals; } @@ -315,7 +243,8 @@ public List getMorphColors() { /** * Gets the List of face {@link UV} layers. - * Each UV layer is an List of UV matching order and number of vertices in faces. + * Each UV layer is an array of UVs matching the order and number of vertices in faces. + * To signal an update in this array, Geometry.uvsNeedUpdate needs to be set to true. */ public List>> getFaceVertexUvs(){ return this.faceVertexUvs; @@ -334,7 +263,7 @@ public void setBones(List bones) { } /** - * Makes matrix transform directly into vertex coordinates. + * Bakes matrix transform directly into vertex coordinates. */ public void applyMatrix(Matrix4 matrix) { @@ -365,9 +294,8 @@ public void applyMatrix(Matrix4 matrix) this.computeBoundingSphere(); } - public Geometry fromBufferGeometry( BufferGeometry geometry ) { - - Map attributes = geometry.getAttributes(); + public Geometry fromBufferGeometry( BufferGeometry geometry ) + { Float32Array vertices = (Float32Array)geometry.getAttribute("position").getArray(); Uint16Array indices = geometry.getAttribute("index") != null @@ -450,7 +378,8 @@ private void addFace(Float32Array normals, Float32Array colors, List te } - public Vector3 center() { + public Vector3 center() + { this.computeBoundingBox(); @@ -466,6 +395,9 @@ public Vector3 center() { } + /** + * Computes face normals. + */ public void computeFaceNormals() { Vector3 cb = new Vector3(), ab = new Vector3(); @@ -515,9 +447,8 @@ public void computeVertexNormals(boolean areaWeighted) // vertex normals weighted by triangle areas // http://www.iquilezles.org/www/articles/normals/normals.htm - Vector3 vA, vB, vC, vD; - Vector3 cb = new Vector3(), ab = new Vector3(), - db = new Vector3(), dc = new Vector3(), bc = new Vector3(); + Vector3 vA, vB, vC; + Vector3 cb = new Vector3(), ab = new Vector3(); for ( int f = 0, fl = this.faces.size(); f < fl; f ++ ) { @@ -574,7 +505,11 @@ public void computeVertexNormals(boolean areaWeighted) } } - public void computeMorphNormals() { + /** + * Computes morph normals. + */ + public void computeMorphNormals() + { Face3 face; @@ -754,6 +689,9 @@ public void computeTangents() this.hasTangents = true; } + /** + * Compute distances between vertices for Line geometries. + */ public void computeLineDistances( ) { double d = 0; @@ -768,7 +706,6 @@ public void computeLineDistances( ) this.lineDistances.add( i, d ); } } - /** * Computes bounding box of the geometry. @@ -803,13 +740,22 @@ public void computeBoundingSphere() } - public void merge( Geometry geometry, Matrix4 matrix ) { + public void merge( Geometry geometry, Matrix4 matrix ) + { merge(geometry, matrix, 0); } - public void merge( Geometry geometry, Matrix4 matrix, int materialIndexOffset ) { + /** + * Merge two geometries or geometry and geometry from object (using object's transform) + * + * @param geometry + * @param matrix + * @param materialIndexOffset + */ + public void merge( Geometry geometry, Matrix4 matrix, int materialIndexOffset ) + { Matrix3 normalMatrix = null; @@ -962,15 +908,12 @@ public int mergeVertices() int[] indices = { face.getA(), face.getB(), face.getC() }; - int dupIndex = -1; - // if any duplicate vertices are found in a Face3 // we have to remove the face as nothing can be saved for ( int n = 0; n < 3; n ++ ) { if ( indices[ n ] == indices[ ( n + 1 ) % 3 ] ) { - dupIndex = n; faceIndicesToRemove.add( i ); break; } @@ -994,6 +937,9 @@ public int mergeVertices() return diff; } + /** + * Creates a new clone of the Geometry. + */ public Geometry clone() { Geometry geometry = new Geometry(); diff --git a/src/thothbot/parallax/core/shared/core/GeometryObject.java b/src/thothbot/parallax/core/shared/core/GeometryObject.java index 762eb664..f1f21bc9 100644 --- a/src/thothbot/parallax/core/shared/core/GeometryObject.java +++ b/src/thothbot/parallax/core/shared/core/GeometryObject.java @@ -28,6 +28,9 @@ import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.shaders.Attribute; import thothbot.parallax.core.shared.materials.Material; +import thothbot.parallax.core.shared.objects.Line; +import thothbot.parallax.core.shared.objects.Mesh; +import thothbot.parallax.core.shared.objects.PointCloud; public abstract class GeometryObject extends Object3D { @@ -68,6 +71,12 @@ public void setMaterial(Material material) this.material = material; } + /** + * Abstract method to get intersections between a casted ray and this object. + * Subclasses such as {@link Mesh}, {@link Line}, and {@link PointCloud} implement this method in order to participate in raycasting. + * @param raycaster + * @param intersects + */ public abstract void raycast( Raycaster raycaster, List intersects); // public Material getCustomDepthMaterial() { diff --git a/src/thothbot/parallax/core/shared/core/Object3D.java b/src/thothbot/parallax/core/shared/core/Object3D.java index 235b0a58..29a5b3cb 100644 --- a/src/thothbot/parallax/core/shared/core/Object3D.java +++ b/src/thothbot/parallax/core/shared/core/Object3D.java @@ -32,7 +32,7 @@ import thothbot.parallax.core.shared.math.Vector3; /** - * Implementation of DimensionalObject + * Base class for scene objects. * * @author thothbot * @@ -163,10 +163,20 @@ private void onRemove() { this.handler.onRemove(Object3D.this); } + /** + * Unique number for this object instance. + * + * @return + */ public int getId() { return this.id; } + /** + * Object's parent in the scene graph. + * + * @return + */ public Object3D getParent() { return this.parent; } @@ -175,6 +185,10 @@ public void setParent(Object3D parent) { this.parent = parent; } + /** + * Array with object's children. + * @return + */ public List getChildren() { return this.children; } @@ -205,6 +219,10 @@ public List getChildrenByClass(Class clazz, boolean recur return retval; } + /** + * Object's local position. + * @return + */ public Vector3 getPosition() { return this.position; } @@ -213,6 +231,10 @@ public void setPosition(Vector3 position) { this.position = position; } + /** + * Object's local rotation ({@link Euler} angles), in radians. + * @return + */ public Euler getRotation() { return this.rotation; } @@ -223,7 +245,6 @@ public void setRotation(Euler rotation) { /** * If set to true light will cast dynamic shadows. - * Warning: This is expensive and requires tweaking to get shadows looking right. *

* Default � false. */ @@ -235,6 +256,10 @@ public void setCastShadow(boolean isCastShadow) { this.isCastShadow = isCastShadow; } + /** + * Material gets baked in shadow receiving. default – false + * @return + */ public boolean isReceiveShadow() { return isReceiveShadow; } @@ -243,6 +268,11 @@ public void setReceiveShadow(boolean isReceiveShadow) { this.isReceiveShadow = isReceiveShadow; } + /** + * When this is set, it checks every frame if the object is in the frustum of the camera. + * Otherwise the object gets drawn every frame even if it isn't visible. default – true + * @return + */ public boolean isFrustumCulled() { return isFrustumCulled; } @@ -256,6 +286,10 @@ public void setRotationAutoUpdate(boolean rotationAutoUpdate) { } + /** + * When this is set, then the rotationMatrix gets calculated every frame. default – true + * @return + */ public boolean isRotationAutoUpdate() { return rotationAutoUpdate; } @@ -264,10 +298,19 @@ public void setName(String name) { this.name = name; } + /** + * Optional name of the object (doesn't need to be unique). + * + * @return + */ public String getName() { return name; } + /** + * Object's local scale. + * @return + */ public Vector3 getScale() { return this.scale; } @@ -276,6 +319,10 @@ public void setScale(Vector3 scale) { this.scale = scale; } + /** + * Up direction. + * @return + */ public Vector3 getUp() { return this.up; } @@ -284,14 +331,22 @@ public void setUp(Vector3 up) { this.up = up; } + /** + * Local transform. + * @return + */ public Matrix4 getMatrix() { return this.matrix; } public void setMatrix(Matrix4 matrix) { this.matrix = matrix; - }; + } + /** + * The global transform of the object. If the Object3d has no parent, then it's identical to the local transform. + * @return + */ public Matrix4 getMatrixWorld() { return this.matrixWorld; } @@ -300,6 +355,10 @@ public void setMatrixWorld(Matrix4 matrixWorld) { this.matrixWorld = matrixWorld; } + /** + * When this is set, it calculates the matrixWorld in that frame and resets this property to false. default – false + * @return + */ public boolean isMatrixWorldNeedsUpdate() { return this.matrixWorldNeedsUpdate; } @@ -308,6 +367,11 @@ public void setMatrixWorldNeedsUpdate(boolean needsUpdate) { this.matrixWorldNeedsUpdate = needsUpdate; } + /** + * When this is set, it calculates the matrix of position, (rotation or quaternion) and scale every + * frame and also recalculates the matrixWorld property. default – true + * @return + */ public boolean isMatrixAutoUpdate() { return this.matrixAutoUpdate; } @@ -316,6 +380,10 @@ public void setMatrixAutoUpdate(boolean autoUpdate) { this.matrixAutoUpdate = autoUpdate; } + /** + * Object's local rotation as {@link Quaternion}. + * @return + */ public Quaternion getQuaternion() { return this.quaternion; } @@ -324,6 +392,10 @@ public void setQuaternion(Quaternion quaternion) { this.quaternion = quaternion; } + /** + * Object gets rendered if true. default – true + * @return + */ public boolean isVisible() { return this.visible; } @@ -332,6 +404,10 @@ public void setVisible(boolean visible) { this.visible = visible; } + /** + * This updates the position, rotation and scale with the matrix. + * @param matrix + */ public void applyMatrix(Matrix4 matrix) { this.matrix.multiply( matrix, this.matrix ); @@ -369,11 +445,14 @@ public void setRotationFromQuaternion ( Quaternion q ) { } + /** + * Rotate an object along an axis in object space. The axis is assumed to be normalized. + * @param axis A normalized vector in object space. + * @param angle The angle in radians. + * @return + */ public Object3D rotateOnAxis(Vector3 axis, double angle) { - // rotate object on axis in object space - // axis is assumed to be normalized - Quaternion q1 = new Quaternion(); q1.setFromAxisAngle( axis, angle ); @@ -408,11 +487,14 @@ public Object3D rotateZ(double angle) { } + /** + * Translate an object by distance along an axis in object space. The axis is assumed to be normalized. + * @param axis A normalized vector in object space. + * @param distance The distance to translate. + * @return + */ public Object3D translateOnAxis ( Vector3 axis, double distance ) { - // translate object by distance along axis in object space - // axis is assumed to be normalized - Vector3 v1 = new Vector3(); @@ -423,6 +505,11 @@ public Object3D translateOnAxis ( Vector3 axis, double distance ) { return this; } + /** + * Translates object along x axis by distance. + * @param distance + * @return + */ public Object3D translateX(double distance) { Vector3 v1 = new Vector3( 1.0, 0, 0 ); @@ -431,6 +518,11 @@ public Object3D translateX(double distance) { } + /** + * Translates object along y axis by distance. + * @param distance + * @return + */ public Object3D translateY(double distance) { Vector3 v1 = new Vector3( 0, 1.0, 0 ); @@ -439,6 +531,11 @@ public Object3D translateY(double distance) { } + /** + * Translates object along z axis by distance. + * @param distance + * @return + */ public Object3D translateZ(double distance) { Vector3 v1 = new Vector3( 0, 0, 1.0 ); @@ -452,6 +549,11 @@ public Vector3 localToWorld( Vector3 vector ) return vector.apply( this.matrixWorld ); } + /** + * Updates the vector from world space to local space. + * @param vector A world vector. + * @return + */ public Vector3 worldToLocal( Vector3 vector ) { Matrix4 m1 = new Matrix4(); @@ -459,6 +561,10 @@ public Vector3 worldToLocal( Vector3 vector ) return vector.apply( m1.getInverse( this.matrixWorld ) ); } + /** + * Rotates object to face point in space. + * @param vector A world vector to look at. + */ public void lookAt(Vector3 vector) { // This routine does not support objects with rotated and/or translated parent(s) @@ -479,6 +585,11 @@ public Object3D add(List objects) { return this; } + /** + * Adds object as child of this object. + * @param object An object + * @return + */ public Object3D add(Object3D object) { if(object.equals(this)) { @@ -510,6 +621,10 @@ public void remove(List objects) { this.remove(objects.get(i)); } + /** + * Removes object as child of this object. + * @param object An object. + */ public void remove(Object3D object) { int index = this.children.indexOf(object); @@ -524,6 +639,12 @@ public void remove(Object3D object) } } + /** + * 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. + * @return + */ public Object3D getObjectById(int id, boolean recursive ) { if ( this.id == id ) return this; @@ -544,6 +665,12 @@ public Object3D getObjectById(int id, boolean recursive ) { return null; } + /** + * 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. + * @return + */ public Object3D getObjectByName( String name, boolean recursive ) { if ( this.name.equals( name ) ) return this; @@ -636,6 +763,10 @@ public Vector3 getWorldDirection(Vector3 optionalTarget) { } + /** + * Executes the callback on this object and all descendants + * @param traverse A {@link Traverse} interface with as first argument an object3D object. + */ public void traverse ( Traverse traverse ) { traverse.callback(this); @@ -647,6 +778,10 @@ public void traverse ( Traverse traverse ) { } } + /** + * Like {@link Object3D#traverse(Traverse)}, but the {@link Traverse} will only be executed for visible objects. Descendants of invisible objects are not traversed. + * @param traverse A {@link Traverse} interface with as first argument an object3D object. + */ public void traverseVisible ( Traverse traverse ) { if ( this.visible == false ) return; @@ -661,6 +796,9 @@ public void traverseVisible ( Traverse traverse ) { } + /** + * Updates local transform. + */ public void updateMatrix() { @@ -670,6 +808,10 @@ public void updateMatrix() } + /** + * Updates global transform of the object and its children. + * @param force + */ public void updateMatrixWorld(boolean force) { if ( this.matrixAutoUpdate == true ) this.updateMatrix(); @@ -702,6 +844,9 @@ public void updateMatrixWorld(boolean force) } + /** + * Creates a new clone of this object and all descendants. + */ public Object3D clone() { return clone(new Object3D()); } diff --git a/src/thothbot/parallax/core/shared/core/Raycaster.java b/src/thothbot/parallax/core/shared/core/Raycaster.java index 55526872..68292714 100644 --- a/src/thothbot/parallax/core/shared/core/Raycaster.java +++ b/src/thothbot/parallax/core/shared/core/Raycaster.java @@ -24,10 +24,22 @@ import thothbot.parallax.core.shared.math.Ray; import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.objects.Line; +import thothbot.parallax.core.shared.objects.Mesh; +/** + * This class makes raycasting easier. Raycasting is used for picking and more. + * + */ public class Raycaster { + /** + * The precision factor of the raycaster when intersecting {@link Mesh} objects. + */ public static final double precision = 0.0001; + /** + * The precision factor of the raycaster when intersecting {@link Line} objects. + */ public static final double linePrecision = 1; public static class Intersect implements Comparable @@ -44,7 +56,6 @@ public static class Intersect implements Comparable public int compareTo(Object arg0) { Intersect b = (Intersect)arg0; -// return this.distance - b.distance; return (this.distance == b.distance) ? 0 : this.distance < b.distance ? -1 : 1; } @@ -53,13 +64,7 @@ public int compareTo(Object arg0) private Ray ray; private double near; private double far; - -// private Sphere sphere = new Sphere(); -// private Ray localRay = new Ray(); -// private Plane facePlane = new Plane(); -// private Vector3 intersectPoint = new Vector3(); -// private Matrix4 inverseMatrix = new Matrix4(); - + public Raycaster() { this(new Vector3(), new Vector3()); @@ -70,29 +75,25 @@ public Raycaster( Vector3 origin, Vector3 direction) this(origin, direction, 0, Double.POSITIVE_INFINITY); } + /** + * This creates a new raycaster object. + * @param origin The origin vector where the ray casts from. + * @param direction The direction vector that gives direction to the ray. + * @param near All results returned are further away than near. Near can't be negative. Default value is 0. + * @param far All results returned are closer then far. Far can't be lower then near . Default value is Infinity. + */ public Raycaster( Vector3 origin, Vector3 direction, double near, double far ) { this.ray = new Ray( origin, direction ); - -// // normalized ray.direction required for accurate distance calculations -// if( this.ray.getDirection().length() > 0 ) -// { -// this.ray.getDirection().normalize(); -// } - this.near = near; this.far = far; } - - - -// var descSort = function ( a, b ) { -// -// return a.distance - b.distance; -// -// }; + /** + * The Ray used for the raycasting. + * @return + */ public Ray getRay() { return ray; } @@ -101,6 +102,12 @@ public void setRay(Ray ray) { this.ray = ray; } + /** + * The near factor of the raycaster. + * This value indicates which objects can be discarded based on the distance. + * This value shouldn't be negative and should be smaller than the far property. + * @return + */ public double getNear() { return near; } @@ -109,6 +116,12 @@ public void setNear(double near) { this.near = near; } + /** + * The far factor of the raycaster. + * This value indicates which objects can be discarded based on the distance. + * This value shouldn't be negative and should be larger than the near property. + * @return + */ public double getFar() { return far; } From 334ba4bfbb8d0e43bcacf351f0728a92fd39fe60 Mon Sep 17 00:00:00 2001 From: thothbot Date: Sat, 24 Jan 2015 12:40:07 +0300 Subject: [PATCH 05/75] Updated documentation --- .../core/shared/core/BufferGeometry.java | 100 ++++++++++++++++-- .../parallax/core/shared/core/Raycaster.java | 57 +++++++--- 2 files changed, 135 insertions(+), 22 deletions(-) diff --git a/src/thothbot/parallax/core/shared/core/BufferGeometry.java b/src/thothbot/parallax/core/shared/core/BufferGeometry.java index d9900254..f789801b 100644 --- a/src/thothbot/parallax/core/shared/core/BufferGeometry.java +++ b/src/thothbot/parallax/core/shared/core/BufferGeometry.java @@ -43,6 +43,33 @@ import com.google.gwt.core.client.GWT; +/** + * This class is an efficient alternative to {@link Geometry}, because it stores all data, including vertex positions, + * face indices, normals, colors, UVs, and custom attributes within buffers; this reduces the cost of passing + * all this data to the GPU. This also makes BufferGeometry harder to work with than {@link Geometry}; rather than + * accessing position data as {@link Vector3} objects, color data as {@link Color} objects, and so on, you have to access + * the raw data from the appropriate attribute buffer {@link BufferAttribute}. + * + *

+ * BufferGeometry geometry = new BufferGeometry();
+ *
+ * int chunkSize = 20000;
+ *
+ * // three components per vertex
+ * int triangles = 160000;
+ * Uint16Array indices = Uint16Array.create( triangles * 3 );
+ *
+ * for ( int i = 0; i < indices.getLength(); i ++ ) 
+ * {
+ *		indices.set( i, i % ( 3 * chunkSize ));
+ * }
+ *
+ * Float32Array positions = Float32Array.create( triangles * 3 * 3 );
+ *
+ * //itemSize = 3 because there are 3 values (components) per vertex
+ * geometry.addAttribute( "position", new BufferAttribute( positions, 3 ) );
+ *
+ */ public class BufferGeometry extends AbstractGeometry { public static class DrawCall @@ -82,6 +109,29 @@ public Map getAttributes() { return this.attributes; } + /** + * WebGL stores data associated with individual vertices of a geometry in attributes. + * Examples include the position of the vertex, the normal vector for the vertex, the vertex color, and so on. + * When using {@link Geometry}, the renderer takes care of wrapping up this information into typed array buffers and sending this + * data to the shader. With BufferGeometry, all of this data is stored in buffers associated with an individual attributes. + * This means that to get the position data associated with a vertex (for instance), you must call .getAttribute() to access + * the "position" attribute, then access the individual x, y, and z coordinates of the position. + *

+ * The following attributes are set by various members of this class: + * + *

    + *
  • position - Stores the x, y, and z coordinates of each vertex in this geometry. Set by .fromGeometry().
  • + *
  • normal - Stores the x, y, and z components of the face or vertex normal vector of each vertex in this geometry. Set by .fromGeometry().
  • + *
  • color - Stores the red, green, and blue channels of vertex color of each vertex in this geometry. Set by .fromGeometry().
  • + *
  • tangent - Stores the x, y, and z components of the tangent vector of each vertex in this geometry. Set by .computeTangents().
  • + *
  • index - Allows for vertices to be re-used across multiple triangles; this is called using "indexed triangles," + * and works much the same as it does in Geometry: each triangle is associated with the index of three vertices. + * This attribute therefore stores the index of each vertex for each triangular face. If this attribute is not set, the renderer + * assumes that each three contiguous positions represent a single triangle.
  • + *
+ * @param name Attribute name + * @param attribute + */ public void addAttribute( String name, BufferAttribute attribute ) { this.attributes.put( name, attribute ); @@ -95,6 +145,12 @@ public BufferAttribute getAttribute( String name ) { } + /** + * For geometries that use indexed triangles, this Array can be used to split the object into multiple WebGL draw calls. + * Each draw call will draw some subset of the vertices in this geometry using the configured shader. + * This may be necessary if, for instance, you have more than 65535 vertices in your object. + * @return + */ public List getOffsets() { return offsets; } @@ -109,6 +165,10 @@ public void addDrawCall( int start, int count, int indexOffset ) { this.drawcalls.add(drawCall); } + /** + * Bakes matrix transform directly into vertex coordinates. + * @param matrix + */ public void applyMatrix( Matrix4 matrix ) { BufferAttribute position = getAttribute("position"); @@ -133,6 +193,11 @@ public void applyMatrix( Matrix4 matrix ) { } + /** + * Populates this BufferGeometry with data from a {@link Geometry} object. + * @param geometry + * @return + */ public BufferGeometry fromGeometry( Geometry geometry) { return fromGeometry(geometry, Material.COLORS.NO); @@ -283,6 +348,10 @@ public BufferGeometry fromGeometry( Geometry geometry, Material.COLORS vertexCol } + /** + * 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. + */ @Override public void computeBoundingBox() { @@ -319,6 +388,10 @@ public void computeBoundingBox() { } + /** + * Computes bounding sphere of the geometry, updating Geometry.boundingSphere attribute. + * Bounding spheres aren't computed by default. They need to be explicitly computed, otherwise they are null. + */ public void computeBoundingSphere() { Box3 box = new Box3(); @@ -365,6 +438,9 @@ public void computeBoundingSphere() { } + /** + * Computes vertex normals by averaging face normals. + */ public void computeVertexNormals() { BufferAttribute positionAttribute = getAttribute("position"); @@ -488,6 +564,11 @@ public void computeVertexNormals() { } + /** + * Computes vertex tangents. + * Based on http://www.terathon.com/code/tangent.html + * Geometry must have vertex UVs (layer 0 will be used). + */ public void computeTangents() { // based on http://www.terathon.com/code/tangent.html @@ -575,18 +656,18 @@ public void computeTangents() { } - /** - computeOffsets - Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices. - This method will effectively rewrite the index buffer and remap all attributes to match the new indices. - WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets. - indexBufferSize - Defaults to 65535, but allows for larger or smaller chunks. - */ public List computeOffsets() { //WebGL limits type of index buffer values to 16-bit. return computeOffsets(65535); } - + + /** + * Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices. + * This method will effectively rewrite the index buffer and remap all attributes to match the new indices. + * WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets + * @param size Defaults to 65535, but allows for larger or smaller chunks. + * @return + */ public List computeOffsets( int size /* indexBufferSize */ ) { // var s = Date.now(); @@ -684,6 +765,9 @@ public List computeOffsets( int size /* indexBufferSize return offsets; } + /** + * Every normal vector in a geometry will have a magnitude of 1. This will correct lighting on the geometry surfaces. + */ public void normalizeNormals() { Float32Array normals = (Float32Array)getAttribute("normal").getArray(); diff --git a/src/thothbot/parallax/core/shared/core/Raycaster.java b/src/thothbot/parallax/core/shared/core/Raycaster.java index 68292714..811e37d0 100644 --- a/src/thothbot/parallax/core/shared/core/Raycaster.java +++ b/src/thothbot/parallax/core/shared/core/Raycaster.java @@ -44,12 +44,26 @@ public class Raycaster public static class Intersect implements Comparable { - // this works because the original ray was normalized, and the transformed localRay wasn't + /** + * distance between the origin of the ray and the intersection + */ public double distance; + /** + * point of intersection, in world coordinates + */ public Vector3 point; public double distanceToRay; + /** + * intersected face + */ public Face3 face; + /** + * index of the intersected face + */ public int faceIndex; + /** + * the intersected object + */ public GeometryObject object; @Override @@ -137,18 +151,6 @@ public void set( Vector3 origin, Vector3 direction ) { } - public List intersectObject( GeometryObject object, boolean recursive ) { - - List intersects = new ArrayList(); - - intersectObject( object, this, intersects, recursive ); - - Collections.sort(intersects); - - return intersects; - - } - public List intersectObjects ( List objects ) { List intersects = new ArrayList(); @@ -165,7 +167,15 @@ public List intersectObjects ( List objects ) { return intersects; } - + + /** + * Checks all intersection between the ray and the objects with or without the descendants. + * Intersections are returned sorted by distance, closest first. Intersections are of the same form as + * those returned by {@link Raycaster#intersectObject(GeometryObject, boolean)} + * @param objects The objects to check for intersection with the ray. + * @param recursive If set, it also checks all descendants of the objects. Otherwise it only checks intersecton with the objects. + * @return + */ public List intersectObjects ( List objects, boolean recursive ) { List intersects = new ArrayList(); @@ -181,7 +191,26 @@ public List intersectObjects ( List objects return intersects; } + + + /** + * Checks all intersection between the ray and the object with or without the descendants. Intersections are returned sorted by distance, + * closest first. An array of intersections is returned... + * @param object The object to check for intersection with the ray. + * @param recursive If set, it also checks all descendants. Otherwise it only checks intersecton with the object. + * @return + */ + public List intersectObject( GeometryObject object, boolean recursive ) { + + List intersects = new ArrayList(); + + intersectObject( object, this, intersects, recursive ); + + Collections.sort(intersects); + + return intersects; + } private void intersectObject ( GeometryObject object, Raycaster raycaster, List intersects, boolean recursive ) { From 0047917354ed588c64234aca3f7893f758dcafbc Mon Sep 17 00:00:00 2001 From: thothbot Date: Sat, 24 Jan 2015 16:08:43 +0300 Subject: [PATCH 06/75] Updated documentation --- .../parallax/core/shared/cameras/Camera.java | 15 +++++++++++++++ .../parallax/core/shared/cameras/CubeCamera.java | 15 +++++++++++++++ .../parallax/core/shared/materials/HasFog.java | 4 ++++ .../core/shared/materials/HasVertexColors.java | 9 +++++++++ .../core/shared/materials/LineBasicMaterial.java | 13 +++++++++++++ .../shared/materials/LineDashedMaterial.java | 16 ++++++++++++++++ .../core/shared/materials/MeshDepthMaterial.java | 4 ++++ .../core/shared/materials/MeshFaceMaterial.java | 15 +++++++++++++++ .../shared/materials/MeshLambertMaterial.java | 4 ++++ .../shared/materials/MeshNormalMaterial.java | 4 ++++ .../core/shared/materials/MeshPhongMaterial.java | 4 ++++ .../parallax/core/shared/objects/Bone.java | 12 ++++++++++-- .../parallax/core/shared/objects/Line.java | 7 +++++++ 13 files changed, 120 insertions(+), 2 deletions(-) diff --git a/src/thothbot/parallax/core/shared/cameras/Camera.java b/src/thothbot/parallax/core/shared/cameras/Camera.java index a1ffd0cb..f019a4c7 100644 --- a/src/thothbot/parallax/core/shared/cameras/Camera.java +++ b/src/thothbot/parallax/core/shared/cameras/Camera.java @@ -39,6 +39,9 @@ public class Camera extends Object3D implements HasEventBus, ViewportResizeHandl protected Matrix4 matrixWorldInverse; protected Matrix4 projectionMatrix; + /** + * This constructor sets the following properties to the correct type: matrixWorldInverse and projectionMatrix. + */ public Camera() { super(); @@ -59,6 +62,10 @@ public void onResize(ViewportResizeEvent event) { // Empty for capability } + /** + * This is the inverse of matrixWorld. MatrixWorld contains the Matrix which has the world transform of the Camera. + * @return + */ public Matrix4 getMatrixWorldInverse() { return this.matrixWorldInverse; @@ -69,6 +76,10 @@ public void setMatrixWorldInverse(Matrix4 matrixWorldInverse) this.matrixWorldInverse = matrixWorldInverse; } + /** + * This is the matrix which contains the projection. + * @return + */ public Matrix4 getProjectionMatrix() { return this.projectionMatrix; @@ -95,6 +106,10 @@ public Vector3 getWorldDirection(Vector3 optionalTarget) { } + /** + * This makes the camera look at the vector position in the global space as long as the parent + * of this camera is the scene or at position (0,0,0). + */ @Override public void lookAt(Vector3 vector) { diff --git a/src/thothbot/parallax/core/shared/cameras/CubeCamera.java b/src/thothbot/parallax/core/shared/cameras/CubeCamera.java index 9c6e34b8..c800224c 100644 --- a/src/thothbot/parallax/core/shared/cameras/CubeCamera.java +++ b/src/thothbot/parallax/core/shared/cameras/CubeCamera.java @@ -52,6 +52,12 @@ public final class CubeCamera extends Object3D private RenderTargetCubeTexture renderTarget; + /** + * Constructs a CubeCamera that contains 6 {@link PerspectiveCamera}s that then render to a {@link RenderTargetCubeTexture} + * @param near The near clipping distance. + * @param far The far clipping distance + * @param cubeResolution Sets the width of the cube. + */ public CubeCamera(double near, double far, int cubeResolution) { this.cameraPX = new PerspectiveCamera( fov, aspect, near, far ); @@ -90,11 +96,20 @@ public CubeCamera(double near, double far, int cubeResolution) this.renderTarget.setMinFilter(TextureMinFilter.LINEAR); } + /** + * The cube texture that gets generated. + * @return + */ public RenderTargetCubeTexture getRenderTarget() { return this.renderTarget; } + /** + * Call this to update the renderTarget. + * @param renderer The current WebGL renderer + * @param scene The current scene + */ public void updateCubeMap( WebGLRenderer renderer, Scene scene ) { RenderTargetCubeTexture renderTarget = this.renderTarget; diff --git a/src/thothbot/parallax/core/shared/materials/HasFog.java b/src/thothbot/parallax/core/shared/materials/HasFog.java index 5f2a462f..becf9ab5 100644 --- a/src/thothbot/parallax/core/shared/materials/HasFog.java +++ b/src/thothbot/parallax/core/shared/materials/HasFog.java @@ -26,6 +26,10 @@ */ public interface HasFog { + /** + * Define whether the material color is affected by global fog settings. Default is false. + * @return + */ public boolean isFog(); public void setFog(boolean fog); } diff --git a/src/thothbot/parallax/core/shared/materials/HasVertexColors.java b/src/thothbot/parallax/core/shared/materials/HasVertexColors.java index c8d92823..3166df2d 100644 --- a/src/thothbot/parallax/core/shared/materials/HasVertexColors.java +++ b/src/thothbot/parallax/core/shared/materials/HasVertexColors.java @@ -26,6 +26,15 @@ */ public interface HasVertexColors { + /** + * Get how the vertices gets colored. Default is {@link Material.COLORS} NO. + * @return + */ public Material.COLORS isVertexColors(); + + /** + * Define how the vertices gets colored. Possible values in {@link Material.COLORS}. Default is {@link Material.COLORS} NO. + * @param vertexColors + */ public void setVertexColors(Material.COLORS vertexColors); } diff --git a/src/thothbot/parallax/core/shared/materials/LineBasicMaterial.java b/src/thothbot/parallax/core/shared/materials/LineBasicMaterial.java index 49e086ca..17ad2a35 100644 --- a/src/thothbot/parallax/core/shared/materials/LineBasicMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/LineBasicMaterial.java @@ -61,10 +61,20 @@ public Shader getAssociatedShader() return new BasicShader(); } + /** + * Line thickness. Default is 1. + * @return + */ public double getLinewidth() { return this.linewidth; } + /** + * Controls line thickness. Default is 1. + *

+ * Due to limitations in the ANGLE layer, on Windows platforms linewidth will always be 1 regardless of the set value. + * @param linewidth + */ public void setLinewidth(double linewidth) { this.linewidth = linewidth; } @@ -79,6 +89,9 @@ public void setFog(boolean fog) { this.isFog = fog; } + /** + * Line color in hexadecimal. Default is 0xffffff. + */ @Override public Color getColor() { return color; diff --git a/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java b/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java index 121b2436..63b80d47 100644 --- a/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java @@ -26,6 +26,10 @@ import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.math.Color; +/** + * A material for drawing wireframe-style geometries with dashed lines. + * + */ public class LineDashedMaterial extends Material implements HasFog, HasColor, HasVertexColors { @@ -71,6 +75,10 @@ public void setScale(double scale) { this.scale = scale; } + /** + * The size of the dash. This is both the gap with the stroke. Default is 3. + * @return + */ public double getDashSize() { return dashSize; } @@ -79,6 +87,10 @@ public void setDashSize(double dashSize) { this.dashSize = dashSize; } + /** + * The size of the gap. Default is 1. + * @return + */ public double getGapSize() { return gapSize; } @@ -87,6 +99,10 @@ public void setGapSize(double gapSize) { this.gapSize = gapSize; } + /** + * The size of the gap. Default is 1. + * @return + */ public double getLinewidth() { return this.linewidth; } diff --git a/src/thothbot/parallax/core/shared/materials/MeshDepthMaterial.java b/src/thothbot/parallax/core/shared/materials/MeshDepthMaterial.java index 07fe92a4..3930f211 100644 --- a/src/thothbot/parallax/core/shared/materials/MeshDepthMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/MeshDepthMaterial.java @@ -26,6 +26,10 @@ import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.OrthographicCamera; +/** + * A material for drawing geometry by depth. Depth is based off of the camera near and far plane. White is nearest, black is farthest. + * + */ public class MeshDepthMaterial extends Material implements HasWireframe { // private boolean isMorphTargets = false; diff --git a/src/thothbot/parallax/core/shared/materials/MeshFaceMaterial.java b/src/thothbot/parallax/core/shared/materials/MeshFaceMaterial.java index 0f19012f..d1ea6b77 100644 --- a/src/thothbot/parallax/core/shared/materials/MeshFaceMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/MeshFaceMaterial.java @@ -23,6 +23,13 @@ import thothbot.parallax.core.client.shaders.Shader; +/** + * A Material to define multiple materials for the same geometry. + * The geometry decides which material is used for which faces by the faces materialindex. + * The materialindex corresponds with the index of the material in the materials array. + * + */ + public final class MeshFaceMaterial extends Material { List materials; @@ -32,11 +39,19 @@ public MeshFaceMaterial() this.materials = new ArrayList(); } + /** + * Creates a MeshFaceMaterial with the correct materials. + * @param materials The materials for the geometry. + */ public MeshFaceMaterial(List materials) { this.materials = materials; } + /** + * Get or set the materials for the geometry. + * @return + */ public List getMaterials() { return this.materials; diff --git a/src/thothbot/parallax/core/shared/materials/MeshLambertMaterial.java b/src/thothbot/parallax/core/shared/materials/MeshLambertMaterial.java index 9d5d0e17..93ab5196 100644 --- a/src/thothbot/parallax/core/shared/materials/MeshLambertMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/MeshLambertMaterial.java @@ -29,6 +29,10 @@ import thothbot.parallax.core.shared.math.Color; import thothbot.parallax.core.shared.math.Vector3; +/** + * A material for non-shiny (Lambertian) surfaces, evaluated per vertex. + * + */ public final class MeshLambertMaterial extends Material implements HasMaterialMap, HasWrap, HasWireframe, HasFog, HasVertexColors, HasSkinning, HasAmbientEmissiveColor, HasShading diff --git a/src/thothbot/parallax/core/shared/materials/MeshNormalMaterial.java b/src/thothbot/parallax/core/shared/materials/MeshNormalMaterial.java index 59e55eff..43b18b24 100644 --- a/src/thothbot/parallax/core/shared/materials/MeshNormalMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/MeshNormalMaterial.java @@ -22,6 +22,10 @@ import thothbot.parallax.core.client.shaders.Shader; import thothbot.parallax.core.shared.cameras.Camera; +/** + * A material that maps the normal vectors to RGB colors. + * + */ public final class MeshNormalMaterial extends Material implements HasWireframe, HasShading { private boolean isWireframe; diff --git a/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java b/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java index 498478ef..0f63ac13 100644 --- a/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java @@ -30,6 +30,10 @@ import thothbot.parallax.core.shared.math.Vector2; import thothbot.parallax.core.shared.math.Vector3; +/** + * A material for shiny surfaces, evaluated per pixel. + * + */ public final class MeshPhongMaterial extends Material implements HasMaterialMap, HasBumpMap, HasNormalMap, HasWrap, HasWireframe, HasFog, HasVertexColors, HasSkinning, HasAmbientEmissiveColor, HasShading diff --git a/src/thothbot/parallax/core/shared/objects/Bone.java b/src/thothbot/parallax/core/shared/objects/Bone.java index 8e658308..8ba0e6e8 100644 --- a/src/thothbot/parallax/core/shared/objects/Bone.java +++ b/src/thothbot/parallax/core/shared/objects/Bone.java @@ -20,12 +20,20 @@ import thothbot.parallax.core.shared.core.Object3D; +/** + * A bone which is part of a SkinnedMesh. + * + */ public class Bone extends Object3D { - public Object3D skin; + public SkinnedMesh skin; - public Bone(Object3D belongsToSkin) + /** + * + * @param belongsToSkin An instance of {@link SkinnedMesh}. + */ + public Bone(SkinnedMesh belongsToSkin) { this.skin = belongsToSkin; } diff --git a/src/thothbot/parallax/core/shared/objects/Line.java b/src/thothbot/parallax/core/shared/objects/Line.java index a6d956d3..31ba91d8 100644 --- a/src/thothbot/parallax/core/shared/objects/Line.java +++ b/src/thothbot/parallax/core/shared/objects/Line.java @@ -89,6 +89,13 @@ public Line(Geometry geometry, LineBasicMaterial material) this(geometry, material, Line.MODE.STRIPS); } + /** + * If no material is supplied, a randomized line material will be created and assigned to the object. + * Also, if no type is supplied, the default {@link Line.MODE}.STRIPS will be used). + * @param geometry Vertices representing the line segment(s). + * @param material Material for the line. Default is {@link LineBasicMaterial}. + * @param mode Connection type between vertices. Default is {@link Line.MODE}.STRIPS. + */ public Line(Geometry geometry, LineBasicMaterial material, Line.MODE mode) { super(geometry, material); From ffca224454a42cbd9f00125c6b20ebdcd60d29af Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 27 Jan 2015 14:07:09 +0300 Subject: [PATCH 07/75] Fixed issue in dynamic geometry --- .../parallax/core/client/renderers/WebGLRenderer.java | 2 +- src/thothbot/parallax/core/shared/core/AbstractGeometry.java | 4 +--- src/thothbot/parallax/core/shared/objects/Mesh.java | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index 31195b2c..f692dc15 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -1708,7 +1708,7 @@ public void updateObject( GeometryObject object, Object3D scene ) geometry.uvsNeedUpdate || geometry.normalsNeedUpdate || geometry.colorsNeedUpdate || geometry.tangentsNeedUpdate || customAttributesDirty ) { - ((Mesh)object).setBuffers( gl, geometryGroup, BufferUsage.DYNAMIC_DRAW, ! geometry.dynamic, material ); + ((Mesh)object).setBuffers( gl, geometryGroup, BufferUsage.DYNAMIC_DRAW, ! ((Geometry)geometry).isDynamic(), material ); } diff --git a/src/thothbot/parallax/core/shared/core/AbstractGeometry.java b/src/thothbot/parallax/core/shared/core/AbstractGeometry.java index 7e7f6d9e..1a5ccafa 100644 --- a/src/thothbot/parallax/core/shared/core/AbstractGeometry.java +++ b/src/thothbot/parallax/core/shared/core/AbstractGeometry.java @@ -47,9 +47,7 @@ public abstract class AbstractGeometry extends WebGLGeometry public boolean lineDistancesNeedUpdate = false; public boolean groupsNeedUpdate = false; - - public boolean dynamic = false; - + public AbstractGeometry() { this.id = BufferGeometry.Counter++; diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index a0d315fe..0dd71293 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -767,7 +767,7 @@ public void setBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup, Bu lineArray = geometryGroup.__lineArray; Geometry geometry = (Geometry)this.getGeometry(); // this is shared for all chunks - + boolean dirtyVertices = geometry.verticesNeedUpdate, dirtyElements = geometry.elementsNeedUpdate, dirtyUvs = geometry.uvsNeedUpdate, @@ -793,7 +793,7 @@ public void setBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup, Bu List morphTargets = geometry.getMorphTargets(); List morphNormals = geometry.getMorphNormals(); - + Log.error(dirtyVertices); if ( dirtyVertices ) { for ( int f = 0, fl = chunk_faces3.size(); f < fl; f ++ ) From 859cf03cd1af11d632b77be2f9cdcc36eeef8f79 Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 27 Jan 2015 20:13:03 +0300 Subject: [PATCH 08/75] Removed unused logs --- .../parallax/core/shared/objects/Mesh.java | 18 +++++++++--------- .../parallax/core/shared/utils/ShapeUtils.java | 4 +--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index 0dd71293..be8c56b6 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -793,9 +793,9 @@ public void setBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup, Bu List morphTargets = geometry.getMorphTargets(); List morphNormals = geometry.getMorphNormals(); - Log.error(dirtyVertices); - if ( dirtyVertices ) - { + + if ( dirtyVertices ) + { for ( int f = 0, fl = chunk_faces3.size(); f < fl; f ++ ) { Face3 face = obj_faces.get( chunk_faces3.get( f ) ); @@ -821,10 +821,10 @@ public void setBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup, Bu gl.bindBuffer( BufferTarget.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer); gl.bufferData( BufferTarget.ARRAY_BUFFER, vertexArray, hint ); - } + } - if ( dirtyMorphTargets ) - { + if ( dirtyMorphTargets ) + { for ( int vk = 0, vkl = morphTargets.size(); vk < vkl; vk ++ ) { @@ -905,10 +905,10 @@ public void setBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup, Bu gl.bufferData( BufferTarget.ARRAY_BUFFER, morphNormalsArrays.get( vk ), hint ); } } - } + } - if ( obj_skinWeights.size() > 0 ) - { + if ( obj_skinWeights.size() > 0 ) + { for ( int f = 0, fl = chunk_faces3.size(); f < fl; f ++ ) { Face3 face = obj_faces.get( chunk_faces3.get( f ) ); diff --git a/src/thothbot/parallax/core/shared/utils/ShapeUtils.java b/src/thothbot/parallax/core/shared/utils/ShapeUtils.java index 6b16f1c7..b6533144 100644 --- a/src/thothbot/parallax/core/shared/utils/ShapeUtils.java +++ b/src/thothbot/parallax/core/shared/utils/ShapeUtils.java @@ -211,8 +211,6 @@ public static void removeHoles( List contour, List> holes shape.addAll(tmpHole1); shape.addAll(tmpHole2); shape.addAll(tmpShape2); - - Log.error("!!!!!!!!!!!!!!!!!!!!", shape.size(), tmpHole1.size(), tmpHole2.size(), tmpShape1.size(), tmpShape2.size(), shapeIndex, shape.size()); } } @@ -243,7 +241,7 @@ public static List> triangulateShape ( List contour, List // prepare all points map Map allPointsMap = GWT.isScript() ? new FastMap() : new HashMap(); - Log.error("**********", allpoints.size(), triangles.size(), isolatedPts.size()); + for ( int i = 0, il = allpoints.size(); i < il; i ++ ) { String key = allpoints.get( i ).getX() + ":" + allpoints.get( i ).getY(); From ad9b3911fe2934b32e1b2236560d754eb5720b89 Mon Sep 17 00:00:00 2001 From: thothbot Date: Thu, 29 Jan 2015 02:50:27 +0300 Subject: [PATCH 09/75] Added animation update handler --- .../parallax/core/client/AnimatedScene.java | 4 +- .../parallax/core/client/RenderingPanel.java | 47 +++++++------------ 2 files changed, 18 insertions(+), 33 deletions(-) diff --git a/src/thothbot/parallax/core/client/AnimatedScene.java b/src/thothbot/parallax/core/client/AnimatedScene.java index 7bd523ab..92596c92 100644 --- a/src/thothbot/parallax/core/client/AnimatedScene.java +++ b/src/thothbot/parallax/core/client/AnimatedScene.java @@ -44,7 +44,7 @@ public static interface AnimationUpdateHandler /** * Called when {@link #onUpdate()} called. */ - public void onUpdate(); + public void onUpdate(double duration); } private RenderingPanel renderingPanel; @@ -98,6 +98,6 @@ protected void onRefresh(double duration) getRenderer().getInfo().getTimer().render = new Duration(); onUpdate(duration); - animationUpdateHandler.onUpdate(); + animationUpdateHandler.onUpdate(duration); } } diff --git a/src/thothbot/parallax/core/client/RenderingPanel.java b/src/thothbot/parallax/core/client/RenderingPanel.java index af512e6b..c72d8f10 100644 --- a/src/thothbot/parallax/core/client/RenderingPanel.java +++ b/src/thothbot/parallax/core/client/RenderingPanel.java @@ -23,7 +23,6 @@ import thothbot.parallax.core.client.context.Canvas3d; import thothbot.parallax.core.client.context.Canvas3dAttributes; import thothbot.parallax.core.client.context.Canvas3dException; -import thothbot.parallax.core.client.debugger.Debugger; import thothbot.parallax.core.client.events.AnimationReadyEvent; import thothbot.parallax.core.client.events.AnimationReadyHandler; import thothbot.parallax.core.client.events.Context3dErrorEvent; @@ -35,7 +34,6 @@ import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.Style.Position; -import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.shared.EventHandler; import com.google.gwt.event.shared.GwtEvent; import com.google.gwt.event.shared.HandlerManager; @@ -53,6 +51,11 @@ */ public class RenderingPanel extends LayoutPanel implements IsWidget, HasWidgets, HasHandlers { + public interface AnimationUpdateHandler + { + public void onUpdate(double duration); + } + // Sets the background color for the {@link Canvas3d}. Default: black (#000000). private int clearColor = 0x000000; @@ -64,16 +67,14 @@ public class RenderingPanel extends LayoutPanel implements IsWidget, HasWidgets, private AnimatedScene animatedScene; private HandlerManager handlerManager; private boolean isLoaded = false; - - // Debug panel - private boolean isDebugEnabled; - private Debugger debugger; // Loading info panel private boolean isSceneLoaded; private Canvas3d canvas; private WebGLRenderer renderer; + + private AnimationUpdateHandler animationUpdateHandler; /** * This constructor will create new instance of the widget. @@ -117,6 +118,11 @@ public AnimatedScene getAnimatedScene() return this.animatedScene; } + public void setAnimationUpdateHandler(AnimationUpdateHandler animationUpdateHandler) + { + this.animationUpdateHandler = animationUpdateHandler; + } + /** * Sets the {@link AnimatedScene} to the widget. * @param animatedScene @@ -127,11 +133,6 @@ public void setAnimatedScene(AnimatedScene animatedScene) handlerManager.fireEvent(new SceneLoadingEvent()); } - public void enableDebug(boolean enabled) - { - this.isDebugEnabled = enabled; - } - public void setBackground(int color) { setBackground(color, this.clearAlpha); @@ -182,20 +183,6 @@ private Canvas3d loadCanvas() throws Exception return canvas; } - - /** - * Load Debugger - */ - private void loadDebuger() - { - if(this.isDebugEnabled && this.debugger == null) - { - this.debugger = new Debugger(getRenderer().getInfo()); - this.add(this.debugger); - this.setWidgetRightWidth(this.debugger, 1, Unit.PX, 17, Unit.EM); - this.setWidgetTopHeight(this.debugger, 1, Unit.PX, 50, Unit.PX); - } - } /** * This method is called when a widget is attached to the browser's document. @@ -260,19 +247,17 @@ public void onLoaded() this.animatedScene.init(this, new AnimatedScene.AnimationUpdateHandler() { @Override - public void onUpdate() + public void onUpdate(double duration) { if(!isSceneLoaded) { handlerManager.fireEvent(new SceneLoadingEvent(true)); isSceneLoaded = true; - - loadDebuger(); } - - // Update debugger - if(debugger != null) debugger.update(); + + if(animationUpdateHandler != null) + animationUpdateHandler.onUpdate(duration); } }); From ef979dd1e2ecfe5173d7876a1d94f026b08cc6ec Mon Sep 17 00:00:00 2001 From: thothbot Date: Sat, 31 Jan 2015 01:07:10 +0300 Subject: [PATCH 10/75] Added anaglyph effect --- .../renderers/effects/AnaglyphEffect.java | 178 ++++++++++++++++++ .../renderers/effects/AnaglyphShader.java | 52 +++++ .../renderers/effects/shaders/anaglyph.fs | 17 ++ .../renderers/effects/shaders/anaglyph.vs | 8 + 4 files changed, 255 insertions(+) create mode 100644 src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java create mode 100644 src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java create mode 100644 src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.fs create mode 100644 src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.vs diff --git a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java b/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java new file mode 100644 index 00000000..5392029f --- /dev/null +++ b/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java @@ -0,0 +1,178 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.client.renderers.effects; + +import thothbot.parallax.core.client.gl2.enums.PixelFormat; +import thothbot.parallax.core.client.gl2.enums.TextureMagFilter; +import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; +import thothbot.parallax.core.client.renderers.WebGLRenderer; +import thothbot.parallax.core.client.textures.RenderTargetTexture; +import thothbot.parallax.core.shared.Log; +import thothbot.parallax.core.shared.cameras.OrthographicCamera; +import thothbot.parallax.core.shared.cameras.PerspectiveCamera; +import thothbot.parallax.core.shared.geometries.PlaneBufferGeometry; +import thothbot.parallax.core.shared.materials.ShaderMaterial; +import thothbot.parallax.core.shared.math.Mathematics; +import thothbot.parallax.core.shared.math.Matrix4; +import thothbot.parallax.core.shared.objects.Mesh; +import thothbot.parallax.core.shared.scenes.Scene; + +public class AnaglyphEffect +{ + + WebGLRenderer renderer; + + private Matrix4 eyeRight = new Matrix4(); + private Matrix4 eyeLeft = new Matrix4(); + private double focalLength = 125; + private double _aspect, _near, _far, _fov; + + private PerspectiveCamera _cameraL = new PerspectiveCamera(); + private PerspectiveCamera _cameraR = new PerspectiveCamera(); + + private OrthographicCamera _camera = new OrthographicCamera( -1, 1, 1, - 1, 0, 1 ); + + private Scene _scene = new Scene(); + + private RenderTargetTexture _renderTargetL; + private RenderTargetTexture _renderTargetR; + + private ShaderMaterial _material; + + public AnaglyphEffect(WebGLRenderer renderer) + { + this.renderer = renderer; + + _cameraL.setMatrixAutoUpdate(false); + _cameraR.setMatrixAutoUpdate(false); + + initRenderTargets(renderer.getAbsoluteWidth(), renderer.getAbsoluteHeight()); + + Mesh mesh = new Mesh( new PlaneBufferGeometry( 2, 2 ), _material ); + _scene.add( mesh ); + + } + + public void setSize( int width, int height ) { + + initRenderTargets(width, height); + + renderer.setSize( width, height ); + + } + + private void initRenderTargets(int width, int height ) + { +// if ( _renderTargetL != null ) +// _renderTargetL.dispose(); +// if ( _renderTargetR != null ) +// _renderTargetR.dispose(); + + _renderTargetL = new RenderTargetTexture( width, height ); + _renderTargetL.setMinFilter(TextureMinFilter.LINEAR); + _renderTargetL.setMagFilter(TextureMagFilter.NEAREST); + _renderTargetL.setFormat(PixelFormat.RGBA); + + _renderTargetR = new RenderTargetTexture( width, height ); + _renderTargetR.setMinFilter(TextureMinFilter.LINEAR); + _renderTargetR.setMagFilter(TextureMagFilter.NEAREST); + _renderTargetR.setFormat(PixelFormat.RGBA); + + _material = new ShaderMaterial(new AnaglyphShader()); + _material.getShader().getUniforms().get( "mapLeft" ).setValue( _renderTargetL ); + _material.getShader().getUniforms().get( "mapRight").setValue( _renderTargetR ); + } + + /* + * Renderer now uses an asymmetric perspective projection + * (http://paulbourke.net/miscellaneous/stereographics/stereorender/). + * + * Each camera is offset by the eye seperation and its projection matrix is + * also skewed asymetrically back to converge on the same projection plane. + * Added a focal length parameter to, this is where the parallax is equal to 0. + */ + + public void render( Scene scene, PerspectiveCamera camera ) + { + scene.updateMatrixWorld(false); + + if ( camera.getParent() == null ) + camera.updateMatrixWorld(false); + + boolean hasCameraChanged = ( _aspect != camera.getAspect() ) || ( _near != camera.getNear() ) || ( _far != camera.getFar() ) || ( _fov != camera.getFov() ); + + if ( hasCameraChanged ) + { + _aspect = camera.getAspect(); + _near = camera.getNear(); + _far = camera.getFar(); + _fov = camera.getFov(); + + Matrix4 projectionMatrix = camera.getProjectionMatrix().clone(); + double eyeSep = focalLength / 30.0 * 0.5; + double eyeSepOnProjection = eyeSep * _near / focalLength; + double ymax = _near * Math.tan( Mathematics.degToRad( _fov * 0.5 ) ); + double xmin, xmax; + + // translate xOffset + + eyeRight.getArray().set(12, eyeSep); + eyeLeft.getArray().set(12, -eyeSep); + + // for left eye + + xmin = -ymax * _aspect + eyeSepOnProjection; + xmax = ymax * _aspect + eyeSepOnProjection; + + projectionMatrix.getArray().set(0, 2.0 * _near / ( xmax - xmin )); + projectionMatrix.getArray().set(8, ( xmax + xmin ) / ( xmax - xmin )); + + _cameraL.getProjectionMatrix().copy( projectionMatrix ); + + // for right eye + + xmin = -ymax * _aspect - eyeSepOnProjection; + xmax = ymax * _aspect - eyeSepOnProjection; + + projectionMatrix.getArray().set(0, 2.0 * _near / ( xmax - xmin )); + projectionMatrix.getArray().set(8, ( xmax + xmin ) / ( xmax - xmin )); + + _cameraR.getProjectionMatrix().copy( projectionMatrix ); + + } + + _cameraL.getMatrixWorld().copy( camera.getMatrixWorld() ).multiply( eyeLeft ); + _cameraL.getPosition().copy( camera.getPosition() ); + _cameraL.setNear( camera.getNear() ); + _cameraL.setFar( camera.getFar() ); + + renderer.render( scene, _cameraL, _renderTargetL, true ); + + _cameraR.getMatrixWorld().copy( camera.getMatrixWorld() ).multiply( eyeRight ); + _cameraR.getPosition().copy( camera.getPosition() ); + _cameraR.setNear( camera.getNear() ); + _cameraR.setFar( camera.getFar() ); + + renderer.render( scene, _cameraR, _renderTargetR, true ); + + renderer.render( _scene, _camera ); + + } + +} diff --git a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java b/src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java new file mode 100644 index 00000000..a9165317 --- /dev/null +++ b/src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java @@ -0,0 +1,52 @@ +/* + * Copyright 2014 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.client.renderers.effects; + +import thothbot.parallax.core.client.shaders.Shader; +import thothbot.parallax.core.client.shaders.Uniform; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.resources.client.TextResource; + +public class AnaglyphShader extends Shader +{ + + interface Resources extends DefaultResources + { + Resources INSTANCE = GWT.create(Resources.class); + + @Source("shaders/anaglyph.vs") + TextResource getVertexShader(); + + @Source("shaders/anaglyph.fs") + TextResource getFragmentShader(); + } + + public AnaglyphShader() + { + super(Resources.INSTANCE); + } + + @Override + protected void initUniforms() + { + this.addUniform("mapLeft", new Uniform( Uniform.TYPE.T, null )); + this.addUniform("mapRight", new Uniform( Uniform.TYPE.T, null )); + } +} diff --git a/src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.fs b/src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.fs new file mode 100644 index 00000000..b96f36df --- /dev/null +++ b/src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.fs @@ -0,0 +1,17 @@ +uniform sampler2D mapLeft; +uniform sampler2D mapRight; +varying vec2 vUv; + +void main() { + + vec4 colorL, colorR; + vec2 uv = vUv; + + colorL = texture2D( mapLeft, uv ); + colorR = texture2D( mapRight, uv ); + + // http://3dtv.at/Knowhow/AnaglyphComparison_en.aspx + + gl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1; + +} diff --git a/src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.vs b/src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.vs new file mode 100644 index 00000000..887fa2ae --- /dev/null +++ b/src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.vs @@ -0,0 +1,8 @@ +varying vec2 vUv; + +void main() { + + vUv = vec2( uv.x, uv.y ); + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + +} From 07abc56ac8005dff1690e8f69275575cc0bd3549 Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 2 Feb 2015 15:22:37 +0300 Subject: [PATCH 11/75] Updated rendering target --- .../client/gl2/WebGLRenderingContext.java | 2 +- .../core/client/renderers/WebGLRenderer.java | 43 +++++++++++++++++- .../renderers/effects/AnaglyphEffect.java | 6 +-- .../renderers/effects/AnaglyphShader.java | 4 +- .../textures/RenderTargetCubeTexture.java | 5 +++ .../client/textures/RenderTargetTexture.java | 45 ++++++++++++++++--- 6 files changed, 91 insertions(+), 14 deletions(-) diff --git a/src/thothbot/parallax/core/client/gl2/WebGLRenderingContext.java b/src/thothbot/parallax/core/client/gl2/WebGLRenderingContext.java index a5e6447c..fb7a32ba 100644 --- a/src/thothbot/parallax/core/client/gl2/WebGLRenderingContext.java +++ b/src/thothbot/parallax/core/client/gl2/WebGLRenderingContext.java @@ -1582,7 +1582,7 @@ public void texImage2D(TextureTarget target, int slot, int level, texImage2D(target.getValue() + slot, level, format.getValue(), width, height, border, format.getValue(), type.getValue(), pixels); } - + private native void texImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, ArrayBufferView pixels) /*-{ this.texImage2D(target, level, internalformat, width, height, border, diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index f692dc15..81daed33 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -1820,9 +1820,48 @@ public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget this.transparentObjects = new ArrayList(); projectObject( scene, scene ); + + if ( this.isSortObjects() ) { + + Collections.sort(opaqueObjects, new Comparator() { + + @Override + public int compare(WebGLObject a, WebGLObject b) { + if ( a.z != b.z ) { + + return (int)(b.z - a.z); + + } else { + + return a.id - b.id; + + } + + } + }); + + Collections.sort(transparentObjects, new Comparator() { + + @Override + public int compare(WebGLObject a, WebGLObject b) { + if ( a.material.getId() != b.material.getId() ) { + + return a.material.getId() - b.material.getId(); + + } else if ( a.z != b.z ) { + + return (int)(a.z - b.z); + + } else { + + return a.id - b.id; -// if ( this.isSortObjects() ) -// Collections.sort(renderList); + } + + } + }); + + } // custom render plugins (pre pass) renderPlugins( this.renderPluginsPre, camera ); diff --git a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java b/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java index 5392029f..5e56b8d7 100644 --- a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java +++ b/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java @@ -61,9 +61,9 @@ public AnaglyphEffect(WebGLRenderer renderer) _cameraL.setMatrixAutoUpdate(false); _cameraR.setMatrixAutoUpdate(false); - + initRenderTargets(renderer.getAbsoluteWidth(), renderer.getAbsoluteHeight()); - + Mesh mesh = new Mesh( new PlaneBufferGeometry( 2, 2 ), _material ); _scene.add( mesh ); @@ -88,7 +88,7 @@ private void initRenderTargets(int width, int height ) _renderTargetL.setMinFilter(TextureMinFilter.LINEAR); _renderTargetL.setMagFilter(TextureMagFilter.NEAREST); _renderTargetL.setFormat(PixelFormat.RGBA); - + _renderTargetR = new RenderTargetTexture( width, height ); _renderTargetR.setMinFilter(TextureMinFilter.LINEAR); _renderTargetR.setMagFilter(TextureMagFilter.NEAREST); diff --git a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java b/src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java index a9165317..94f4becd 100644 --- a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java +++ b/src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java @@ -46,7 +46,7 @@ public AnaglyphShader() @Override protected void initUniforms() { - this.addUniform("mapLeft", new Uniform( Uniform.TYPE.T, null )); - this.addUniform("mapRight", new Uniform( Uniform.TYPE.T, null )); + this.addUniform("mapLeft", new Uniform( Uniform.TYPE.T )); + this.addUniform("mapRight", new Uniform( Uniform.TYPE.T )); } } diff --git a/src/thothbot/parallax/core/client/textures/RenderTargetCubeTexture.java b/src/thothbot/parallax/core/client/textures/RenderTargetCubeTexture.java index 2b64d54e..5e420ec6 100644 --- a/src/thothbot/parallax/core/client/textures/RenderTargetCubeTexture.java +++ b/src/thothbot/parallax/core/client/textures/RenderTargetCubeTexture.java @@ -55,11 +55,16 @@ public void deallocate(WebGLRenderingContext gl) return; gl.deleteTexture(this.getWebGlTexture()); + this.setWebGlTexture(null); + for (int i = 0; i < 6; i++) { gl.deleteFramebuffer(this.webglFramebuffer.get(i)); gl.deleteRenderbuffer(this.webglRenderbuffer.get(i)); } + + this.webglFramebuffer = null; + this.webglRenderbuffer = null; } @Override diff --git a/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java b/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java index 76bfb226..061a71cb 100644 --- a/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java +++ b/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java @@ -18,6 +18,7 @@ package thothbot.parallax.core.client.textures; +import thothbot.parallax.core.client.gl2.WebGLConstants; import thothbot.parallax.core.client.gl2.WebGLFramebuffer; import thothbot.parallax.core.client.gl2.WebGLRenderbuffer; import thothbot.parallax.core.client.gl2.WebGLRenderingContext; @@ -41,6 +42,8 @@ public class RenderTargetTexture extends Texture private WebGLFramebuffer webglFramebuffer; private WebGLRenderbuffer webglRenderbuffer; + + public RenderTargetTexture shareDepthFrom; public RenderTargetTexture(int width, int height) { @@ -112,8 +115,13 @@ public void deallocate(WebGLRenderingContext gl) return; gl.deleteTexture(this.getWebGlTexture()); + this.setWebGlTexture(null); + gl.deleteFramebuffer(this.webglFramebuffer); gl.deleteRenderbuffer(this.webglRenderbuffer); + + this.webglFramebuffer = null; + this.webglRenderbuffer = null; } public RenderTargetTexture clone() @@ -144,31 +152,56 @@ public void setRenderTarget(WebGLRenderingContext gl) { if (this.webglFramebuffer != null) return; - + + this.deallocate(gl); this.setWebGlTexture(gl.createTexture()); - + // Setup texture, create render and frame buffers boolean isTargetPowerOfTwo = Mathematics.isPowerOfTwo(this.width) && Mathematics.isPowerOfTwo(this.height); this.webglFramebuffer = gl.createFramebuffer(); - this.webglRenderbuffer = gl.createRenderbuffer(); + + if ( this.shareDepthFrom != null ) + { + this.webglRenderbuffer = this.shareDepthFrom.webglRenderbuffer; + } + else + { + this.webglRenderbuffer = gl.createRenderbuffer(); + } gl.bindTexture(TextureTarget.TEXTURE_2D, this.getWebGlTexture()); - setTextureParameters(gl, TextureTarget.TEXTURE_2D, isTargetPowerOfTwo); gl.texImage2D(TextureTarget.TEXTURE_2D, 0, this.width, this.height, 0, getFormat(), getType(), null); setupFrameBuffer(gl, this.webglFramebuffer, TextureTarget.TEXTURE_2D); - setupRenderBuffer(gl, this.webglRenderbuffer); + + if ( this.shareDepthFrom != null ) + { + + if ( this.isDepthBuffer && ! this.isStencilBuffer ) { + + gl.framebufferRenderbuffer( FramebufferSlot.DEPTH_ATTACHMENT, this.webglRenderbuffer ); + + } else if ( this.isDepthBuffer && this.isStencilBuffer ) { + + gl.framebufferRenderbuffer( FramebufferSlot.DEPTH_STENCIL_ATTACHMENT, this.webglRenderbuffer ); + + } + + } else { + + setupRenderBuffer( gl, this.webglRenderbuffer ); + + } if (isTargetPowerOfTwo) gl.generateMipmap(TextureTarget.TEXTURE_2D); // Release everything - gl.bindTexture(TextureTarget.TEXTURE_2D, null); gl.bindRenderbuffer(null); gl.bindFramebuffer(null); } From 4002949552d6697ae326d88e01b24214c2822b4c Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 3 Feb 2015 01:57:35 +0300 Subject: [PATCH 12/75] Updated issues with auto-resize --- .../core/client/renderers/WebGLRenderer.java | 17 ++++++---- .../renderers/effects/AnaglyphEffect.java | 26 +++++++++++---- .../parallax/core/shared/cameras/Camera.java | 2 +- .../shared/cameras/OrthographicCamera.java | 20 +++++++++--- .../parallax/core/shared/math/Matrix4.java | 32 +++++++++---------- .../parallax/core/shared/objects/Mesh.java | 4 +++ 6 files changed, 66 insertions(+), 35 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index 81daed33..c63e2985 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -1814,7 +1814,7 @@ public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget _projScreenMatrix.multiply( camera.getProjectionMatrix(), camera.getMatrixWorldInverse() ); _frustum.setFromMatrix( _projScreenMatrix ); - + this.lights = new ArrayList(); this.opaqueObjects = new ArrayList(); this.transparentObjects = new ArrayList(); @@ -3099,28 +3099,33 @@ public void setRenderTarget( RenderTargetTexture renderTarget ) Log.debug("Called setRenderTarget(params)"); WebGLFramebuffer framebuffer = null; + int width, height; + if(renderTarget != null) { renderTarget.setRenderTarget(getGL()); framebuffer = renderTarget.getWebGLFramebuffer(); - this._currentWidth = renderTarget.getWidth(); - this._currentHeight = renderTarget.getHeight(); + width = renderTarget.getWidth(); + height = renderTarget.getHeight(); } else { - this._currentWidth = this._viewportWidth; - this._currentHeight = this._viewportHeight; + width = this._viewportWidth; + height = this._viewportHeight; } if ( framebuffer != this._currentFramebuffer ) { getGL().bindFramebuffer( framebuffer ); - getGL().viewport( 0, 0, this._currentWidth, this._currentHeight ); + getGL().viewport( 0, 0, width, height); this._currentFramebuffer = framebuffer; } + + _currentWidth = width; + _currentHeight = height; } /** diff --git a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java b/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java index 5e56b8d7..afbaedff 100644 --- a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java +++ b/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java @@ -18,6 +18,8 @@ package thothbot.parallax.core.client.renderers.effects; +import thothbot.parallax.core.client.events.ViewportResizeEvent; +import thothbot.parallax.core.client.events.ViewportResizeHandler; import thothbot.parallax.core.client.gl2.enums.PixelFormat; import thothbot.parallax.core.client.gl2.enums.TextureMagFilter; import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; @@ -46,7 +48,7 @@ public class AnaglyphEffect private PerspectiveCamera _cameraL = new PerspectiveCamera(); private PerspectiveCamera _cameraR = new PerspectiveCamera(); - private OrthographicCamera _camera = new OrthographicCamera( -1, 1, 1, - 1, 0, 1 ); + private OrthographicCamera _camera = new OrthographicCamera( 2, 2, 0, 1 ); private Scene _scene = new Scene(); @@ -61,7 +63,16 @@ public AnaglyphEffect(WebGLRenderer renderer) _cameraL.setMatrixAutoUpdate(false); _cameraR.setMatrixAutoUpdate(false); - + + _camera.addViewportResizeHandler(new ViewportResizeHandler() { + + @Override + public void onResize(ViewportResizeEvent event) { + _camera.setSize( 2, 2 ); + + } + }); + initRenderTargets(renderer.getAbsoluteWidth(), renderer.getAbsoluteHeight()); Mesh mesh = new Mesh( new PlaneBufferGeometry( 2, 2 ), _material ); @@ -79,10 +90,10 @@ public void setSize( int width, int height ) { private void initRenderTargets(int width, int height ) { -// if ( _renderTargetL != null ) -// _renderTargetL.dispose(); -// if ( _renderTargetR != null ) -// _renderTargetR.dispose(); + if ( _renderTargetL != null ) + _renderTargetL.deallocate(this.renderer.getGL()); + if ( _renderTargetR != null ) + _renderTargetR.deallocate(this.renderer.getGL()); _renderTargetL = new RenderTargetTexture( width, height ); _renderTargetL.setMinFilter(TextureMinFilter.LINEAR); @@ -96,7 +107,8 @@ private void initRenderTargets(int width, int height ) _material = new ShaderMaterial(new AnaglyphShader()); _material.getShader().getUniforms().get( "mapLeft" ).setValue( _renderTargetL ); - _material.getShader().getUniforms().get( "mapRight").setValue( _renderTargetR ); + _material.getShader().getUniforms().get( "mapRight").setValue( _renderTargetR ); + } /* diff --git a/src/thothbot/parallax/core/shared/cameras/Camera.java b/src/thothbot/parallax/core/shared/cameras/Camera.java index f019a4c7..87ec8a25 100644 --- a/src/thothbot/parallax/core/shared/cameras/Camera.java +++ b/src/thothbot/parallax/core/shared/cameras/Camera.java @@ -54,7 +54,7 @@ public Camera() public HandlerRegistration addViewportResizeHandler(ViewportResizeHandler handler) { - return EVENT_BUS.addHandler(ViewportResizeEvent.TYPE, handler); + return EVENT_BUS.addHandler(ViewportResizeEvent.TYPE, handler); } @Override diff --git a/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java b/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java index 831f95a1..59f669f4 100644 --- a/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java +++ b/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java @@ -19,6 +19,7 @@ package thothbot.parallax.core.shared.cameras; import thothbot.parallax.core.client.events.ViewportResizeEvent; +import thothbot.parallax.core.shared.Log; /** * Camera with orthographic projection @@ -46,7 +47,7 @@ public class OrthographicCamera extends Camera protected double bottom; protected double near = 0.1; - protected double far = 200.0; + protected double far = 2000.0; /** * Orthographic Camera constructor. @@ -204,10 +205,10 @@ public void setFar(double far) */ public void updateProjectionMatrix() { - double dx = ( this.right - this.left ) / ( 2 * this.zoom ); - double dy = ( this.top - this.bottom ) / ( 2 * this.zoom ); - double cx = ( this.right + this.left ) / 2; - double cy = ( this.top + this.bottom ) / 2; + double dx = ( this.right - this.left ) / ( 2.0 * this.zoom ); + double dy = ( this.top - this.bottom ) / ( 2.0 * this.zoom ); + double cx = ( this.right + this.left ) / 2.0; + double cy = ( this.top + this.bottom ) / 2.0; this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far ); @@ -233,4 +234,13 @@ public OrthographicCamera clone() { return camera; } + + public String toString() + { + return OrthographicCamera.class.getSimpleName() + + " {left: " + this.left + + ", right: " + this.right + + ", top: " + this.top + + ", bottom: " + this.bottom + " }"; + } } diff --git a/src/thothbot/parallax/core/shared/math/Matrix4.java b/src/thothbot/parallax/core/shared/math/Matrix4.java index 67a1c11f..4494d15a 100644 --- a/src/thothbot/parallax/core/shared/math/Matrix4.java +++ b/src/thothbot/parallax/core/shared/math/Matrix4.java @@ -716,22 +716,22 @@ public Matrix4 getInverse(Matrix4 m) double n31 = me.get(2), n32 = me.get(6), n33 = me.get(10), n34 = me.get(14); double n41 = me.get(3), n42 = me.get(7), n43 = me.get(11), n44 = me.get(15); - te.set(0, n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44); - te.set(4, n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44); - te.set(8, n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44); - te.set(12, n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34); - te.set(1, n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44); - te.set(5, n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44); - te.set(9, n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44); - te.set(13, n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34); - te.set(2, n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44); - te.set(6, n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44); - te.set(10, n12*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44); - te.set(14, n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34); - te.set(3, n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43); - te.set(7, n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43); - te.set(11, n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43); - te.set(15, n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33); + te.set(0, n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44); + te.set(4, n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44); + te.set(8, n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44); + te.set(12, n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34); + te.set(1, n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44); + te.set(5, n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44); + te.set(9, n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44); + te.set(13, n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34); + te.set(2, n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44); + te.set(6, n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44); + te.set(10, n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44); + te.set(14, n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34); + te.set(3, n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43); + te.set(7, n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43); + te.set(11, n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43); + te.set(15, n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33); double det = n11 * te.get( 0 ) + n21 * te.get( 4 ) + n31 * te.get( 8 ) + n41 * te.get( 12 ); diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index be8c56b6..8bb99c70 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -380,6 +380,10 @@ public void raycast( Raycaster raycaster, List intersects) } + public Mesh clone() { + return clone(false); + } + public Mesh clone( boolean recursive ) { return clone(new Mesh( this.getGeometry(), this.getMaterial() ), recursive); } From 74d333817312809580aa27602014eccdac2cfa31 Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 3 Feb 2015 17:29:43 +0300 Subject: [PATCH 13/75] Added fullscreen support for Rendering panel --- .../parallax/core/client/RenderingPanel.java | 19 +++++++++++++++++++ .../core/client/context/Canvas3d.java | 7 ++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/thothbot/parallax/core/client/RenderingPanel.java b/src/thothbot/parallax/core/client/RenderingPanel.java index c72d8f10..4d62144c 100644 --- a/src/thothbot/parallax/core/client/RenderingPanel.java +++ b/src/thothbot/parallax/core/client/RenderingPanel.java @@ -33,6 +33,7 @@ import thothbot.parallax.core.shared.Log; import com.google.gwt.core.client.Scheduler; +import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Position; import com.google.gwt.event.shared.EventHandler; import com.google.gwt.event.shared.GwtEvent; @@ -338,4 +339,22 @@ private static String cssColor(int color) return retval; } + + public void toFullScreen() { + RenderingPanel.toFullScreen(this.getElement()); + } + + private static native void toFullScreen(Element element) /*-{ + if(element.requestFullscreen) { + element.requestFullscreen(); + } else if(element.webkitRequestFullscreen) { + element.webkitRequestFullscreen(); + } else if(element.mozRequestFullscreen) { + element.mozRequestFullScreen(); + } + + var rect = element.getBoundingClientRect(); + element.width = rect.width; + element.height = rect.height; + }-*/; } diff --git a/src/thothbot/parallax/core/client/context/Canvas3d.java b/src/thothbot/parallax/core/client/context/Canvas3d.java index 8ae60323..4d4eef80 100644 --- a/src/thothbot/parallax/core/client/context/Canvas3d.java +++ b/src/thothbot/parallax/core/client/context/Canvas3d.java @@ -24,6 +24,7 @@ import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.dom.client.CanvasElement; import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Element; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.ui.FocusWidget; @@ -47,9 +48,9 @@ public class Canvas3d extends FocusWidget */ public Canvas3d(Canvas3dAttributes attribs) throws Exception { - canvas = Document.get().createElement("canvas").cast(); + canvas = Document.get().createCanvasElement(); setElement(canvas); - + for (final String contextId : CONTEXT_IDS) { try @@ -77,7 +78,7 @@ private static native WebGLRenderingContext getContext(CanvasElement canvas, Str JavaScriptObject glContextAttr) /*-{ return canvas.getContext(contextId, glContextAttr); }-*/; - + /** * Gets the width of the canvas3d. */ From ab162a22dd51f6914abe2b935724a6ba0a578865 Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 3 Feb 2015 18:46:26 +0300 Subject: [PATCH 14/75] Added effects plugin and moved anagliph into it --- .../parallax/core/client/RenderingPanel.java | 8 ++++ .../core/client/renderers/Plugin.java | 5 ++- .../core/client/renderers/WebGLRenderer.java | 6 ++- .../effects/Anaglyph.java} | 38 +++++++++++++------ .../parallax/plugins/effects/Effects.gwt.xml | 7 ++++ .../effects/shaders}/AnaglyphShader.java | 6 +-- .../effects/shaders/source}/anaglyph.fs | 0 .../effects/shaders/source}/anaglyph.vs | 0 8 files changed, 51 insertions(+), 19 deletions(-) rename src/thothbot/parallax/{core/client/renderers/effects/AnaglyphEffect.java => plugins/effects/Anaglyph.java} (89%) create mode 100644 src/thothbot/parallax/plugins/effects/Effects.gwt.xml rename src/thothbot/parallax/{core/client/renderers/effects => plugins/effects/shaders}/AnaglyphShader.java (91%) rename src/thothbot/parallax/{core/client/renderers/effects/shaders => plugins/effects/shaders/source}/anaglyph.fs (100%) rename src/thothbot/parallax/{core/client/renderers/effects/shaders => plugins/effects/shaders/source}/anaglyph.vs (100%) diff --git a/src/thothbot/parallax/core/client/RenderingPanel.java b/src/thothbot/parallax/core/client/RenderingPanel.java index 4d62144c..45fc0af8 100644 --- a/src/thothbot/parallax/core/client/RenderingPanel.java +++ b/src/thothbot/parallax/core/client/RenderingPanel.java @@ -357,4 +357,12 @@ private static native void toFullScreen(Element element) /*-{ element.width = rect.width; element.height = rect.height; }-*/; + + public boolean isSupportFullScreen() { + return RenderingPanel.isSupportFullScreen(this.getElement()); + } + + private static native boolean isSupportFullScreen(Element element) /*-{ + return (element.requestFullscreen || element.webkitRequestFullscreen || element.mozRequestFullscreen) ? true : false; + }-*/; } diff --git a/src/thothbot/parallax/core/client/renderers/Plugin.java b/src/thothbot/parallax/core/client/renderers/Plugin.java index b294702c..70516c8c 100644 --- a/src/thothbot/parallax/core/client/renderers/Plugin.java +++ b/src/thothbot/parallax/core/client/renderers/Plugin.java @@ -32,9 +32,10 @@ public enum TYPE { }; private boolean isEnabled = true; - private WebGLRenderer renderer; - private Scene scene; private boolean isRendering; + + protected WebGLRenderer renderer; + protected Scene scene; public Plugin(WebGLRenderer renderer, Scene scene) { diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index c63e2985..28559511 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -72,6 +72,7 @@ import thothbot.parallax.core.client.textures.Texture; import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.cameras.PerspectiveCamera; import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.BufferAttribute; import thothbot.parallax.core.shared.core.BufferGeometry; @@ -113,6 +114,7 @@ import thothbot.parallax.core.shared.scenes.AbstractFog; import thothbot.parallax.core.shared.scenes.FogExp2; import thothbot.parallax.core.shared.scenes.Scene; +import thothbot.parallax.plugins.effects.Anaglyph; import com.google.gwt.canvas.dom.client.Context2d; import com.google.gwt.core.client.GWT; @@ -1779,7 +1781,7 @@ public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget { render(scene, camera, renderTarget, false); } - + /** * Rendering. * @@ -1790,7 +1792,7 @@ public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget, boolean forceClear ) { Log.debug("Called render()"); - + AbstractFog fog = scene.getFog(); // reset caching for this frame diff --git a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java b/src/thothbot/parallax/plugins/effects/Anaglyph.java similarity index 89% rename from src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java rename to src/thothbot/parallax/plugins/effects/Anaglyph.java index afbaedff..c5f2272c 100644 --- a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphEffect.java +++ b/src/thothbot/parallax/plugins/effects/Anaglyph.java @@ -16,30 +16,32 @@ * If not, see http://creativecommons.org/licenses/by/3.0/. */ -package thothbot.parallax.core.client.renderers.effects; +package thothbot.parallax.plugins.effects; + +import java.util.List; import thothbot.parallax.core.client.events.ViewportResizeEvent; import thothbot.parallax.core.client.events.ViewportResizeHandler; import thothbot.parallax.core.client.gl2.enums.PixelFormat; import thothbot.parallax.core.client.gl2.enums.TextureMagFilter; import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; +import thothbot.parallax.core.client.renderers.Plugin; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.textures.RenderTargetTexture; -import thothbot.parallax.core.shared.Log; +import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.OrthographicCamera; import thothbot.parallax.core.shared.cameras.PerspectiveCamera; import thothbot.parallax.core.shared.geometries.PlaneBufferGeometry; +import thothbot.parallax.core.shared.lights.Light; import thothbot.parallax.core.shared.materials.ShaderMaterial; import thothbot.parallax.core.shared.math.Mathematics; import thothbot.parallax.core.shared.math.Matrix4; import thothbot.parallax.core.shared.objects.Mesh; import thothbot.parallax.core.shared.scenes.Scene; +import thothbot.parallax.plugins.effects.shaders.AnaglyphShader; -public class AnaglyphEffect +public class Anaglyph extends Plugin { - - WebGLRenderer renderer; - private Matrix4 eyeRight = new Matrix4(); private Matrix4 eyeLeft = new Matrix4(); private double focalLength = 125; @@ -56,10 +58,10 @@ public class AnaglyphEffect private RenderTargetTexture _renderTargetR; private ShaderMaterial _material; - - public AnaglyphEffect(WebGLRenderer renderer) + + public Anaglyph(WebGLRenderer renderer, Scene scene) { - this.renderer = renderer; + super(renderer, scene); _cameraL.setMatrixAutoUpdate(false); _cameraR.setMatrixAutoUpdate(false); @@ -68,6 +70,7 @@ public AnaglyphEffect(WebGLRenderer renderer) @Override public void onResize(ViewportResizeEvent event) { + _camera.setSize( 2, 2 ); } @@ -80,6 +83,12 @@ public void onResize(ViewportResizeEvent event) { } + + @Override + public TYPE getType() { + return Plugin.TYPE.POST_RENDER; + } + public void setSize( int width, int height ) { initRenderTargets(width, height); @@ -120,10 +129,16 @@ private void initRenderTargets(int width, int height ) * Added a focal length parameter to, this is where the parallax is equal to 0. */ - public void render( Scene scene, PerspectiveCamera camera ) + @Override + public void render( Camera sceneCamera, List lights, int currentWidth, int currentHeight ) { - scene.updateMatrixWorld(false); + if(!(sceneCamera instanceof PerspectiveCamera)) + return; + + PerspectiveCamera camera = (PerspectiveCamera)sceneCamera; + scene.updateMatrixWorld(false); + if ( camera.getParent() == null ) camera.updateMatrixWorld(false); @@ -186,5 +201,4 @@ public void render( Scene scene, PerspectiveCamera camera ) renderer.render( _scene, _camera ); } - } diff --git a/src/thothbot/parallax/plugins/effects/Effects.gwt.xml b/src/thothbot/parallax/plugins/effects/Effects.gwt.xml new file mode 100644 index 00000000..a8820f33 --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/Effects.gwt.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java b/src/thothbot/parallax/plugins/effects/shaders/AnaglyphShader.java similarity index 91% rename from src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java rename to src/thothbot/parallax/plugins/effects/shaders/AnaglyphShader.java index 94f4becd..9a636110 100644 --- a/src/thothbot/parallax/core/client/renderers/effects/AnaglyphShader.java +++ b/src/thothbot/parallax/plugins/effects/shaders/AnaglyphShader.java @@ -16,7 +16,7 @@ * If not, see http://creativecommons.org/licenses/by/3.0/. */ -package thothbot.parallax.core.client.renderers.effects; +package thothbot.parallax.plugins.effects.shaders; import thothbot.parallax.core.client.shaders.Shader; import thothbot.parallax.core.client.shaders.Uniform; @@ -31,10 +31,10 @@ interface Resources extends DefaultResources { Resources INSTANCE = GWT.create(Resources.class); - @Source("shaders/anaglyph.vs") + @Source("source/anaglyph.vs") TextResource getVertexShader(); - @Source("shaders/anaglyph.fs") + @Source("source/anaglyph.fs") TextResource getFragmentShader(); } diff --git a/src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.fs b/src/thothbot/parallax/plugins/effects/shaders/source/anaglyph.fs similarity index 100% rename from src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.fs rename to src/thothbot/parallax/plugins/effects/shaders/source/anaglyph.fs diff --git a/src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.vs b/src/thothbot/parallax/plugins/effects/shaders/source/anaglyph.vs similarity index 100% rename from src/thothbot/parallax/core/client/renderers/effects/shaders/anaglyph.vs rename to src/thothbot/parallax/plugins/effects/shaders/source/anaglyph.vs From a48ae93517db6cc775699557ed0a27160b79419c Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 3 Feb 2015 20:22:42 +0300 Subject: [PATCH 15/75] Added Stereo effects plugin --- .../core/client/renderers/WebGLRenderer.java | 21 +++ .../shared/cameras/PerspectiveCamera.java | 2 +- .../parallax/plugins/effects/Anaglyph.java | 10 +- .../parallax/plugins/effects/Effect.java | 40 +++++ .../parallax/plugins/effects/Stereo.java | 139 ++++++++++++++++++ 5 files changed, 203 insertions(+), 9 deletions(-) create mode 100644 src/thothbot/parallax/plugins/effects/Effect.java create mode 100644 src/thothbot/parallax/plugins/effects/Stereo.java diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index 28559511..d5399457 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -370,6 +370,7 @@ public WebGLRenderer(WebGLRenderingContext gl, int width, int height) public void addPlugin(Plugin plugin) { + deletePlugin(plugin); if(plugin.getType() == Plugin.TYPE.PRE_RENDER) { this.renderPluginsPre.add( plugin ); @@ -385,6 +386,26 @@ else if(plugin.getType() == Plugin.TYPE.POST_RENDER) } } + public void deletePlugin(Plugin plugin) + { + if(plugin == null) + return; + + if(plugin.getType() == Plugin.TYPE.PRE_RENDER) + { + this.renderPluginsPre.remove( plugin ); + } + else if(plugin.getType() == Plugin.TYPE.POST_RENDER) + { + this.renderPluginsPost.remove( plugin ); + } + else + { + Log.error("Unknown plugin type: " + plugin.getType()); + return; + } + } + public boolean supportsVertexTextures() { return this._maxVertexTextures > 0; diff --git a/src/thothbot/parallax/core/shared/cameras/PerspectiveCamera.java b/src/thothbot/parallax/core/shared/cameras/PerspectiveCamera.java index 9e843d37..ff8b18b8 100644 --- a/src/thothbot/parallax/core/shared/cameras/PerspectiveCamera.java +++ b/src/thothbot/parallax/core/shared/cameras/PerspectiveCamera.java @@ -33,7 +33,7 @@ */ public class PerspectiveCamera extends Camera { - protected double zoom = 1.0; + public double zoom = 1.0; protected double fov; protected double aspect; diff --git a/src/thothbot/parallax/plugins/effects/Anaglyph.java b/src/thothbot/parallax/plugins/effects/Anaglyph.java index c5f2272c..6358b6b5 100644 --- a/src/thothbot/parallax/plugins/effects/Anaglyph.java +++ b/src/thothbot/parallax/plugins/effects/Anaglyph.java @@ -40,7 +40,7 @@ import thothbot.parallax.core.shared.scenes.Scene; import thothbot.parallax.plugins.effects.shaders.AnaglyphShader; -public class Anaglyph extends Plugin +public class Anaglyph extends Effect { private Matrix4 eyeRight = new Matrix4(); private Matrix4 eyeLeft = new Matrix4(); @@ -82,13 +82,7 @@ public void onResize(ViewportResizeEvent event) { _scene.add( mesh ); } - - - @Override - public TYPE getType() { - return Plugin.TYPE.POST_RENDER; - } - + public void setSize( int width, int height ) { initRenderTargets(width, height); diff --git a/src/thothbot/parallax/plugins/effects/Effect.java b/src/thothbot/parallax/plugins/effects/Effect.java new file mode 100644 index 00000000..e3e76d4c --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/Effect.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.plugins.effects; + +import java.util.List; + +import thothbot.parallax.core.client.renderers.Plugin; +import thothbot.parallax.core.client.renderers.Plugin.TYPE; +import thothbot.parallax.core.client.renderers.WebGLRenderer; +import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.lights.Light; +import thothbot.parallax.core.shared.scenes.Scene; + +public abstract class Effect extends Plugin { + + public Effect(WebGLRenderer renderer, Scene scene) { + super(renderer, scene); + } + + @Override + public TYPE getType() { + return Plugin.TYPE.POST_RENDER; + } +} diff --git a/src/thothbot/parallax/plugins/effects/Stereo.java b/src/thothbot/parallax/plugins/effects/Stereo.java new file mode 100644 index 00000000..079b6253 --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/Stereo.java @@ -0,0 +1,139 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.plugins.effects; + +import java.util.List; + +import thothbot.parallax.core.client.renderers.WebGLRenderer; +import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.cameras.PerspectiveCamera; +import thothbot.parallax.core.shared.lights.Light; +import thothbot.parallax.core.shared.math.Mathematics; +import thothbot.parallax.core.shared.math.Quaternion; +import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.scenes.Scene; + +public class Stereo extends Effect { + + private double eyeSeparation = 3.0; + // Distance to the non-parallax or projection plane + private double focalLength = 15.0; + + // internals + + Vector3 _position = new Vector3(); + Quaternion _quaternion = new Quaternion(); + Vector3 _scale = new Vector3(); + + PerspectiveCamera _cameraL = new PerspectiveCamera(); + PerspectiveCamera _cameraR = new PerspectiveCamera(); + + double _fov; + double _outer, _inner, _top, _bottom; + double _ndfl, _halfFocalWidth, _halfFocalHeight; + double _innerFactor, _outerFactor; + + public Stereo(WebGLRenderer renderer, Scene scene) { + super(renderer, scene); + + renderer.setAutoClear(false); + } + + @Override + public void render(Camera sceneCamera, List lights, int currentWidth, int currentHeight) + { + if(!(sceneCamera instanceof PerspectiveCamera)) + return; + + PerspectiveCamera camera = (PerspectiveCamera)sceneCamera; + + scene.updateMatrixWorld(false); + + if ( camera.getParent() == null ) + camera.updateMatrixWorld(false); + + camera.getMatrixWorld().decompose( _position, _quaternion, _scale ); + + // Effective fov of the camera + + _fov = Mathematics.radToDeg( 2.0 * Math.atan( Math.tan( Mathematics.degToRad( camera.getFov() ) * 0.5 ) / camera.zoom ) ); + + _ndfl = camera.getNear() / this.focalLength; + _halfFocalHeight = Math.tan( Mathematics.degToRad( _fov ) * 0.5 ) * this.focalLength; + _halfFocalWidth = _halfFocalHeight * 0.5 * camera.getAspect(); + + _top = _halfFocalHeight * _ndfl; + _bottom = -_top; + _innerFactor = ( _halfFocalWidth + this.eyeSeparation / 2.0 ) / ( _halfFocalWidth * 2.0 ); + _outerFactor = 1.0 - _innerFactor; + + _outer = _halfFocalWidth * 2.0 * _ndfl * _outerFactor; + _inner = _halfFocalWidth * 2.0 * _ndfl * _innerFactor; + + // left + + _cameraL.getProjectionMatrix().makeFrustum( + -_outer, + _inner, + _bottom, + _top, + camera.getNear(), + camera.getFar() + ); + + _cameraL.getPosition().copy( _position ); + _cameraL.getQuaternion().copy( _quaternion ); + _cameraL.translateX( - this.eyeSeparation / 2.0 ); + + // right + + _cameraR.getProjectionMatrix().makeFrustum( + -_inner, + _outer, + _bottom, + _top, + camera.getNear(), + camera.getFar() + ); + + _cameraR.getPosition().copy( _position ); + _cameraR.getQuaternion().copy( _quaternion ); + _cameraR.translateX( this.eyeSeparation / 2.0 ); + + // + + renderer.clear(); + renderer.enableScissorTest( true ); + + int _width = renderer.getAbsoluteWidth() / 2; + int _height = renderer.getAbsoluteHeight(); + + renderer.setScissor( 0, 0, _width, _height ); + renderer.setViewport( 0, 0, _width, _height ); + renderer.render( scene, _cameraL ); + + renderer.setScissor( _width, 0, _width, _height ); + renderer.setViewport( _width, 0, _width, _height ); + renderer.render( scene, _cameraR ); + + renderer.enableScissorTest( false ); + + } + +} From 863f9c20d6193b7ecf4f100a073af1b45b003af8 Mon Sep 17 00:00:00 2001 From: thothbot Date: Wed, 4 Feb 2015 01:02:54 +0300 Subject: [PATCH 16/75] Added ParallaxBarrier effect --- .../plugins/effects/ParallaxBarrier.java | 191 ++++++++++++++++++ .../shaders/ParallaxBarrierShader.java | 52 +++++ .../effects/shaders/source/parallaxBarrier.fs | 19 ++ .../effects/shaders/source/parallaxBarrier.vs | 8 + 4 files changed, 270 insertions(+) create mode 100644 src/thothbot/parallax/plugins/effects/ParallaxBarrier.java create mode 100644 src/thothbot/parallax/plugins/effects/shaders/ParallaxBarrierShader.java create mode 100644 src/thothbot/parallax/plugins/effects/shaders/source/parallaxBarrier.fs create mode 100644 src/thothbot/parallax/plugins/effects/shaders/source/parallaxBarrier.vs diff --git a/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java b/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java new file mode 100644 index 00000000..930c8e94 --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java @@ -0,0 +1,191 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.plugins.effects; + +import java.util.List; + +import thothbot.parallax.core.client.gl2.enums.PixelFormat; +import thothbot.parallax.core.client.gl2.enums.TextureMagFilter; +import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; +import thothbot.parallax.core.client.renderers.WebGLRenderer; +import thothbot.parallax.core.client.textures.RenderTargetTexture; +import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.cameras.PerspectiveCamera; +import thothbot.parallax.core.shared.geometries.PlaneBufferGeometry; +import thothbot.parallax.core.shared.lights.Light; +import thothbot.parallax.core.shared.materials.ShaderMaterial; +import thothbot.parallax.core.shared.math.Mathematics; +import thothbot.parallax.core.shared.math.Matrix4; +import thothbot.parallax.core.shared.objects.Mesh; +import thothbot.parallax.core.shared.scenes.Scene; +import thothbot.parallax.plugins.effects.shaders.ParallaxBarrierShader; + +public class ParallaxBarrier extends Effect { + + Matrix4 eyeRight = new Matrix4(); + Matrix4 eyeLeft = new Matrix4(); + double focalLength = 125; + double _aspect, _near, _far, _fov; + + PerspectiveCamera _cameraL = new PerspectiveCamera(); + PerspectiveCamera _cameraR = new PerspectiveCamera(); + + Scene _scene = new Scene(); + + PerspectiveCamera _camera = new PerspectiveCamera( 53, 1, 1, 10000 ); + + RenderTargetTexture _renderTargetL; + RenderTargetTexture _renderTargetR; + + private ShaderMaterial _material; + + public ParallaxBarrier(WebGLRenderer renderer, Scene scene) { + super(renderer, scene); + + _cameraL.setMatrixAutoUpdate(false); + _cameraR.setMatrixAutoUpdate(false); + + _camera.getPosition().setZ(2); + _scene.add( _camera ); + + + initRenderTargets(renderer.getAbsoluteWidth(), renderer.getAbsoluteHeight()); + + Mesh mesh = new Mesh( new PlaneBufferGeometry( 2, 2 ), _material ); + _scene.add( mesh ); + + } + + public void setSize( int width, int height ) { + + initRenderTargets(width, height); + + renderer.setSize( width, height ); + + } + + private void initRenderTargets(int width, int height ) + { + if ( _renderTargetL != null ) + _renderTargetL.deallocate(this.renderer.getGL()); + if ( _renderTargetR != null ) + _renderTargetR.deallocate(this.renderer.getGL()); + + _renderTargetL = new RenderTargetTexture( width, height ); + _renderTargetL.setMinFilter(TextureMinFilter.LINEAR); + _renderTargetL.setMagFilter(TextureMagFilter.NEAREST); + _renderTargetL.setFormat(PixelFormat.RGBA); + + _renderTargetR = new RenderTargetTexture( width, height ); + _renderTargetR.setMinFilter(TextureMinFilter.LINEAR); + _renderTargetR.setMagFilter(TextureMagFilter.NEAREST); + _renderTargetR.setFormat(PixelFormat.RGBA); + + _material = new ShaderMaterial(new ParallaxBarrierShader()); + _material.getShader().getUniforms().get( "mapLeft" ).setValue( _renderTargetL ); + _material.getShader().getUniforms().get( "mapRight").setValue( _renderTargetR ); + + } + + /** + * Renderer now uses an asymmetric perspective projection + * (http://paulbourke.net/miscellaneous/stereographics/stereorender/). + * + * Each camera is offset by the eye seperation and its projection matrix is + * also skewed asymetrically back to converge on the same projection plane. + * Added a focal length parameter to, this is where the parallax is equal to 0. + */ + @Override + public void render(Camera sceneCamera, List lights, int currentWidth, int currentHeight) + { + if(!(sceneCamera instanceof PerspectiveCamera)) + return; + + PerspectiveCamera camera = (PerspectiveCamera)sceneCamera; + + scene.updateMatrixWorld(false); + + if ( camera.getParent() == null ) + camera.updateMatrixWorld(false); + + boolean hasCameraChanged = ( _aspect != camera.getAspect() ) || ( _near != camera.getNear() ) || ( _far != camera.getFar() ) || ( _fov != camera.getFov() ); + + if ( hasCameraChanged ) + { + + _aspect = camera.getAspect(); + _near = camera.getNear(); + _far = camera.getFar(); + _fov = camera.getFov(); + + Matrix4 projectionMatrix = camera.getProjectionMatrix().clone(); + double eyeSep = focalLength / 30.0 * 0.5; + double eyeSepOnProjection = eyeSep * _near / focalLength; + double ymax = _near * Math.tan( Mathematics.degToRad( _fov * 0.5 ) ); + double xmin, xmax; + + // translate xOffset + + eyeRight.getArray().set(12, eyeSep); + eyeLeft.getArray().set(12, -eyeSep); + + // for left eye + + xmin = -ymax * _aspect + eyeSepOnProjection; + xmax = ymax * _aspect + eyeSepOnProjection; + + projectionMatrix.getArray().set(0, 2.0 * _near / ( xmax - xmin )); + projectionMatrix.getArray().set(8, ( xmax + xmin ) / ( xmax - xmin )); + + _cameraL.getProjectionMatrix().copy( projectionMatrix ); + + // for right eye + + xmin = -ymax * _aspect - eyeSepOnProjection; + xmax = ymax * _aspect - eyeSepOnProjection; + + projectionMatrix.getArray().set(0, 2.0 * _near / ( xmax - xmin )); + projectionMatrix.getArray().set(8, ( xmax + xmin ) / ( xmax - xmin )); + + _cameraR.getProjectionMatrix().copy( projectionMatrix ); + + } + + _cameraL.getMatrixWorld().copy( camera.getMatrixWorld() ).multiply( eyeLeft ); + _cameraL.getPosition().copy( camera.getPosition() ); + _cameraL.setNear( camera.getNear() ); + _cameraL.setFar( camera.getFar() ); + + renderer.render( scene, _cameraL, _renderTargetL, true ); + + _cameraR.getMatrixWorld().copy( camera.getMatrixWorld() ).multiply( eyeRight ); + _cameraR.getPosition().copy( camera.getPosition() ); + _cameraR.setNear( camera.getNear() ); + _cameraR.setFar( camera.getFar() ); + + renderer.render( scene, _cameraR, _renderTargetR, true ); + + _scene.updateMatrixWorld(false); + + renderer.render( _scene, _camera ); + + + } + +} diff --git a/src/thothbot/parallax/plugins/effects/shaders/ParallaxBarrierShader.java b/src/thothbot/parallax/plugins/effects/shaders/ParallaxBarrierShader.java new file mode 100644 index 00000000..45201bd7 --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/shaders/ParallaxBarrierShader.java @@ -0,0 +1,52 @@ +/* + * Copyright 2014 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.plugins.effects.shaders; + +import thothbot.parallax.core.client.shaders.Shader; +import thothbot.parallax.core.client.shaders.Uniform; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.resources.client.TextResource; + +public class ParallaxBarrierShader extends Shader +{ + + interface Resources extends DefaultResources + { + Resources INSTANCE = GWT.create(Resources.class); + + @Source("source/parallaxBarrier.vs") + TextResource getVertexShader(); + + @Source("source/parallaxBarrier.fs") + TextResource getFragmentShader(); + } + + public ParallaxBarrierShader() + { + super(Resources.INSTANCE); + } + + @Override + protected void initUniforms() + { + this.addUniform("mapLeft", new Uniform( Uniform.TYPE.T )); + this.addUniform("mapRight", new Uniform( Uniform.TYPE.T )); + } +} diff --git a/src/thothbot/parallax/plugins/effects/shaders/source/parallaxBarrier.fs b/src/thothbot/parallax/plugins/effects/shaders/source/parallaxBarrier.fs new file mode 100644 index 00000000..ad97046e --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/shaders/source/parallaxBarrier.fs @@ -0,0 +1,19 @@ +uniform sampler2D mapLeft; +uniform sampler2D mapRight; +varying vec2 vUv; + +void main() { + + vec2 uv = vUv; + + if ( ( mod( gl_FragCoord.y, 2.0 ) ) > 1.00 ) { + + gl_FragColor = texture2D( mapLeft, uv ); + + } else { + + gl_FragColor = texture2D( mapRight, uv ); + + } + +} diff --git a/src/thothbot/parallax/plugins/effects/shaders/source/parallaxBarrier.vs b/src/thothbot/parallax/plugins/effects/shaders/source/parallaxBarrier.vs new file mode 100644 index 00000000..887fa2ae --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/shaders/source/parallaxBarrier.vs @@ -0,0 +1,8 @@ +varying vec2 vUv; + +void main() { + + vUv = vec2( uv.x, uv.y ); + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + +} From daae5399abf9d7851022fc51dd9d41ec7a46b11f Mon Sep 17 00:00:00 2001 From: thothbot Date: Wed, 4 Feb 2015 14:12:28 +0300 Subject: [PATCH 17/75] Added basic render plugin type --- .../core/client/renderers/Plugin.java | 2 ++ .../core/client/renderers/WebGLRenderer.java | 35 ++++++++++++------- .../parallax/plugins/effects/Anaglyph.java | 1 - .../parallax/plugins/effects/Effect.java | 7 +--- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/Plugin.java b/src/thothbot/parallax/core/client/renderers/Plugin.java index 70516c8c..a86ef16f 100644 --- a/src/thothbot/parallax/core/client/renderers/Plugin.java +++ b/src/thothbot/parallax/core/client/renderers/Plugin.java @@ -20,6 +20,7 @@ import java.util.List; +import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.lights.Light; import thothbot.parallax.core.shared.scenes.Scene; @@ -27,6 +28,7 @@ public abstract class Plugin { public enum TYPE { + BASIC_RENDER, PRE_RENDER, POST_RENDER, }; diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index d5399457..f8b1cab8 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -72,7 +72,6 @@ import thothbot.parallax.core.client.textures.Texture; import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; -import thothbot.parallax.core.shared.cameras.PerspectiveCamera; import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.BufferAttribute; import thothbot.parallax.core.shared.core.BufferGeometry; @@ -114,7 +113,6 @@ import thothbot.parallax.core.shared.scenes.AbstractFog; import thothbot.parallax.core.shared.scenes.FogExp2; import thothbot.parallax.core.shared.scenes.Scene; -import thothbot.parallax.plugins.effects.Anaglyph; import com.google.gwt.canvas.dom.client.Context2d; import com.google.gwt.core.client.GWT; @@ -246,6 +244,8 @@ public final native double _devicePixelRatio() /*-{ private RendererLights _lights; + private List renderPluginsBasic; + // An array with render plugins to be applied before rendering. private List renderPluginsPre; @@ -364,6 +364,7 @@ public WebGLRenderer(WebGLRenderingContext gl, int width, int height) setDefaultGLState(); // default plugins (order is important) + this.renderPluginsBasic = new ArrayList(); this.renderPluginsPre = new ArrayList(); this.renderPluginsPost = new ArrayList(); } @@ -379,10 +380,9 @@ else if(plugin.getType() == Plugin.TYPE.POST_RENDER) { this.renderPluginsPost.add( plugin ); } - else + else if(plugin.getType() == Plugin.TYPE.BASIC_RENDER) { - Log.error("Unknown plugin type: " + plugin.getType()); - return; + this.renderPluginsBasic.add( plugin ); } } @@ -399,10 +399,9 @@ else if(plugin.getType() == Plugin.TYPE.POST_RENDER) { this.renderPluginsPost.remove( plugin ); } - else + else if(plugin.getType() == Plugin.TYPE.BASIC_RENDER) { - Log.error("Unknown plugin type: " + plugin.getType()); - return; + this.renderPluginsBasic.remove( plugin ); } } @@ -1811,7 +1810,11 @@ public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget * @param forceClear optional */ public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget, boolean forceClear ) - { + { + // Render basic plugins + if(renderPlugins( this.renderPluginsBasic, camera )) + return; + Log.debug("Called render()"); AbstractFog fog = scene.getFog(); @@ -2031,16 +2034,18 @@ public void renderImmediateObject( Camera camera, List lights, AbstractFo } - private void renderPlugins( List plugins, Camera camera ) - { - if ( plugins.size() == 0 ) return; + private boolean renderPlugins( List plugins, Camera camera ) + { + if ( plugins.size() == 0 ) + return false; + boolean retval = false; for ( int i = 0, il = plugins.size(); i < il; i ++ ) { Plugin plugin = plugins.get( i ); if( ! plugin.isEnabled() || plugin.isRendering() ) - return; + continue; plugin.setRendering(true); Log.debug("Called renderPlugins(): " + plugin.getClass().getName()); @@ -2077,7 +2082,11 @@ private void renderPlugins( List plugins, Camera camera ) this._lightsNeedUpdate = true; plugin.setRendering(false); + + retval = true; } + + return retval; } private void renderObjects (List renderList, Camera camera, List lights, AbstractFog fog, boolean useBlending ) diff --git a/src/thothbot/parallax/plugins/effects/Anaglyph.java b/src/thothbot/parallax/plugins/effects/Anaglyph.java index 6358b6b5..21cc49d6 100644 --- a/src/thothbot/parallax/plugins/effects/Anaglyph.java +++ b/src/thothbot/parallax/plugins/effects/Anaglyph.java @@ -25,7 +25,6 @@ import thothbot.parallax.core.client.gl2.enums.PixelFormat; import thothbot.parallax.core.client.gl2.enums.TextureMagFilter; import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; -import thothbot.parallax.core.client.renderers.Plugin; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.textures.RenderTargetTexture; import thothbot.parallax.core.shared.cameras.Camera; diff --git a/src/thothbot/parallax/plugins/effects/Effect.java b/src/thothbot/parallax/plugins/effects/Effect.java index e3e76d4c..b109bfd5 100644 --- a/src/thothbot/parallax/plugins/effects/Effect.java +++ b/src/thothbot/parallax/plugins/effects/Effect.java @@ -18,13 +18,8 @@ package thothbot.parallax.plugins.effects; -import java.util.List; - import thothbot.parallax.core.client.renderers.Plugin; -import thothbot.parallax.core.client.renderers.Plugin.TYPE; import thothbot.parallax.core.client.renderers.WebGLRenderer; -import thothbot.parallax.core.shared.cameras.Camera; -import thothbot.parallax.core.shared.lights.Light; import thothbot.parallax.core.shared.scenes.Scene; public abstract class Effect extends Plugin { @@ -35,6 +30,6 @@ public Effect(WebGLRenderer renderer, Scene scene) { @Override public TYPE getType() { - return Plugin.TYPE.POST_RENDER; + return Plugin.TYPE.BASIC_RENDER; } } From 415545ff0521f0b4398873877b7030bb95d44827 Mon Sep 17 00:00:00 2001 From: thothbot Date: Wed, 4 Feb 2015 17:09:45 +0300 Subject: [PATCH 18/75] Refactored plugin operations --- .../core/client/renderers/WebGLRenderer.java | 51 ++++--------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index f8b1cab8..573be129 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -244,13 +244,7 @@ public final native double _devicePixelRatio() /*-{ private RendererLights _lights; - private List renderPluginsBasic; - - // An array with render plugins to be applied before rendering. - private List renderPluginsPre; - - //An array with render plugins to be applied after rendering. - private List renderPluginsPost; + private List plugins; // var sprites = []; // var lensFlares = []; @@ -364,26 +358,13 @@ public WebGLRenderer(WebGLRenderingContext gl, int width, int height) setDefaultGLState(); // default plugins (order is important) - this.renderPluginsBasic = new ArrayList(); - this.renderPluginsPre = new ArrayList(); - this.renderPluginsPost = new ArrayList(); + this.plugins = new ArrayList(); } public void addPlugin(Plugin plugin) { deletePlugin(plugin); - if(plugin.getType() == Plugin.TYPE.PRE_RENDER) - { - this.renderPluginsPre.add( plugin ); - } - else if(plugin.getType() == Plugin.TYPE.POST_RENDER) - { - this.renderPluginsPost.add( plugin ); - } - else if(plugin.getType() == Plugin.TYPE.BASIC_RENDER) - { - this.renderPluginsBasic.add( plugin ); - } + this.plugins.add( plugin ); } public void deletePlugin(Plugin plugin) @@ -391,18 +372,7 @@ public void deletePlugin(Plugin plugin) if(plugin == null) return; - if(plugin.getType() == Plugin.TYPE.PRE_RENDER) - { - this.renderPluginsPre.remove( plugin ); - } - else if(plugin.getType() == Plugin.TYPE.POST_RENDER) - { - this.renderPluginsPost.remove( plugin ); - } - else if(plugin.getType() == Plugin.TYPE.BASIC_RENDER) - { - this.renderPluginsBasic.remove( plugin ); - } + this.plugins.remove( plugin ); } public boolean supportsVertexTextures() @@ -1812,7 +1782,7 @@ public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget, boolean forceClear ) { // Render basic plugins - if(renderPlugins( this.renderPluginsBasic, camera )) + if(renderPlugins( this.plugins, camera, Plugin.TYPE.BASIC_RENDER )) return; Log.debug("Called render()"); @@ -1890,7 +1860,7 @@ public int compare(WebGLObject a, WebGLObject b) { } // custom render plugins (pre pass) - renderPlugins( this.renderPluginsPre, camera ); + renderPlugins( this.plugins, camera, Plugin.TYPE.PRE_RENDER ); this.getInfo().getRender().calls = 0; this.getInfo().getRender().vertices = 0; @@ -1954,7 +1924,7 @@ public int compare(WebGLObject a, WebGLObject b) { } // custom render plugins (post pass) - renderPlugins( this.renderPluginsPost, camera ); + renderPlugins( this.plugins, camera, Plugin.TYPE.POST_RENDER ); // Generate mipmap if we're using any kind of mipmap filtering if ( renderTarget != null && renderTarget.isGenerateMipmaps() @@ -2034,7 +2004,7 @@ public void renderImmediateObject( Camera camera, List lights, AbstractFo } - private boolean renderPlugins( List plugins, Camera camera ) + private boolean renderPlugins( List plugins, Camera camera, Plugin.TYPE type ) { if ( plugins.size() == 0 ) return false; @@ -2044,7 +2014,7 @@ private boolean renderPlugins( List plugins, Camera camera ) { Plugin plugin = plugins.get( i ); - if( ! plugin.isEnabled() || plugin.isRendering() ) + if( ! plugin.isEnabled() || plugin.isRendering() || plugin.getType() != type ) continue; plugin.setRendering(true); @@ -2359,13 +2329,14 @@ private void initMaterial ( Material material, List lights, AbstractFog f parameters.maxShadows = maxShadows; - for(Plugin plugin: this.renderPluginsPre) + for(Plugin plugin: this.plugins) if(plugin instanceof ShadowMap && ((ShadowMap)plugin).isEnabled() && object.isReceiveShadow()) { parameters.shadowMapEnabled = object.isReceiveShadow() && maxShadows > 0; parameters.shadowMapSoft = ((ShadowMap)plugin).isSoft(); parameters.shadowMapDebug = ((ShadowMap)plugin).isDebugEnabled(); parameters.shadowMapCascade = ((ShadowMap)plugin).isCascade(); + break; } material.updateProgramParameters(parameters); From 3ac201dc2c7b9b2801666f9e83602d5e6d5042f0 Mon Sep 17 00:00:00 2001 From: thothbot Date: Wed, 4 Feb 2015 19:14:17 +0300 Subject: [PATCH 19/75] Added OculusRift effect --- .../core/client/renderers/Plugin.java | 4 + .../core/client/renderers/WebGLRenderer.java | 16 +- .../parallax/plugins/effects/Anaglyph.java | 16 +- .../parallax/plugins/effects/OculusRift.java | 246 ++++++++++++++++++ .../plugins/effects/ParallaxBarrier.java | 8 - .../effects/shaders/OculusRiftShader.java | 59 +++++ .../effects/shaders/source/oculusRift.fs | 26 ++ .../effects/shaders/source/oculusRift.vs | 5 + 8 files changed, 357 insertions(+), 23 deletions(-) create mode 100644 src/thothbot/parallax/plugins/effects/OculusRift.java create mode 100644 src/thothbot/parallax/plugins/effects/shaders/OculusRiftShader.java create mode 100644 src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.fs create mode 100644 src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.vs diff --git a/src/thothbot/parallax/core/client/renderers/Plugin.java b/src/thothbot/parallax/core/client/renderers/Plugin.java index a86ef16f..b38ca918 100644 --- a/src/thothbot/parallax/core/client/renderers/Plugin.java +++ b/src/thothbot/parallax/core/client/renderers/Plugin.java @@ -73,4 +73,8 @@ public void setRendering(boolean isRendering) { public abstract Plugin.TYPE getType(); public abstract void render( Camera camera, List lights, int currentWidth, int currentHeight ); + + public void deallocate() { + + } } diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index 573be129..e10386b0 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -372,9 +372,11 @@ public void deletePlugin(Plugin plugin) if(plugin == null) return; - this.plugins.remove( plugin ); + if(this.plugins.remove( plugin )) { + plugin.deallocate(); + } } - + public boolean supportsVertexTextures() { return this._maxVertexTextures > 0; @@ -660,11 +662,15 @@ public void enableScissorTest(boolean enable) else getGL().disable(EnableCap.SCISSOR_TEST); } - - + public void setClearColor( int hex ) { - setClearColor(new Color(hex), 1.0); + setClearColor(new Color(hex)); + } + + public void setClearColor( Color color ) + { + setClearColor(color, 1.0); } /** diff --git a/src/thothbot/parallax/plugins/effects/Anaglyph.java b/src/thothbot/parallax/plugins/effects/Anaglyph.java index 21cc49d6..a2223eda 100644 --- a/src/thothbot/parallax/plugins/effects/Anaglyph.java +++ b/src/thothbot/parallax/plugins/effects/Anaglyph.java @@ -81,15 +81,7 @@ public void onResize(ViewportResizeEvent event) { _scene.add( mesh ); } - - public void setSize( int width, int height ) { - - initRenderTargets(width, height); - - renderer.setSize( width, height ); - - } - + private void initRenderTargets(int width, int height ) { if ( _renderTargetL != null ) @@ -192,6 +184,10 @@ public void render( Camera sceneCamera, List lights, int currentWidth, in renderer.render( scene, _cameraR, _renderTargetR, true ); renderer.render( _scene, _camera ); - + } + + @Override + public void deallocate() { + super.deallocate(); } } diff --git a/src/thothbot/parallax/plugins/effects/OculusRift.java b/src/thothbot/parallax/plugins/effects/OculusRift.java new file mode 100644 index 00000000..c89a99df --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/OculusRift.java @@ -0,0 +1,246 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.plugins.effects; + +import java.util.List; + +import thothbot.parallax.core.client.events.ViewportResizeEvent; +import thothbot.parallax.core.client.events.ViewportResizeHandler; +import thothbot.parallax.core.client.gl2.enums.PixelFormat; +import thothbot.parallax.core.client.gl2.enums.TextureMagFilter; +import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; +import thothbot.parallax.core.client.renderers.WebGLRenderer; +import thothbot.parallax.core.client.textures.RenderTargetTexture; +import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.cameras.OrthographicCamera; +import thothbot.parallax.core.shared.cameras.PerspectiveCamera; +import thothbot.parallax.core.shared.geometries.PlaneBufferGeometry; +import thothbot.parallax.core.shared.lights.Light; +import thothbot.parallax.core.shared.materials.ShaderMaterial; +import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.core.shared.math.Mathematics; +import thothbot.parallax.core.shared.math.Matrix4; +import thothbot.parallax.core.shared.math.Vector2; +import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.math.Vector4; +import thothbot.parallax.core.shared.objects.Mesh; +import thothbot.parallax.core.shared.scenes.Scene; +import thothbot.parallax.plugins.effects.shaders.OculusRiftShader; + +public class OculusRift extends Effect { + + private static class HMD { + // DK1 + /* + hResolution: 1280, + vResolution: 800, + hScreenSize: 0.14976, + vScreenSize: 0.0936, + interpupillaryDistance: 0.064, + lensSeparationDistance: 0.064, + eyeToScreenDistance: 0.041, + distortionK : [1.0, 0.22, 0.24, 0.0], + chromaAbParameter: [ 0.996, -0.004, 1.014, 0.0] + */ + // DK2 + public int hResolution = 1920; + public int vResolution = 1080; + public double hScreenSize = 0.12576; + public double vScreenSize = 0.07074; + public double interpupillaryDistance = 0.0635; + public double lensSeparationDistance = 0.0635; + public double eyeToScreenDistance = 0.041; + public double[] distortionK = new double[]{1.0, 0.22, 0.24, 0.0}; + public double[] chromaAbParameter = new double[]{ 0.996, -0.004, 1.014, 0.0}; + }; + + public static class Params { + public Matrix4 proj; + public Matrix4 tranform; + public int[] viewport; + public Vector2 lensCenter; + }; + + // worldFactor indicates how many units is 1 meter + private double worldFactor = 1.0; + private OculusRift.HMD hdm; + + // Perspective camera + PerspectiveCamera pCamera = new PerspectiveCamera(); + Vector3 target = new Vector3(); + + // Orthographic camera + OrthographicCamera oCamera = new OrthographicCamera( 2, 2, 1, 1000 ); + + Color emptyColor = new Color(0x000000); + + // Render target + RenderTargetTexture renderTarget; + ShaderMaterial RTMaterial; + + // Final scene + Scene finalScene = new Scene(); + + double distScale = 1.0; + + Params left = new Params(), right = new Params(); + + public OculusRift(WebGLRenderer renderer, Scene scene) { + super(renderer, scene); + + renderer.setAutoClear(false); + + pCamera.setMatrixAutoUpdate(false); + + oCamera.getPosition().setZ( 1 ); + + oCamera.addViewportResizeHandler(new ViewportResizeHandler() { + + @Override + public void onResize(ViewportResizeEvent event) { + + oCamera.setSize( 2, 2 ); + + } + }); + + RTMaterial = new ShaderMaterial(new OculusRiftShader()); + + Mesh mesh = new Mesh( new PlaneBufferGeometry( 2, 2 ), RTMaterial ); + + finalScene.add( oCamera ); + finalScene.add( mesh ); + + setHMD(new OculusRift.HMD()); + } + + private void initRenderTargets(int width, int height ) + { + if ( renderTarget != null ) + renderTarget.deallocate(this.renderer.getGL()); + + renderTarget = new RenderTargetTexture( width, height ); + renderTarget.setMinFilter(TextureMinFilter.LINEAR); + renderTarget.setMagFilter(TextureMagFilter.NEAREST); + renderTarget.setFormat(PixelFormat.RGBA); + + RTMaterial.getShader().getUniforms().get( "texid" ).setValue( renderTarget ); + } + + public OculusRift.HMD getHDM() { + return this.hdm; + } + + public void setHMD(OculusRift.HMD hdm) { + + this.hdm = hdm; + + // Compute aspect ratio and FOV + double aspect = hdm.hResolution / (2*hdm.vResolution); + + // Fov is normally computed with: + // THREE.Math.radToDeg( 2*Math.atan2(HMD.vScreenSize,2*HMD.eyeToScreenDistance) ); + // But with lens distortion it is increased (see Oculus SDK Documentation) + double r = -1.0 - (4.0 * (hdm.hScreenSize/4.0 - hdm.lensSeparationDistance/2.0) / hdm.hScreenSize); + distScale = (hdm.distortionK[0] + hdm.distortionK[1] * Math.pow(r,2) + hdm.distortionK[2] * Math.pow(r,4) + hdm.distortionK[3] * Math.pow(r,6)); + double fov = Mathematics.radToDeg(2.0 * Math.atan2(hdm.vScreenSize * distScale, 2.0 * hdm.eyeToScreenDistance)); + + // Compute camera projection matrices + Matrix4 proj = (new Matrix4()).makePerspective( fov, aspect, 0.3, 10000 ); + double h = 4.0 * (hdm.hScreenSize/4.0 - hdm.interpupillaryDistance/2.0) / hdm.hScreenSize; + left.proj = ((new Matrix4()).makeTranslation( h, 0.0, 0.0 )).multiply(proj); + right.proj = ((new Matrix4()).makeTranslation( -h, 0.0, 0.0 )).multiply(proj); + + // Compute camera transformation matrices + left.tranform = (new Matrix4()).makeTranslation( -worldFactor * hdm.interpupillaryDistance/2.0, 0.0, 0.0 ); + right.tranform = (new Matrix4()).makeTranslation( worldFactor * hdm.interpupillaryDistance/2.0, 0.0, 0.0 ); + + // Compute Viewport + left.viewport = new int[]{0, 0, hdm.hResolution/2, hdm.vResolution}; + right.viewport = new int[]{hdm.hResolution/2, 0, hdm.hResolution/2, hdm.vResolution}; + + // Distortion shader parameters + double lensShift = 4.0 * (hdm.hScreenSize/4.0 - hdm.lensSeparationDistance/2.0) / hdm.hScreenSize; + left.lensCenter = new Vector2(lensShift, 0.0); + right.lensCenter = new Vector2(-lensShift, 0.0); + + RTMaterial.getShader().getUniforms().get( "hmdWarpParam" ).setValue( new Vector4(hdm.distortionK[0], hdm.distortionK[1], hdm.distortionK[2], hdm.distortionK[3]) ); + RTMaterial.getShader().getUniforms().get( "chromAbParam" ).setValue( new Vector4(hdm.chromaAbParameter[0], hdm.chromaAbParameter[1], hdm.chromaAbParameter[2], hdm.chromaAbParameter[3]) ); + RTMaterial.getShader().getUniforms().get( "scaleIn" ).setValue( new Vector2(1.0,1.0/aspect) ); + RTMaterial.getShader().getUniforms().get( "scale" ).setValue( new Vector2(1.0/distScale, 1.0*aspect/distScale) ); + + // Create render target + initRenderTargets((int)(hdm.hResolution * distScale / 2.0), (int)(hdm.vResolution * distScale)); + } + + @Override + public void render(Camera sceneCamera, List lights, int currentWidth, int currentHeight) + { + + if(!(sceneCamera instanceof PerspectiveCamera)) + return; + + PerspectiveCamera camera = (PerspectiveCamera)sceneCamera; + + if ( camera.getParent() == null ) + camera.updateMatrixWorld(false); + + Color cc = renderer.getClearColor().clone(); + + // Clear + renderer.setClearColor(emptyColor); + renderer.clear(); + renderer.setClearColor(cc); + + // camera parameters + if (camera.isMatrixAutoUpdate()) + camera.updateMatrix(); + + // Render left + + pCamera.getProjectionMatrix().copy(left.proj); + + pCamera.getMatrix().copy(camera.getMatrix()).multiply(left.tranform); + pCamera.setMatrixWorldNeedsUpdate(true); + + renderer.setViewport(left.viewport[0], left.viewport[1], left.viewport[2], left.viewport[3]); + + RTMaterial.getShader().getUniforms().get( "lensCenter" ).setValue(left.lensCenter); + renderer.render( scene, pCamera, renderTarget, true ); + + renderer.render( finalScene, oCamera ); + + // Render right + + pCamera.getProjectionMatrix().copy(right.proj); + + pCamera.getMatrix().copy(camera.getMatrix()).multiply(right.tranform); + pCamera.setMatrixWorldNeedsUpdate(true); + + renderer.setViewport(right.viewport[0], right.viewport[1], right.viewport[2], right.viewport[3]); + + RTMaterial.getShader().getUniforms().get( "lensCenter" ).setValue(right.lensCenter); + + renderer.render( scene, pCamera, renderTarget, true ); + renderer.render( finalScene, oCamera ); + + + } + +} diff --git a/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java b/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java index 930c8e94..3a57ff60 100644 --- a/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java +++ b/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java @@ -71,15 +71,7 @@ public ParallaxBarrier(WebGLRenderer renderer, Scene scene) { _scene.add( mesh ); } - - public void setSize( int width, int height ) { - - initRenderTargets(width, height); - renderer.setSize( width, height ); - - } - private void initRenderTargets(int width, int height ) { if ( _renderTargetL != null ) diff --git a/src/thothbot/parallax/plugins/effects/shaders/OculusRiftShader.java b/src/thothbot/parallax/plugins/effects/shaders/OculusRiftShader.java new file mode 100644 index 00000000..c6f13cc7 --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/shaders/OculusRiftShader.java @@ -0,0 +1,59 @@ +/* + * Copyright 2014 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.plugins.effects.shaders; + +import thothbot.parallax.core.client.shaders.Shader; +import thothbot.parallax.core.client.shaders.Uniform; +import thothbot.parallax.core.shared.math.Vector2; +import thothbot.parallax.core.shared.math.Vector4; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.resources.client.TextResource; + +public class OculusRiftShader extends Shader +{ + + interface Resources extends DefaultResources + { + Resources INSTANCE = GWT.create(Resources.class); + + @Source("source/oculusRift.vs") + TextResource getVertexShader(); + + @Source("source/oculusRift.fs") + TextResource getFragmentShader(); + } + + public OculusRiftShader() + { + super(Resources.INSTANCE); + } + + @Override + protected void initUniforms() + { + this.addUniform("texid", new Uniform( Uniform.TYPE.T )); + this.addUniform("scale", new Uniform( Uniform.TYPE.V2, new Vector2(1.0,1.0) )); + this.addUniform("scaleIn", new Uniform( Uniform.TYPE.V2, new Vector2(1.0,1.0) )); + this.addUniform("lensCenter", new Uniform( Uniform.TYPE.V2, new Vector2(0.0,0.0) )); + this.addUniform("hmdWarpParam", new Uniform( Uniform.TYPE.V4, new Vector4(1.0,0.0,0.0,0.0) )); + this.addUniform("chromAbParam", new Uniform( Uniform.TYPE.V4, new Vector4(1.0,0.0,0.0,0.0) )); + } +} + diff --git a/src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.fs b/src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.fs new file mode 100644 index 00000000..a23ef83a --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.fs @@ -0,0 +1,26 @@ +uniform vec2 scale; +uniform vec2 scaleIn; +uniform vec2 lensCenter; +uniform vec4 hmdWarpParam; +uniform vec4 chromAbParam; +uniform sampler2D texid; +varying vec2 vUv; +void main() +{ + vec2 uv = (vUv*2.0)-1.0; // range from [0,1] to [-1,1] + vec2 theta = (uv-lensCenter)*scaleIn; + float rSq = theta.x*theta.x + theta.y*theta.y; + vec2 rvector = theta*(hmdWarpParam.x + hmdWarpParam.y*rSq + hmdWarpParam.z*rSq*rSq + hmdWarpParam.w*rSq*rSq*rSq); + ' vec2 rBlue = rvector * (chromAbParam.z + chromAbParam.w * rSq);', + vec2 tcBlue = (lensCenter + scale * rBlue); + tcBlue = (tcBlue+1.0)/2.0; // range from [-1,1] to [0,1] + if (any(bvec2(clamp(tcBlue, vec2(0.0,0.0), vec2(1.0,1.0))-tcBlue))) { + gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); + return;} + vec2 tcGreen = lensCenter + scale * rvector; + tcGreen = (tcGreen+1.0)/2.0; // range from [-1,1] to [0,1] + vec2 rRed = rvector * (chromAbParam.x + chromAbParam.y * rSq); + vec2 tcRed = lensCenter + scale * rRed; + tcRed = (tcRed+1.0)/2.0; // range from [-1,1] to [0,1] + gl_FragColor = vec4(texture2D(texid, tcRed).r, texture2D(texid, tcGreen).g, texture2D(texid, tcBlue).b, 1); +} diff --git a/src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.vs b/src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.vs new file mode 100644 index 00000000..13854c18 --- /dev/null +++ b/src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.vs @@ -0,0 +1,5 @@ +varying vec2 vUv; +void main() { + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); +} From 06a95364803656054c52d3a75be039e12cb15fea Mon Sep 17 00:00:00 2001 From: thothbot Date: Thu, 5 Feb 2015 02:09:36 +0300 Subject: [PATCH 20/75] Fixed few issues in OculusRift shader --- .../parallax/plugins/effects/OculusRift.java | 20 +++++++++++-------- .../effects/shaders/source/oculusRift.fs | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/thothbot/parallax/plugins/effects/OculusRift.java b/src/thothbot/parallax/plugins/effects/OculusRift.java index c89a99df..5f90e09b 100644 --- a/src/thothbot/parallax/plugins/effects/OculusRift.java +++ b/src/thothbot/parallax/plugins/effects/OculusRift.java @@ -27,6 +27,7 @@ import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.textures.RenderTargetTexture; +import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.OrthographicCamera; import thothbot.parallax.core.shared.cameras.PerspectiveCamera; @@ -78,7 +79,7 @@ public static class Params { }; // worldFactor indicates how many units is 1 meter - private double worldFactor = 1.0; + private double worldFactor = 100.0; private OculusRift.HMD hdm; // Perspective camera @@ -121,13 +122,12 @@ public void onResize(ViewportResizeEvent event) { }); RTMaterial = new ShaderMaterial(new OculusRiftShader()); - + setHMD(new OculusRift.HMD()); + Mesh mesh = new Mesh( new PlaneBufferGeometry( 2, 2 ), RTMaterial ); finalScene.add( oCamera ); - finalScene.add( mesh ); - - setHMD(new OculusRift.HMD()); + finalScene.add( mesh ); } private void initRenderTargets(int width, int height ) @@ -172,8 +172,13 @@ public void setHMD(OculusRift.HMD hdm) { right.tranform = (new Matrix4()).makeTranslation( worldFactor * hdm.interpupillaryDistance/2.0, 0.0, 0.0 ); // Compute Viewport - left.viewport = new int[]{0, 0, hdm.hResolution/2, hdm.vResolution}; - right.viewport = new int[]{hdm.hResolution/2, 0, hdm.hResolution/2, hdm.vResolution}; +// left.viewport = new int[]{0, 0, hdm.hResolution/2, hdm.vResolution}; +// right.viewport = new int[]{hdm.hResolution/2, 0, hdm.hResolution/2, hdm.vResolution}; + + int width = renderer.getAbsoluteWidth(); + int height = renderer.getAbsoluteHeight(); + left.viewport = new int[]{width/2 - hdm.hResolution/2, height/2 - hdm.vResolution/2, hdm.hResolution/2, hdm.vResolution}; + right.viewport = new int[]{width/2, height/2 - hdm.vResolution/2, hdm.hResolution/2, hdm.vResolution}; // Distortion shader parameters double lensShift = 4.0 * (hdm.hScreenSize/4.0 - hdm.lensSeparationDistance/2.0) / hdm.hScreenSize; @@ -192,7 +197,6 @@ public void setHMD(OculusRift.HMD hdm) { @Override public void render(Camera sceneCamera, List lights, int currentWidth, int currentHeight) { - if(!(sceneCamera instanceof PerspectiveCamera)) return; diff --git a/src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.fs b/src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.fs index a23ef83a..f0f3676d 100644 --- a/src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.fs +++ b/src/thothbot/parallax/plugins/effects/shaders/source/oculusRift.fs @@ -11,7 +11,7 @@ void main() vec2 theta = (uv-lensCenter)*scaleIn; float rSq = theta.x*theta.x + theta.y*theta.y; vec2 rvector = theta*(hmdWarpParam.x + hmdWarpParam.y*rSq + hmdWarpParam.z*rSq*rSq + hmdWarpParam.w*rSq*rSq*rSq); - ' vec2 rBlue = rvector * (chromAbParam.z + chromAbParam.w * rSq);', + vec2 rBlue = rvector * (chromAbParam.z + chromAbParam.w * rSq); vec2 tcBlue = (lensCenter + scale * rBlue); tcBlue = (tcBlue+1.0)/2.0; // range from [-1,1] to [0,1] if (any(bvec2(clamp(tcBlue, vec2(0.0,0.0), vec2(1.0,1.0))-tcBlue))) { From 58eabc418f05ad30ef79849c4e342080ad571f52 Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 6 Feb 2015 18:32:52 +0300 Subject: [PATCH 21/75] Added deallocation for effects --- .../core/client/renderers/Plugin.java | 3 +-- .../core/client/renderers/WebGLRenderer.java | 21 +++++++++---------- .../parallax/plugins/effects/Anaglyph.java | 8 ++++++- .../parallax/plugins/effects/OculusRift.java | 17 ++++++++++++++- .../plugins/effects/ParallaxBarrier.java | 10 +++++++++ .../parallax/plugins/effects/Stereo.java | 16 ++++++++++++++ 6 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/Plugin.java b/src/thothbot/parallax/core/client/renderers/Plugin.java index b38ca918..17ad2a39 100644 --- a/src/thothbot/parallax/core/client/renderers/Plugin.java +++ b/src/thothbot/parallax/core/client/renderers/Plugin.java @@ -20,7 +20,6 @@ import java.util.List; -import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.lights.Light; import thothbot.parallax.core.shared.scenes.Scene; @@ -73,7 +72,7 @@ public void setRendering(boolean isRendering) { public abstract Plugin.TYPE getType(); public abstract void render( Camera camera, List lights, int currentWidth, int currentHeight ); - + public void deallocate() { } diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index e10386b0..c5e89513 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -1897,10 +1897,13 @@ public int compare(WebGLObject a, WebGLObject b) { } + Log.debug(" -- render() overrideMaterial : " + (scene.overrideMaterial != null) + + ", lights: " + lights.size() + + ", opaqueObjects: " + opaqueObjects.size() + + ", transparentObjects: " + transparentObjects.size() ); + if ( scene.overrideMaterial != null ) - { - Log.debug("render(): override material"); - + { Material material = scene.overrideMaterial; this.setBlending( material.getBlending(), material.getBlendEquation(), material.getBlendSrc(), material.getBlendDst() ); @@ -1913,9 +1916,7 @@ public int compare(WebGLObject a, WebGLObject b) { renderObjectsImmediate( _webglObjectsImmediate, null, camera, lights, fog, false, material ); } else - { - Log.debug("render(): NON override material"); - + { Material material = null; // opaque pass (front-to-back order) @@ -2072,9 +2073,7 @@ private void renderObjects (List renderList, Camera camera, List

  • renderList, Camera camera, List lights, AbstractFog fog, boolean useBlending, Material overrideMaterial ) - { - Log.debug("Called renderObjects() render list contains = " + renderList.size()); - + { Material material = null; for ( int i = renderList.size() - 1; i != - 1; i -- ) { @@ -2289,7 +2288,7 @@ else if ( object instanceof Mesh && ((Mesh)object).morphTargetBase != null ) disableUnusedAttributes(); - Log.debug(" -> renderBuffer() ID " + object.getId() + " = " + object.getClass().getName()); + Log.debug(" ----> renderBuffer() ID " + object.getId() + " (" + object.getClass().getSimpleName() + ")"); // Render object's buffers object.renderBuffer(this, geometry, updateBuffers); @@ -3105,7 +3104,7 @@ private void setCubeTexture ( CubeTexture texture, int slot ) */ public void setRenderTarget( RenderTargetTexture renderTarget ) { - Log.debug("Called setRenderTarget(params)"); + Log.debug(" ----> Called setRenderTarget(params)"); WebGLFramebuffer framebuffer = null; int width, height; diff --git a/src/thothbot/parallax/plugins/effects/Anaglyph.java b/src/thothbot/parallax/plugins/effects/Anaglyph.java index a2223eda..a718b112 100644 --- a/src/thothbot/parallax/plugins/effects/Anaglyph.java +++ b/src/thothbot/parallax/plugins/effects/Anaglyph.java @@ -27,6 +27,7 @@ import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.textures.RenderTargetTexture; +import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.OrthographicCamera; import thothbot.parallax.core.shared.cameras.PerspectiveCamera; @@ -74,7 +75,7 @@ public void onResize(ViewportResizeEvent event) { } }); - + initRenderTargets(renderer.getAbsoluteWidth(), renderer.getAbsoluteHeight()); Mesh mesh = new Mesh( new PlaneBufferGeometry( 2, 2 ), _material ); @@ -189,5 +190,10 @@ public void render( Camera sceneCamera, List lights, int currentWidth, in @Override public void deallocate() { super.deallocate(); + + _renderTargetL.deallocate(this.renderer.getGL()); + _renderTargetR.deallocate(this.renderer.getGL()); + + _material.deallocate(renderer); } } diff --git a/src/thothbot/parallax/plugins/effects/OculusRift.java b/src/thothbot/parallax/plugins/effects/OculusRift.java index 5f90e09b..8942084e 100644 --- a/src/thothbot/parallax/plugins/effects/OculusRift.java +++ b/src/thothbot/parallax/plugins/effects/OculusRift.java @@ -27,7 +27,6 @@ import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.textures.RenderTargetTexture; -import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.OrthographicCamera; import thothbot.parallax.core.shared.cameras.PerspectiveCamera; @@ -101,10 +100,13 @@ public static class Params { double distScale = 1.0; Params left = new Params(), right = new Params(); + + boolean _oldAutoClear; public OculusRift(WebGLRenderer renderer, Scene scene) { super(renderer, scene); + _oldAutoClear = renderer.isAutoClear(); renderer.setAutoClear(false); pCamera.setMatrixAutoUpdate(false); @@ -246,5 +248,18 @@ public void render(Camera sceneCamera, List lights, int currentWidth, int } + + @Override + public void deallocate() { + super.deallocate(); + + int _width = renderer.getAbsoluteWidth(); + int _height = renderer.getAbsoluteHeight(); + + renderer.setScissor( 0, 0, _width, _height ); + renderer.setViewport( 0, 0, _width, _height ); + + renderer.setAutoClear(_oldAutoClear); + } } diff --git a/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java b/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java index 3a57ff60..5eca845b 100644 --- a/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java +++ b/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java @@ -179,5 +179,15 @@ public void render(Camera sceneCamera, List lights, int currentWidth, int } + + @Override + public void deallocate() { + super.deallocate(); + + _renderTargetL.deallocate(this.renderer.getGL()); + _renderTargetR.deallocate(this.renderer.getGL()); + + _material.deallocate(renderer); + } } diff --git a/src/thothbot/parallax/plugins/effects/Stereo.java b/src/thothbot/parallax/plugins/effects/Stereo.java index 079b6253..06d360fe 100644 --- a/src/thothbot/parallax/plugins/effects/Stereo.java +++ b/src/thothbot/parallax/plugins/effects/Stereo.java @@ -48,10 +48,13 @@ public class Stereo extends Effect { double _outer, _inner, _top, _bottom; double _ndfl, _halfFocalWidth, _halfFocalHeight; double _innerFactor, _outerFactor; + + boolean _oldAutoClear; public Stereo(WebGLRenderer renderer, Scene scene) { super(renderer, scene); + _oldAutoClear = renderer.isAutoClear(); renderer.setAutoClear(false); } @@ -135,5 +138,18 @@ public void render(Camera sceneCamera, List lights, int currentWidth, int renderer.enableScissorTest( false ); } + + @Override + public void deallocate() { + super.deallocate(); + + int _width = renderer.getAbsoluteWidth(); + int _height = renderer.getAbsoluteHeight(); + + renderer.setScissor( 0, 0, _width, _height ); + renderer.setViewport( 0, 0, _width, _height ); + + renderer.setAutoClear(_oldAutoClear); + } } From c019ddd29745f3289d34b7fa33f53b6457fe236a Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 6 Feb 2015 23:52:27 +0300 Subject: [PATCH 22/75] Added resize handler for effects --- .../core/client/renderers/WebGLRenderer.java | 21 ++++++-- .../parallax/plugins/effects/Anaglyph.java | 11 +++- .../parallax/plugins/effects/Effect.java | 17 +++++- .../parallax/plugins/effects/OculusRift.java | 54 ++++++++++++------- .../plugins/effects/ParallaxBarrier.java | 13 ++++- .../parallax/plugins/effects/Stereo.java | 7 +++ 6 files changed, 95 insertions(+), 28 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index c5e89513..365a95cb 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -219,6 +219,8 @@ public final native double _devicePixelRatio() /*-{ private int absoluteWidth = 0; private int absoluteHeight = 0; + private int _viewportX = 0; + private int _viewportY = 0; private int _viewportWidth = 0; private int _viewportHeight = 0; private int _currentWidth = 0; @@ -596,6 +598,9 @@ private void setDefaultGLState () getGL().enable( EnableCap.BLEND ); getGL().blendEquation( BlendEquationMode.FUNC_ADD ); getGL().blendFunc( BlendingFactorSrc.SRC_ALPHA, BlendingFactorDest.ONE_MINUS_SRC_ALPHA ); + + getGL().viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight ); + getGL().clearColor( _clearColor.getR(), _clearColor.getG(), _clearColor.getB(), _clearAlpha ); } /** @@ -624,10 +629,13 @@ public void setSize(int width, int height) */ public void setViewport(int x, int y, int width, int height) { + this._viewportX = x; + this._viewportY = y; + this._viewportWidth = width; this._viewportHeight = height; - getGL().viewport(x, y, this._viewportWidth, this._viewportHeight); + getGL().viewport(this._viewportX, this._viewportY, this._viewportWidth, this._viewportHeight); } public int getAbsoluteWidth() { @@ -3107,7 +3115,7 @@ public void setRenderTarget( RenderTargetTexture renderTarget ) Log.debug(" ----> Called setRenderTarget(params)"); WebGLFramebuffer framebuffer = null; - int width, height; + int width, height, vx, vy; if(renderTarget != null) { @@ -3116,18 +3124,25 @@ public void setRenderTarget( RenderTargetTexture renderTarget ) width = renderTarget.getWidth(); height = renderTarget.getHeight(); + + vx = 0; + vy = 0; } else { width = this._viewportWidth; height = this._viewportHeight; + + vx = _viewportX; + vy = _viewportY; + } if ( framebuffer != this._currentFramebuffer ) { getGL().bindFramebuffer( framebuffer ); - getGL().viewport( 0, 0, width, height); + getGL().viewport( vx, vy, width, height); this._currentFramebuffer = framebuffer; } diff --git a/src/thothbot/parallax/plugins/effects/Anaglyph.java b/src/thothbot/parallax/plugins/effects/Anaglyph.java index a718b112..3cf63970 100644 --- a/src/thothbot/parallax/plugins/effects/Anaglyph.java +++ b/src/thothbot/parallax/plugins/effects/Anaglyph.java @@ -76,11 +76,20 @@ public void onResize(ViewportResizeEvent event) { } }); + _material = new ShaderMaterial(new AnaglyphShader()); initRenderTargets(renderer.getAbsoluteWidth(), renderer.getAbsoluteHeight()); Mesh mesh = new Mesh( new PlaneBufferGeometry( 2, 2 ), _material ); _scene.add( mesh ); + } + + @Override + public void onResize(ViewportResizeEvent event) + { + int width = event.getRenderer().getAbsoluteWidth(); + int height = event.getRenderer().getAbsoluteHeight(); + initRenderTargets(width, height); } private void initRenderTargets(int width, int height ) @@ -100,10 +109,8 @@ private void initRenderTargets(int width, int height ) _renderTargetR.setMagFilter(TextureMagFilter.NEAREST); _renderTargetR.setFormat(PixelFormat.RGBA); - _material = new ShaderMaterial(new AnaglyphShader()); _material.getShader().getUniforms().get( "mapLeft" ).setValue( _renderTargetL ); _material.getShader().getUniforms().get( "mapRight").setValue( _renderTargetR ); - } /* diff --git a/src/thothbot/parallax/plugins/effects/Effect.java b/src/thothbot/parallax/plugins/effects/Effect.java index b109bfd5..4165a087 100644 --- a/src/thothbot/parallax/plugins/effects/Effect.java +++ b/src/thothbot/parallax/plugins/effects/Effect.java @@ -18,18 +18,33 @@ package thothbot.parallax.plugins.effects; +import com.google.gwt.event.shared.HandlerRegistration; + +import thothbot.parallax.core.client.events.HasEventBus; +import thothbot.parallax.core.client.events.ViewportResizeEvent; +import thothbot.parallax.core.client.events.ViewportResizeHandler; import thothbot.parallax.core.client.renderers.Plugin; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.shared.scenes.Scene; -public abstract class Effect extends Plugin { +public abstract class Effect extends Plugin implements HasEventBus, ViewportResizeHandler { public Effect(WebGLRenderer renderer, Scene scene) { super(renderer, scene); + + addViewportResizeHandler(this); } @Override public TYPE getType() { return Plugin.TYPE.BASIC_RENDER; } + + public HandlerRegistration addViewportResizeHandler(ViewportResizeHandler handler) + { + return EVENT_BUS.addHandler(ViewportResizeEvent.TYPE, handler); + } + + @Override + public abstract void onResize(ViewportResizeEvent event); } diff --git a/src/thothbot/parallax/plugins/effects/OculusRift.java b/src/thothbot/parallax/plugins/effects/OculusRift.java index 8942084e..22ee1e8c 100644 --- a/src/thothbot/parallax/plugins/effects/OculusRift.java +++ b/src/thothbot/parallax/plugins/effects/OculusRift.java @@ -27,6 +27,7 @@ import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.textures.RenderTargetTexture; +import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.OrthographicCamera; import thothbot.parallax.core.shared.cameras.PerspectiveCamera; @@ -47,17 +48,17 @@ public class OculusRift extends Effect { private static class HMD { // DK1 - /* - hResolution: 1280, - vResolution: 800, - hScreenSize: 0.14976, - vScreenSize: 0.0936, - interpupillaryDistance: 0.064, - lensSeparationDistance: 0.064, - eyeToScreenDistance: 0.041, - distortionK : [1.0, 0.22, 0.24, 0.0], - chromaAbParameter: [ 0.996, -0.004, 1.014, 0.0] - */ + +// public int hResolution = 1280; +// public int vResolution = 800; +// hScreenSize: 0.14976, +// vScreenSize: 0.0936, +// interpupillaryDistance: 0.064, +// lensSeparationDistance: 0.064, +// eyeToScreenDistance: 0.041, +// distortionK : [1.0, 0.22, 0.24, 0.0], +// chromaAbParameter: [ 0.996, -0.004, 1.014, 0.0] + // DK2 public int hResolution = 1920; public int vResolution = 1080; @@ -78,7 +79,7 @@ public static class Params { }; // worldFactor indicates how many units is 1 meter - private double worldFactor = 100.0; + private double worldFactor = 1.0; private OculusRift.HMD hdm; // Perspective camera @@ -132,6 +133,18 @@ public void onResize(ViewportResizeEvent event) { finalScene.add( mesh ); } + @Override + public void onResize(ViewportResizeEvent event) + { + int width = event.getRenderer().getAbsoluteWidth(); + int height = event.getRenderer().getAbsoluteHeight(); + + left.viewport = new int[]{width/2 - hdm.hResolution/2, height/2 - hdm.vResolution/2, hdm.hResolution/2, hdm.vResolution}; + right.viewport = new int[]{width/2, height/2 - hdm.vResolution/2, hdm.hResolution/2, hdm.vResolution}; + + initRenderTargets(width, height); + } + private void initRenderTargets(int width, int height ) { if ( renderTarget != null ) @@ -154,7 +167,7 @@ public void setHMD(OculusRift.HMD hdm) { this.hdm = hdm; // Compute aspect ratio and FOV - double aspect = hdm.hResolution / (2*hdm.vResolution); + double aspect = (double)hdm.hResolution / (double)(2.0 * hdm.vResolution); // Fov is normally computed with: // THREE.Math.radToDeg( 2*Math.atan2(HMD.vScreenSize,2*HMD.eyeToScreenDistance) ); @@ -176,7 +189,7 @@ public void setHMD(OculusRift.HMD hdm) { // Compute Viewport // left.viewport = new int[]{0, 0, hdm.hResolution/2, hdm.vResolution}; // right.viewport = new int[]{hdm.hResolution/2, 0, hdm.hResolution/2, hdm.vResolution}; - + int width = renderer.getAbsoluteWidth(); int height = renderer.getAbsoluteHeight(); left.viewport = new int[]{width/2 - hdm.hResolution/2, height/2 - hdm.vResolution/2, hdm.hResolution/2, hdm.vResolution}; @@ -187,13 +200,13 @@ public void setHMD(OculusRift.HMD hdm) { left.lensCenter = new Vector2(lensShift, 0.0); right.lensCenter = new Vector2(-lensShift, 0.0); + // Create render target + initRenderTargets((int)(hdm.hResolution * distScale / 2.0), (int)(hdm.vResolution * distScale)); + RTMaterial.getShader().getUniforms().get( "hmdWarpParam" ).setValue( new Vector4(hdm.distortionK[0], hdm.distortionK[1], hdm.distortionK[2], hdm.distortionK[3]) ); RTMaterial.getShader().getUniforms().get( "chromAbParam" ).setValue( new Vector4(hdm.chromaAbParameter[0], hdm.chromaAbParameter[1], hdm.chromaAbParameter[2], hdm.chromaAbParameter[3]) ); RTMaterial.getShader().getUniforms().get( "scaleIn" ).setValue( new Vector2(1.0,1.0/aspect) ); RTMaterial.getShader().getUniforms().get( "scale" ).setValue( new Vector2(1.0/distScale, 1.0*aspect/distScale) ); - - // Create render target - initRenderTargets((int)(hdm.hResolution * distScale / 2.0), (int)(hdm.vResolution * distScale)); } @Override @@ -245,8 +258,6 @@ public void render(Camera sceneCamera, List lights, int currentWidth, int renderer.render( scene, pCamera, renderTarget, true ); renderer.render( finalScene, oCamera ); - - } @Override @@ -260,6 +271,9 @@ public void deallocate() { renderer.setViewport( 0, 0, _width, _height ); renderer.setAutoClear(_oldAutoClear); - } + + renderTarget.deallocate(this.renderer.getGL()); + RTMaterial.deallocate(renderer); + } } diff --git a/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java b/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java index 5eca845b..39d90466 100644 --- a/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java +++ b/src/thothbot/parallax/plugins/effects/ParallaxBarrier.java @@ -20,6 +20,7 @@ import java.util.List; +import thothbot.parallax.core.client.events.ViewportResizeEvent; import thothbot.parallax.core.client.gl2.enums.PixelFormat; import thothbot.parallax.core.client.gl2.enums.TextureMagFilter; import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; @@ -64,13 +65,22 @@ public ParallaxBarrier(WebGLRenderer renderer, Scene scene) { _camera.getPosition().setZ(2); _scene.add( _camera ); - + _material = new ShaderMaterial(new ParallaxBarrierShader()); initRenderTargets(renderer.getAbsoluteWidth(), renderer.getAbsoluteHeight()); Mesh mesh = new Mesh( new PlaneBufferGeometry( 2, 2 ), _material ); _scene.add( mesh ); } + + @Override + public void onResize(ViewportResizeEvent event) + { + int width = event.getRenderer().getAbsoluteWidth(); + int height = event.getRenderer().getAbsoluteHeight(); + + initRenderTargets(width, height); + } private void initRenderTargets(int width, int height ) { @@ -89,7 +99,6 @@ private void initRenderTargets(int width, int height ) _renderTargetR.setMagFilter(TextureMagFilter.NEAREST); _renderTargetR.setFormat(PixelFormat.RGBA); - _material = new ShaderMaterial(new ParallaxBarrierShader()); _material.getShader().getUniforms().get( "mapLeft" ).setValue( _renderTargetL ); _material.getShader().getUniforms().get( "mapRight").setValue( _renderTargetR ); diff --git a/src/thothbot/parallax/plugins/effects/Stereo.java b/src/thothbot/parallax/plugins/effects/Stereo.java index 06d360fe..2d6cb13d 100644 --- a/src/thothbot/parallax/plugins/effects/Stereo.java +++ b/src/thothbot/parallax/plugins/effects/Stereo.java @@ -20,6 +20,7 @@ import java.util.List; +import thothbot.parallax.core.client.events.ViewportResizeEvent; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.PerspectiveCamera; @@ -57,6 +58,12 @@ public Stereo(WebGLRenderer renderer, Scene scene) { _oldAutoClear = renderer.isAutoClear(); renderer.setAutoClear(false); } + + @Override + public void onResize(ViewportResizeEvent event) + { + + } @Override public void render(Camera sceneCamera, List lights, int currentWidth, int currentHeight) From e993f116fb90eb395b12b232320c2a52e0fbd26d Mon Sep 17 00:00:00 2001 From: thothbot Date: Sun, 8 Feb 2015 01:52:50 +0300 Subject: [PATCH 23/75] Added STLLoader --- .../core/client/gl2/arrays/TypeArray.java | 6 +- .../core/shared/helpers/CameraHelper.java | 6 +- .../core/shared/objects/MorphAnimMesh.java | 8 +- .../parallax/loader/shared/STLLoader.java | 318 ++++++++++++++++++ 4 files changed, 328 insertions(+), 10 deletions(-) create mode 100644 src/thothbot/parallax/loader/shared/STLLoader.java diff --git a/src/thothbot/parallax/core/client/gl2/arrays/TypeArray.java b/src/thothbot/parallax/core/client/gl2/arrays/TypeArray.java index 71db497b..dcd3efd1 100644 --- a/src/thothbot/parallax/core/client/gl2/arrays/TypeArray.java +++ b/src/thothbot/parallax/core/client/gl2/arrays/TypeArray.java @@ -62,5 +62,9 @@ public final native void set(TypeArray array, int offset) /*-{ */ public final native int getLength() /*-{ return this.length; - }-*/; + }-*/; + + public final native int reverse() /*-{ + return this.reverse; + }-*/; } diff --git a/src/thothbot/parallax/core/shared/helpers/CameraHelper.java b/src/thothbot/parallax/core/shared/helpers/CameraHelper.java index 30b07664..23782c05 100644 --- a/src/thothbot/parallax/core/shared/helpers/CameraHelper.java +++ b/src/thothbot/parallax/core/shared/helpers/CameraHelper.java @@ -49,12 +49,8 @@ public class CameraHelper extends Line { private Camera camera; -// + private Map> pointMap; -// -// private static Projector __projector = new Projector(); -// private static Vector3 __v = new Vector3(); -// private static Camera __c = new Camera(); public CameraHelper(Camera camera) { diff --git a/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java b/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java index 5351f4a4..2fa5bffb 100644 --- a/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java +++ b/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java @@ -117,10 +117,10 @@ public void parseAnimations() { MorphTarget morph = geometry.getMorphTargets().get(i); - MatchResult matcher = pattern.exec(morph.name); - for (int j=0; i<=matcher.getGroupCount(); i++) { - String label = matcher.getGroup(1); - String num = matcher.getGroup(2); + for (MatchResult result = pattern.exec(morph.name); result != null; result = pattern.exec(morph.name)) + { + String label = result.getGroup(1); + String num = result.getGroup(2); if ( ! this.animations.containsKey( label ) ) { Animation animation = new Animation(); diff --git a/src/thothbot/parallax/loader/shared/STLLoader.java b/src/thothbot/parallax/loader/shared/STLLoader.java new file mode 100644 index 00000000..58a7e25a --- /dev/null +++ b/src/thothbot/parallax/loader/shared/STLLoader.java @@ -0,0 +1,318 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.loader.shared; + +import com.google.gwt.regexp.shared.MatchResult; +import com.google.gwt.regexp.shared.RegExp; + +import thothbot.parallax.core.client.gl2.arrays.Float32Array; +import thothbot.parallax.core.client.gl2.arrays.Uint8Array; +import thothbot.parallax.core.shared.core.AbstractGeometry; +import thothbot.parallax.core.shared.core.BufferAttribute; +import thothbot.parallax.core.shared.core.BufferGeometry; +import thothbot.parallax.core.shared.core.Face3; +import thothbot.parallax.core.shared.core.Geometry; +import thothbot.parallax.core.shared.math.Vector3; + +public class STLLoader extends Loader { + + public class DataView { + + Uint8Array buffer; + int byteOffset = 0; + int byteLength; + + public DataView(Uint8Array buffer) { + this(buffer, 0, buffer.getByteLength() > 0 ? buffer.getByteLength() : buffer.getLength()); + } + + public DataView(Uint8Array buffer, int byteOffset, int byteLength) { + this.buffer = buffer; + this.byteOffset = byteOffset; + this.byteLength = byteLength; +// this._isString = typeof buffer === "string"; + } + + public double getFloat32 (int byteOffset, boolean littleEndian) { + + Uint8Array b = this._getBytes(4, byteOffset, littleEndian); + + int sign = 1 - (2 * (b.get(3) >> 7)); + int exponent = (((b.get(3) << 1) & 0xff) | (b.get(2) >> 7)) - 127; + int mantissa = ((b.get(2) & 0x7f) << 16) | (b.get(1) << 8) | b.get(0); + + if (exponent == 128) { + if (mantissa != 0) { + return Double.NaN; + } else { + return sign * Double.POSITIVE_INFINITY; + } + } + + if (exponent == -127) { // Denormalized + return sign * mantissa * Math.pow(2, -126 - 23); + } + + return sign * (1 + mantissa * Math.pow(2, -23)) * Math.pow(2, exponent); + } + + + public int getInt32 (int byteOffset, boolean littleEndian) { + Uint8Array b = this._getBytes(4, byteOffset, littleEndian); + return (b.get(3) << 24) | (b.get(2) << 16) | (b.get(1) << 8) | b.get(0); + } + + public int getUint32 (int byteOffset, boolean littleEndian) { + return this.getInt32(byteOffset, littleEndian) >>> 0; + } + + public int getInt16 (int byteOffset, boolean littleEndian) { + return (this.getUint16(byteOffset, littleEndian) << 16) >> 16; + } + + public int getUint16 (int byteOffset, boolean littleEndian) { + Uint8Array b = this._getBytes(2, byteOffset, littleEndian); + return (b.get(1) << 8) | b.get(0); + } + + public int getInt8 (int byteOffset) { + return (this.getUint8(byteOffset) << 24) >> 24; + } + + public int getUint8 (int byteOffset) { + return this._getBytes(1, byteOffset, false).get(0); + } + + private Uint8Array _getBytes(int length, int byteOffset, boolean littleEndian) { + + Uint8Array result; + + byteOffset = this.byteOffset + byteOffset; + + if (length < 0 || byteOffset + length > this.byteLength) { + + throw new Error("DataView length or (byteOffset+length) value is out of bounds"); + + } + + result = this.buffer.slice(byteOffset, byteOffset + length); + + if (!littleEndian && length > 1) + { + result.reverse(); + } + + return result; + + } + + } + + AbstractGeometry geometry; + Uint8Array binData; + + @Override + public void parse(String string) { + + this.binData = ensureBinary( string ); + + if(isBinary()) + this.parseBinary(); + else + this.parseASCII( string ); + } + + private void parseBinary() + { + DataView reader = new DataView( this.binData ); + int faces = reader.getUint32( 80, true ); + + boolean hasColors = false; + Float32Array colors = null; + + double r = 0, g = 0, b = 0; + double defaultR = 0, defaultG = 0, defaultB = 0, alpha = 0; + // process STL header + // check for default color in header ("COLOR=rgba" sequence). + + for ( int index = 0; index < 80 - 10; index ++ ) { + + if ((reader.getUint32(index, false) == 0x434F4C4F /*COLO*/) && + (reader.getUint8(index + 4) == 0x52 /*'R'*/) && + (reader.getUint8(index + 5) == 0x3D /*'='*/)) { + + hasColors = true; + colors = Float32Array.create( faces * 3 * 3); + + defaultR = (double)reader.getUint8(index + 6) / 255.0; + defaultG = (double)reader.getUint8(index + 7) / 255.0; + defaultB = (double)reader.getUint8(index + 8) / 255.0; + alpha = (double)reader.getUint8(index + 9) / 255.0; + } + } + + int dataOffset = 84; + int faceLength = 12 * 4 + 2; + + int offset = 0; + + geometry = new BufferGeometry(); + + Float32Array vertices = Float32Array.create( faces * 3 * 3 ); + Float32Array normals = Float32Array.create( faces * 3 * 3 ); + + for ( int face = 0; face < faces; face ++ ) { + + int start = dataOffset + face * faceLength; + double normalX = reader.getFloat32(start, true); + double normalY = reader.getFloat32(start + 4, true); + double normalZ = reader.getFloat32(start + 8, true); + + if (hasColors) { + + int packedColor = reader.getUint16(start + 48, true); + + if ((packedColor & 0x8000) == 0) { // facet has its own unique color + + r = (double)(packedColor & 0x1F) / 31.0; + g = (double)((packedColor >> 5) & 0x1F) / 31.0; + b = (double)((packedColor >> 10) & 0x1F) / 31.0; + } else { + + r = defaultR; + g = defaultG; + b = defaultB; + } + } + + for ( int i = 1; i <= 3; i ++ ) { + + int vertexstart = start + i * 12; + + vertices.set( offset , reader.getFloat32( vertexstart, true )); + vertices.set( offset + 1 , reader.getFloat32( vertexstart + 4, true )); + vertices.set( offset + 2 , reader.getFloat32( vertexstart + 8, true )); + + normals.set( offset , normalX ); + normals.set( offset + 1 , normalY ); + normals.set( offset + 2 , normalZ ); + + if (hasColors) { + colors.set( offset , r ); + colors.set( offset + 1 , g ); + colors.set( offset + 2 , b ); + } + + offset += 3; + + } + + } + + ((BufferGeometry)geometry).addAttribute( "position", new BufferAttribute( vertices, 3 ) ); + ((BufferGeometry)geometry).addAttribute( "normal", new BufferAttribute( normals, 3 ) ); + + if (hasColors) { + ((BufferGeometry)geometry).addAttribute( "color", new BufferAttribute( colors, 3 ) ); +// geometry.hasColors = true; +// geometry.alpha = alpha; + } + + } + + private void parseASCII( String data ) + { +// var length, normal, patternFace, patternNormal, patternVertex, result, text; + this.geometry = new Geometry(); + + Vector3 normal = null; + RegExp patternFace = RegExp.compile("facet([\\s\\S]*?)endfacet", "g"); + + for (MatchResult result = patternFace.exec(data); result != null; result = patternFace.exec(data)) + { + String text = result.getGroup(0); + RegExp patternNormal = RegExp.compile("normal[\\s]+([\\-+]?[0-9]+\\.?[0-9]*([eE][\\-+]?[0-9]+)?)+[\\s]+([\\-+]?[0-9]*\\.?[0-9]+([eE][\\-+]?[0-9]+)?)+[\\s]+([\\-+]?[0-9]*\\.?[0-9]+([eE][\\-+]?[0-9]+)?)+", "g"); + + for (MatchResult result2 = patternNormal.exec(text); result2 != null; result2 = patternNormal.exec(text)) + { + normal = new Vector3( Double.parseDouble( result2.getGroup(1) ), Double.parseDouble( result2.getGroup(3) ), Double.parseDouble( result2.getGroup(5) ) ); + } + + RegExp patternVertex = RegExp.compile("vertex[\\s]+([\\-+]?[0-9]+\\.?[0-9]*([eE][\\-+]?[0-9]+)?)+[\\s]+([\\-+]?[0-9]*\\.?[0-9]+([eE][\\-+]?[0-9]+)?)+[\\s]+([\\-+]?[0-9]*\\.?[0-9]+([eE][\\-+]?[0-9]+)?)+", "g"); + + for (MatchResult result2 = patternVertex.exec(text); result2 != null; result2 = patternVertex.exec(text)) + + { + ((Geometry)geometry).getVertices().add( new Vector3( Double.parseDouble( result2.getGroup(1) ), Double.parseDouble( result2.getGroup(3) ), Double.parseDouble( result2.getGroup(5) ) ) ); + } + + int length = ((Geometry)geometry).getVertices().size(); + + ((Geometry)geometry).getFaces().add( new Face3( length - 3, length - 2, length - 1, normal ) ); + + } + + geometry.computeBoundingBox(); + geometry.computeBoundingSphere(); + + } + + private Uint8Array ensureBinary( String buf ) { + + Uint8Array array_buffer = Uint8Array.create(buf.length()); + + for(int i = 0; i < buf.length(); i++) + { + array_buffer.set(i, Character.codePointAt(buf, i) & 0xff); // implicitly assumes little-endian + } + + return array_buffer; + } + + + private boolean isBinary() { + + DataView reader = new DataView( this.binData ); + int face_size = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8); + int n_faces = reader.getUint32(80, true); + int expect = 80 + (32 / 8) + (n_faces * face_size); + + if ( expect == reader.byteLength ) { + + return true; + + } + + // some binary files will have different size from expected, + // checking characters higher than ASCII to confirm is binary + int fileLength = reader.byteLength; + for ( int index = 0; index < fileLength; index ++ ) { + + if ( reader.getUint8(index) > 127 ) { + + return true; + + } + + } + + return false; + } + +} From 27dfb1ce584dafc3f26863a56b3df6552892683f Mon Sep 17 00:00:00 2001 From: thothbot Date: Sun, 8 Feb 2015 03:12:34 +0300 Subject: [PATCH 24/75] Fixed some issues in Uint8Array --- .../core/client/gl2/arrays/Uint8Array.java | 19 ++++++++++++++++++- .../parallax/loader/shared/STLLoader.java | 12 ++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/thothbot/parallax/core/client/gl2/arrays/Uint8Array.java b/src/thothbot/parallax/core/client/gl2/arrays/Uint8Array.java index 30535648..38752399 100644 --- a/src/thothbot/parallax/core/client/gl2/arrays/Uint8Array.java +++ b/src/thothbot/parallax/core/client/gl2/arrays/Uint8Array.java @@ -217,6 +217,23 @@ public native Uint8Array slice(int begin) /*-{ * @param end */ public native Uint8Array slice(int begin, int end) /*-{ - return this.slice(begin, end); + // ArrayBuffer is supposed to support slice + // which works in Chrome 18 but not Firefox 10 or 11. As for Firefox, you need to copy it manually. + if (!Uint8Array.prototype.slice) + { + var that = new Uint8Array(this); +// if (end == undefined) end = that.length; +// var result = new ArrayBuffer(end - begin); + var resultArray = new Uint8Array(end - begin); + for (var i = 0; i < resultArray.length; i++) + resultArray[i] = that[i + begin]; + return resultArray; + + } else { + + return this.slice(begin, end); + + } + }-*/; } diff --git a/src/thothbot/parallax/loader/shared/STLLoader.java b/src/thothbot/parallax/loader/shared/STLLoader.java index 58a7e25a..f48aea25 100644 --- a/src/thothbot/parallax/loader/shared/STLLoader.java +++ b/src/thothbot/parallax/loader/shared/STLLoader.java @@ -23,6 +23,7 @@ import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.client.gl2.arrays.Uint8Array; +import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.BufferAttribute; import thothbot.parallax.core.shared.core.BufferGeometry; @@ -124,20 +125,23 @@ private Uint8Array _getBytes(int length, int byteOffset, boolean littleEndian) { } - AbstractGeometry geometry; - Uint8Array binData; + private AbstractGeometry geometry; + private Uint8Array binData; @Override public void parse(String string) { - - this.binData = ensureBinary( string ); + this.binData = ensureBinary( string ); if(isBinary()) this.parseBinary(); else this.parseASCII( string ); } + public AbstractGeometry getGeometry() { + return this.geometry; + } + private void parseBinary() { DataView reader = new DataView( this.binData ); From 0eec56529f31d3f04fecab654c74769432afd51a Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 9 Feb 2015 01:07:01 +0300 Subject: [PATCH 25/75] Updated model loader --- .../core/client/gl2/arrays/ArrayBuffer.java | 38 ++++ .../core/client/gl2/arrays/DataView.java | 189 ++++++++++++++++++ .../parallax/loader/shared/Loader.java | 55 +++-- .../parallax/loader/shared/STLLoader.java | 156 +++++---------- 4 files changed, 314 insertions(+), 124 deletions(-) create mode 100644 src/thothbot/parallax/core/client/gl2/arrays/DataView.java diff --git a/src/thothbot/parallax/core/client/gl2/arrays/ArrayBuffer.java b/src/thothbot/parallax/core/client/gl2/arrays/ArrayBuffer.java index 23946611..7f23e5a5 100644 --- a/src/thothbot/parallax/core/client/gl2/arrays/ArrayBuffer.java +++ b/src/thothbot/parallax/core/client/gl2/arrays/ArrayBuffer.java @@ -38,10 +38,48 @@ public static native ArrayBuffer create(int length) /*-{ return new $wnd.ArrayBuffer(length); }-*/; + public static native ArrayBuffer copy(com.google.gwt.typedarrays.shared.ArrayBuffer origin) /*-{ + if (!ArrayBuffer.prototype.slice) + { + ArrayBuffer.prototype.slice = function (start, end) { + var that = new Uint8Array(this); + if (end == undefined) end = that.length; + var result = new ArrayBuffer(end - start); + var resultArray = new Uint8Array(result); + for (var i = 0; i < resultArray.length; i++) + resultArray[i] = that[i + start]; + return result; + } + } + + return origin.slice(0); + }-*/; + + public static native ArrayBuffer slice(int start, int end) /*-{ + if (!ArrayBuffer.prototype.slice) + { + ArrayBuffer.prototype.slice = function (start, end) { + var that = new Uint8Array(this); + if (end == undefined) end = that.length; + var result = new ArrayBuffer(end - start); + var resultArray = new Uint8Array(result); + for (var i = 0; i < resultArray.length; i++) + resultArray[i] = that[i + start]; + return result; + } + } + + return this.slice(start, end); + }-*/; + /** * The length of the ArrayBuffer in bytes, as fixed at construction time. */ public native int getByteLength() /*-{ return this.byteLength; }-*/; + + public native byte get(int index) /*-{ + return this[index]; + }-*/; } diff --git a/src/thothbot/parallax/core/client/gl2/arrays/DataView.java b/src/thothbot/parallax/core/client/gl2/arrays/DataView.java new file mode 100644 index 00000000..7b170141 --- /dev/null +++ b/src/thothbot/parallax/core/client/gl2/arrays/DataView.java @@ -0,0 +1,189 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.client.gl2.arrays; + +import com.google.gwt.core.client.JavaScriptObject; + +public final class DataView extends JavaScriptObject +{ + protected DataView() { + + } + + /** + * @param buffer + * @return a {@link DataView} instance + */ + public static native DataView create(ArrayBuffer buffer) /*-{ + return new $wnd.DataView(buffer); + }-*/; + + /** + * @param buffer + * @param byteOffset + * @return a {@link DataView} instance + */ + public static native DataView create(ArrayBuffer buffer, int byteOffset) /*-{ + return new $wnd.DataView(buffer, byteOffset); + }-*/; + + /** + * @param buffer + * @param byteOffset + * @param byteLength + * @return a {@link DataView} instance + */ + public static native DataView create(ArrayBuffer buffer, int byteOffset, + int byteLength) /*-{ + return new $wnd.DataView(buffer, byteOffset, byteLength); + }-*/; + + public native int byteLength() /*-{ + return this.byteLength; + }-*/; + + public native float getFloat32(int byteOffset) /*-{ + return this.getFloat32(byteOffset); + }-*/; + + public native float getFloat32(int byteOffset, boolean littleEndian) /*-{ + return this.getFloat32(byteOffset, littleEndian); + }-*/; + + public native double getFloat64(int byteOffset) /*-{ + return this.getFloat64(byteOffset); + }-*/; + + public native double getFloat64(int byteOffset, boolean littleEndian) /*-{ + return this.getFloat64(byteOffset, littleEndian); + }-*/; + + public native short getInt16(int byteOffset) /*-{ + return this.getInt16(byteOffset); + }-*/; + + public native short getInt16(int byteOffset, boolean littleEndian) /*-{ + return this.getInt16(byteOffset, littleEndian); + }-*/; + + public native int getInt32(int byteOffset) /*-{ + return this.getInt32(byteOffset); + }-*/; + + public native int getInt32(int byteOffset, boolean littleEndian) /*-{ + return this.getInt32(byteOffset, littleEndian); + }-*/; + + public native byte getInt8(int byteOffset) /*-{ + return this.getInt8(byteOffset); + }-*/; + + public native int getUint16(int byteOffset) /*-{ + return this.getUint16(byteOffset); + }-*/; + + public native int getUint16(int byteOffset, boolean littleEndian) /*-{ + return this.getUint16(byteOffset, littleEndian); + }-*/; + + public int getUint32(int byteOffset) { + return (int) getUint32AsDouble(byteOffset); + } + + public int getUint32(int byteOffset, boolean littleEndian) { + return (int) getUint32AsDouble(byteOffset, littleEndian); + } + + public native double getUint32AsDouble(int byteOffset) /*-{ + return this.getUint32(byteOffset); + }-*/; + + public native double getUint32AsDouble(int byteOffset, boolean littleEndian) /*-{ + return this.getUint32(byteOffset, littleEndian); + }-*/; + + public native short getUint8(int byteOffset) /*-{ + return this.getUint8(byteOffset); + }-*/; + + public native void setFloat32(int byteOffset, float value) /*-{ + this.setFloat32(byteOffset, value); + }-*/; + + public native void setFloat32(int byteOffset, float value, boolean littleEndian) /*-{ + this.setFloat32(byteOffset, value, littleEndian); + }-*/; + + public native void setFloat64(int byteOffset, double value) /*-{ + this.setFloat64(byteOffset, value); + }-*/; + + public native void setFloat64(int byteOffset, double value, boolean littleEndian) /*-{ + this.setFloat64(byteOffset, value, littleEndian); + }-*/; + + public native void setInt16(int byteOffset, int value) /*-{ + this.setInt16(byteOffset, value); + }-*/; + + public native void setInt16(int byteOffset, int value, boolean littleEndian) /*-{ + this.setInt16(byteOffset, value, littleEndian); + }-*/; + + public native void setInt32(int byteOffset, int value) /*-{ + this.setInt32(byteOffset, value); + }-*/; + + public native void setInt32(int byteOffset, int value, boolean littleEndian) /*-{ + this.setInt32(byteOffset, value, littleEndian); + }-*/; + + public native void setInt8(int byteOffset, int value) /*-{ + this.setInt8(byteOffset, value); + }-*/; + + public native void setUint16(int byteOffset, int value) /*-{ + this.setUint16(byteOffset, value); + }-*/; + + public native void setUint16(int byteOffset, int value, boolean littleEndian) /*-{ + this.setUint16(byteOffset, value, littleEndian); + }-*/; + + public void setUint32(int byteOffset, long value) { + setUint32FromDouble(byteOffset, value); + } + + public void setUint32(int byteOffset, long value, boolean littleEndian) { + setUint32FromDouble(byteOffset, value, littleEndian); + } + + public native void setUint32FromDouble(int byteOffset, double value) /*-{ + this.setUint32(byteOffset, value); + }-*/; + + public native void setUint32FromDouble(int byteOffset, double value, boolean littleEndian) /*-{ + this.setUint32(byteOffset, value, littleEndian); + }-*/; + + public native void setUint8(int byteOffset, int value) /*-{ + this.setUint8(byteOffset, value); + }-*/; +} + diff --git a/src/thothbot/parallax/loader/shared/Loader.java b/src/thothbot/parallax/loader/shared/Loader.java index d0b5f4c7..540225d6 100644 --- a/src/thothbot/parallax/loader/shared/Loader.java +++ b/src/thothbot/parallax/loader/shared/Loader.java @@ -18,13 +18,13 @@ package thothbot.parallax.loader.shared; +import thothbot.parallax.core.client.gl2.arrays.ArrayBuffer; import thothbot.parallax.core.shared.Log; -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; import com.google.gwt.http.client.RequestException; -import com.google.gwt.http.client.Response; +import com.google.gwt.xhr.client.ReadyStateChangeHandler; +import com.google.gwt.xhr.client.XMLHttpRequest; +import com.google.gwt.xhr.client.XMLHttpRequest.ResponseType; public abstract class Loader { @@ -34,35 +34,58 @@ public interface ModelLoadHandler } private String texturePath; + private ResponseType responseType = ResponseType.Default; public void load(final String url, final ModelLoadHandler modelLoadHandler) throws RequestException { texturePath = extractUrlBase(url); - RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url); - rb.sendRequest(null, new RequestCallback() { + final XMLHttpRequest request = XMLHttpRequest.create(); + request.open( "GET", url ); + request.setResponseType(this.responseType); + request.send( null ); + request.setOnReadyStateChange(new ReadyStateChangeHandler() { + @Override - public void onResponseReceived(Request request, Response response) - { - parse(response.getText()); - modelLoadHandler.onModelLoaded(); - } + public void onReadyStateChange(XMLHttpRequest xhr) { + if(xhr.getReadyState() == XMLHttpRequest.DONE) + { + if (xhr.getStatus() >= 400) { + Log.error("Error while loading file: " + url); + } + else + { + if(xhr.getResponseType().equals("arraybuffer")) { + com.google.gwt.typedarrays.shared.ArrayBuffer origin = xhr.getResponseArrayBuffer(); - @Override - public void onError(Request request, Throwable exception) - { - Log.error("Error while loading file: " + url); + parse(ArrayBuffer.copy(origin)); + } else + parse(xhr.getResponseText()); + + modelLoadHandler.onModelLoaded(); + } + + request.clearOnReadyStateChange(); + request.abort(); + } } }); } - public abstract void parse(String string); + public abstract void parse(String string); + public void parse(ArrayBuffer buffer) { + + } public String getTexturePath() { return this.texturePath; } + public void setResponseType(ResponseType responseType) { + this.responseType = responseType; + } + private String extractUrlBase( String url ) { int i = url.lastIndexOf('/'); diff --git a/src/thothbot/parallax/loader/shared/STLLoader.java b/src/thothbot/parallax/loader/shared/STLLoader.java index f48aea25..b0fec641 100644 --- a/src/thothbot/parallax/loader/shared/STLLoader.java +++ b/src/thothbot/parallax/loader/shared/STLLoader.java @@ -20,7 +20,10 @@ import com.google.gwt.regexp.shared.MatchResult; import com.google.gwt.regexp.shared.RegExp; +import com.google.gwt.xhr.client.XMLHttpRequest.ResponseType; +import thothbot.parallax.core.client.gl2.arrays.ArrayBuffer; +import thothbot.parallax.core.client.gl2.arrays.DataView; import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.client.gl2.arrays.Uint8Array; import thothbot.parallax.core.shared.Log; @@ -32,120 +35,48 @@ import thothbot.parallax.core.shared.math.Vector3; public class STLLoader extends Loader { - - public class DataView { - - Uint8Array buffer; - int byteOffset = 0; - int byteLength; - - public DataView(Uint8Array buffer) { - this(buffer, 0, buffer.getByteLength() > 0 ? buffer.getByteLength() : buffer.getLength()); - } - - public DataView(Uint8Array buffer, int byteOffset, int byteLength) { - this.buffer = buffer; - this.byteOffset = byteOffset; - this.byteLength = byteLength; -// this._isString = typeof buffer === "string"; - } - - public double getFloat32 (int byteOffset, boolean littleEndian) { - - Uint8Array b = this._getBytes(4, byteOffset, littleEndian); - - int sign = 1 - (2 * (b.get(3) >> 7)); - int exponent = (((b.get(3) << 1) & 0xff) | (b.get(2) >> 7)) - 127; - int mantissa = ((b.get(2) & 0x7f) << 16) | (b.get(1) << 8) | b.get(0); - - if (exponent == 128) { - if (mantissa != 0) { - return Double.NaN; - } else { - return sign * Double.POSITIVE_INFINITY; - } - } - - if (exponent == -127) { // Denormalized - return sign * mantissa * Math.pow(2, -126 - 23); - } - - return sign * (1 + mantissa * Math.pow(2, -23)) * Math.pow(2, exponent); - } - - - public int getInt32 (int byteOffset, boolean littleEndian) { - Uint8Array b = this._getBytes(4, byteOffset, littleEndian); - return (b.get(3) << 24) | (b.get(2) << 16) | (b.get(1) << 8) | b.get(0); - } - - public int getUint32 (int byteOffset, boolean littleEndian) { - return this.getInt32(byteOffset, littleEndian) >>> 0; - } - - public int getInt16 (int byteOffset, boolean littleEndian) { - return (this.getUint16(byteOffset, littleEndian) << 16) >> 16; - } - - public int getUint16 (int byteOffset, boolean littleEndian) { - Uint8Array b = this._getBytes(2, byteOffset, littleEndian); - return (b.get(1) << 8) | b.get(0); - } - - public int getInt8 (int byteOffset) { - return (this.getUint8(byteOffset) << 24) >> 24; - } - - public int getUint8 (int byteOffset) { - return this._getBytes(1, byteOffset, false).get(0); - } - - private Uint8Array _getBytes(int length, int byteOffset, boolean littleEndian) { - - Uint8Array result; - - byteOffset = this.byteOffset + byteOffset; - - if (length < 0 || byteOffset + length > this.byteLength) { - - throw new Error("DataView length or (byteOffset+length) value is out of bounds"); - - } - - result = this.buffer.slice(byteOffset, byteOffset + length); - - if (!littleEndian && length > 1) - { - result.reverse(); - } - - return result; - - } + private AbstractGeometry geometry; + private ArrayBuffer binData; + + public boolean hasColors; + public double alpha; + + public STLLoader() + { + // Load binary data by default + setResponseType(ResponseType.ArrayBuffer); } - private AbstractGeometry geometry; - private Uint8Array binData; - @Override - public void parse(String string) { + public void parse(ArrayBuffer buffer) + { + this.binData = buffer; - this.binData = ensureBinary( string ); if(isBinary()) this.parseBinary(); else - this.parseASCII( string ); + this.parseASCII( ensureString(buffer) ); + + } + + @Override + public void parse(String string) { + +// this.binData = ensureBinary( string ); + +// this.parseBinary(); } - public AbstractGeometry getGeometry() { + public AbstractGeometry getGeometry() + { return this.geometry; } private void parseBinary() { - DataView reader = new DataView( this.binData ); - int faces = reader.getUint32( 80, true ); + DataView reader = DataView.create( this.binData ); + int faces = (int)reader.getUint32( 80, true ); boolean hasColors = false; Float32Array colors = null; @@ -184,6 +115,7 @@ private void parseBinary() for ( int face = 0; face < faces; face ++ ) { int start = dataOffset + face * faceLength; + double normalX = reader.getFloat32(start, true); double normalY = reader.getFloat32(start + 4, true); double normalZ = reader.getFloat32(start + 8, true); @@ -234,15 +166,14 @@ private void parseBinary() if (hasColors) { ((BufferGeometry)geometry).addAttribute( "color", new BufferAttribute( colors, 3 ) ); -// geometry.hasColors = true; -// geometry.alpha = alpha; + this.hasColors = true; + this.alpha = alpha; } } private void parseASCII( String data ) { -// var length, normal, patternFace, patternNormal, patternVertex, result, text; this.geometry = new Geometry(); Vector3 normal = null; @@ -288,16 +219,25 @@ private Uint8Array ensureBinary( String buf ) { return array_buffer; } - + private String ensureString ( ArrayBuffer buf ) { + + Uint8Array array_buffer = Uint8Array.create(buf); + StringBuilder builder = new StringBuilder(buf.getByteLength()); + for(int i = 0; i < buf.getByteLength(); i++) { + builder.append(Character.toChars(array_buffer.get(i))); // implicitly assumes little-endian + } + return builder.toString(); + } + private boolean isBinary() { - DataView reader = new DataView( this.binData ); + DataView reader = DataView.create( this.binData ); int face_size = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8); - int n_faces = reader.getUint32(80, true); + int n_faces = (int)reader.getUint32(80, true); int expect = 80 + (32 / 8) + (n_faces * face_size); - - if ( expect == reader.byteLength ) { + + if ( expect == reader.byteLength() ) { return true; @@ -305,7 +245,7 @@ private boolean isBinary() { // some binary files will have different size from expected, // checking characters higher than ASCII to confirm is binary - int fileLength = reader.byteLength; + int fileLength = reader.byteLength(); for ( int index = 0; index < fileLength; index ++ ) { if ( reader.getUint8(index) > 127 ) { From 950928ff2a04704c835908e5ec3b97a13fe7ae7b Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 9 Feb 2015 01:31:25 +0300 Subject: [PATCH 26/75] Apdated load handler for object loader --- .../parallax/loader/shared/ColladaLoader.java | 5 ++- .../parallax/loader/shared/JsonLoader.java | 38 +++++++++---------- .../parallax/loader/shared/Loader.java | 17 +++++---- .../parallax/loader/shared/STLLoader.java | 31 ++++++--------- 4 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/thothbot/parallax/loader/shared/ColladaLoader.java b/src/thothbot/parallax/loader/shared/ColladaLoader.java index 806c1745..87c5a548 100644 --- a/src/thothbot/parallax/loader/shared/ColladaLoader.java +++ b/src/thothbot/parallax/loader/shared/ColladaLoader.java @@ -18,6 +18,7 @@ package thothbot.parallax.loader.shared; +import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.loader.shared.collada.DaeDocument; import com.google.gwt.xml.client.Document; @@ -28,10 +29,12 @@ public class ColladaLoader extends Loader private DaeDocument daeDocument; private Document document; - public void parse(String xmlString) + public AbstractGeometry parse(String xmlString) { document = XMLParser.parse(xmlString); daeDocument = new DaeDocument(document); + + return null; } public DaeDocument getDaeDocument() { diff --git a/src/thothbot/parallax/loader/shared/JsonLoader.java b/src/thothbot/parallax/loader/shared/JsonLoader.java index fd476bd8..e1bb8368 100644 --- a/src/thothbot/parallax/loader/shared/JsonLoader.java +++ b/src/thothbot/parallax/loader/shared/JsonLoader.java @@ -28,6 +28,7 @@ import thothbot.parallax.core.client.textures.CompressedTexture; import thothbot.parallax.core.client.textures.Texture; import thothbot.parallax.core.shared.Log; +import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.Face3; import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.core.Geometry.MorphColor; @@ -68,29 +69,25 @@ public class JsonLoader extends Loader { - private JsoObject object; - private Geometry geometry; private List materials; @Override - public void parse(String string) + public AbstractGeometry parse(String string) { if(!isThisJsonStringValid(string)) - return; + return null; Log.debug("JSON parse()"); - geometry = new Geometry(); - - double scale = object.getScale() > 0 ? 1.0 / object.getScale() : 1.0; + Geometry geometry = new Geometry(); parseMaterials(); - parseModel(scale); + parseModel(geometry); - parseSkin(); - parseMorphing(scale); + parseSkin(geometry); + parseMorphing(geometry); geometry.computeFaceNormals(); geometry.computeBoundingSphere(); @@ -99,18 +96,15 @@ public void parse(String string) geometry.computeTangents(); geometry.computeMorphNormals(); + + return geometry; } - - public Geometry getGeometry() - { - return this.geometry; - } - + public List getMaterials() { return this.materials; } - public void morphColorsToFaceColors() + public void morphColorsToFaceColors(Geometry geometry) { if ( geometry.getMorphColors() != null && geometry.getMorphColors().size() > 0 ) { @@ -376,12 +370,14 @@ else if( material instanceof HasSpecularMap ) return material; } - private void parseModel(double scale) + private void parseModel(Geometry geometry) { if(object.getFaces() == null) return; Log.debug("JSON parseFaces()"); + + double scale = object.getScale() > 0 ? 1.0 / object.getScale() : 1.0; List faces = object.getFaces(); List vertices = object.getVertices(); @@ -644,7 +640,7 @@ private void parseModel(double scale) } } - private void parseSkin() + private void parseSkin(Geometry geometry) { int influencesPerVertex = ( object.getInfluencesPerVertex() > 0 ) ? object.getInfluencesPerVertex() : 2; @@ -684,9 +680,11 @@ private void parseSkin() // geometry.animation = json.animation; } - private void parseMorphing(double scale) + private void parseMorphing(Geometry geometry) { Log.debug("JSON parseMorphing()"); + + double scale = object.getScale() > 0 ? 1.0 / object.getScale() : 1.0; if ( object.getMorphTargets() != null) { diff --git a/src/thothbot/parallax/loader/shared/Loader.java b/src/thothbot/parallax/loader/shared/Loader.java index 540225d6..667af078 100644 --- a/src/thothbot/parallax/loader/shared/Loader.java +++ b/src/thothbot/parallax/loader/shared/Loader.java @@ -20,6 +20,7 @@ import thothbot.parallax.core.client.gl2.arrays.ArrayBuffer; import thothbot.parallax.core.shared.Log; +import thothbot.parallax.core.shared.core.AbstractGeometry; import com.google.gwt.http.client.RequestException; import com.google.gwt.xhr.client.ReadyStateChangeHandler; @@ -30,7 +31,7 @@ public abstract class Loader { public interface ModelLoadHandler { - public void onModelLoaded(); + public void onModelLoaded(AbstractGeometry geometry); } private String texturePath; @@ -56,14 +57,16 @@ public void onReadyStateChange(XMLHttpRequest xhr) { } else { + AbstractGeometry geometry = null; + if(xhr.getResponseType().equals("arraybuffer")) { com.google.gwt.typedarrays.shared.ArrayBuffer origin = xhr.getResponseArrayBuffer(); - parse(ArrayBuffer.copy(origin)); + geometry = parse(ArrayBuffer.copy(origin)); } else - parse(xhr.getResponseText()); + geometry = parse(xhr.getResponseText()); - modelLoadHandler.onModelLoaded(); + modelLoadHandler.onModelLoaded(geometry); } request.clearOnReadyStateChange(); @@ -73,9 +76,9 @@ public void onReadyStateChange(XMLHttpRequest xhr) { }); } - public abstract void parse(String string); - public void parse(ArrayBuffer buffer) { - + public abstract AbstractGeometry parse(String string); + public AbstractGeometry parse(ArrayBuffer buffer) { + return null; } public String getTexturePath() { diff --git a/src/thothbot/parallax/loader/shared/STLLoader.java b/src/thothbot/parallax/loader/shared/STLLoader.java index b0fec641..3389682d 100644 --- a/src/thothbot/parallax/loader/shared/STLLoader.java +++ b/src/thothbot/parallax/loader/shared/STLLoader.java @@ -26,7 +26,6 @@ import thothbot.parallax.core.client.gl2.arrays.DataView; import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.client.gl2.arrays.Uint8Array; -import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.BufferAttribute; import thothbot.parallax.core.shared.core.BufferGeometry; @@ -36,7 +35,6 @@ public class STLLoader extends Loader { - private AbstractGeometry geometry; private ArrayBuffer binData; public boolean hasColors; @@ -49,31 +47,24 @@ public STLLoader() } @Override - public void parse(ArrayBuffer buffer) + public AbstractGeometry parse(ArrayBuffer buffer) { this.binData = buffer; if(isBinary()) - this.parseBinary(); + return this.parseBinary(); else - this.parseASCII( ensureString(buffer) ); + return this.parseASCII( ensureString(buffer) ); } @Override - public void parse(String string) { - -// this.binData = ensureBinary( string ); - -// this.parseBinary(); - } - - public AbstractGeometry getGeometry() + public AbstractGeometry parse(String string) { - return this.geometry; + return null; } - - private void parseBinary() + + private AbstractGeometry parseBinary() { DataView reader = DataView.create( this.binData ); int faces = (int)reader.getUint32( 80, true ); @@ -107,7 +98,7 @@ private void parseBinary() int offset = 0; - geometry = new BufferGeometry(); + BufferGeometry geometry = new BufferGeometry(); Float32Array vertices = Float32Array.create( faces * 3 * 3 ); Float32Array normals = Float32Array.create( faces * 3 * 3 ); @@ -170,11 +161,12 @@ private void parseBinary() this.alpha = alpha; } + return geometry; } - private void parseASCII( String data ) + private AbstractGeometry parseASCII( String data ) { - this.geometry = new Geometry(); + Geometry geometry = new Geometry(); Vector3 normal = null; RegExp patternFace = RegExp.compile("facet([\\s\\S]*?)endfacet", "g"); @@ -206,6 +198,7 @@ private void parseASCII( String data ) geometry.computeBoundingBox(); geometry.computeBoundingSphere(); + return geometry; } private Uint8Array ensureBinary( String buf ) { From e92c70a3b39fc8d6ae6d63285bc3499a536b82fe Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 9 Feb 2015 02:16:49 +0300 Subject: [PATCH 27/75] Updated common loader object --- .../parallax/loader/shared/ColladaLoader.java | 2 +- .../parallax/loader/shared/JsonLoader.java | 2 +- src/thothbot/parallax/loader/shared/STLLoader.java | 14 +++++++++++--- .../loader/shared/{Loader.java => XHRLoader.java} | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) rename src/thothbot/parallax/loader/shared/{Loader.java => XHRLoader.java} (98%) diff --git a/src/thothbot/parallax/loader/shared/ColladaLoader.java b/src/thothbot/parallax/loader/shared/ColladaLoader.java index 87c5a548..5b8e1f62 100644 --- a/src/thothbot/parallax/loader/shared/ColladaLoader.java +++ b/src/thothbot/parallax/loader/shared/ColladaLoader.java @@ -24,7 +24,7 @@ import com.google.gwt.xml.client.Document; import com.google.gwt.xml.client.XMLParser; -public class ColladaLoader extends Loader +public class ColladaLoader extends XHRLoader { private DaeDocument daeDocument; private Document document; diff --git a/src/thothbot/parallax/loader/shared/JsonLoader.java b/src/thothbot/parallax/loader/shared/JsonLoader.java index e1bb8368..02104c86 100644 --- a/src/thothbot/parallax/loader/shared/JsonLoader.java +++ b/src/thothbot/parallax/loader/shared/JsonLoader.java @@ -67,7 +67,7 @@ import com.google.web.bindery.autobean.shared.AutoBean; import com.google.web.bindery.autobean.shared.AutoBeanCodex; -public class JsonLoader extends Loader +public class JsonLoader extends XHRLoader { private JsoObject object; diff --git a/src/thothbot/parallax/loader/shared/STLLoader.java b/src/thothbot/parallax/loader/shared/STLLoader.java index 3389682d..b99340a9 100644 --- a/src/thothbot/parallax/loader/shared/STLLoader.java +++ b/src/thothbot/parallax/loader/shared/STLLoader.java @@ -33,12 +33,12 @@ import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.math.Vector3; -public class STLLoader extends Loader { +public class STLLoader extends XHRLoader { private ArrayBuffer binData; - public boolean hasColors; - public double alpha; + private boolean hasColors; + private double alpha; public STLLoader() { @@ -46,6 +46,14 @@ public STLLoader() setResponseType(ResponseType.ArrayBuffer); } + public boolean isHasColors() { + return hasColors; + } + + public double getAlpha() { + return alpha; + } + @Override public AbstractGeometry parse(ArrayBuffer buffer) { diff --git a/src/thothbot/parallax/loader/shared/Loader.java b/src/thothbot/parallax/loader/shared/XHRLoader.java similarity index 98% rename from src/thothbot/parallax/loader/shared/Loader.java rename to src/thothbot/parallax/loader/shared/XHRLoader.java index 667af078..e6fd64bc 100644 --- a/src/thothbot/parallax/loader/shared/Loader.java +++ b/src/thothbot/parallax/loader/shared/XHRLoader.java @@ -27,7 +27,7 @@ import com.google.gwt.xhr.client.XMLHttpRequest; import com.google.gwt.xhr.client.XMLHttpRequest.ResponseType; -public abstract class Loader +public abstract class XHRLoader { public interface ModelLoadHandler { From 3b320f23dfbd2c5a80e93591217b3c21b40e3480 Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 9 Feb 2015 03:12:46 +0300 Subject: [PATCH 28/75] Added common loading handler --- .../parallax/loader/shared/XHRLoader.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/thothbot/parallax/loader/shared/XHRLoader.java b/src/thothbot/parallax/loader/shared/XHRLoader.java index e6fd64bc..d387c7f6 100644 --- a/src/thothbot/parallax/loader/shared/XHRLoader.java +++ b/src/thothbot/parallax/loader/shared/XHRLoader.java @@ -18,6 +18,9 @@ package thothbot.parallax.loader.shared; +import java.util.ArrayList; +import java.util.List; + import thothbot.parallax.core.client.gl2.arrays.ArrayBuffer; import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.core.AbstractGeometry; @@ -29,6 +32,18 @@ public abstract class XHRLoader { + private static List loadHandlers = new ArrayList(); + private static LoaderProgressHandler loaderProgressHandler; + public static void addLoaderProgress(LoaderProgressHandler loaderProgressHandler) + { + XHRLoader.loaderProgressHandler = loaderProgressHandler; + } + + public interface LoaderProgressHandler + { + public void onProgressUpdate(int left); + } + public interface ModelLoadHandler { public void onModelLoaded(AbstractGeometry geometry); @@ -45,6 +60,9 @@ public void load(final String url, final ModelLoadHandler modelLoadHandler) thro request.open( "GET", url ); request.setResponseType(this.responseType); request.send( null ); + + loadHandlers.add(modelLoadHandler); + XHRLoader.loaderProgressHandler.onProgressUpdate(loadHandlers.size()); request.setOnReadyStateChange(new ReadyStateChangeHandler() { @@ -71,6 +89,10 @@ public void onReadyStateChange(XMLHttpRequest xhr) { request.clearOnReadyStateChange(); request.abort(); + + loadHandlers.remove(modelLoadHandler); + if(XHRLoader.loaderProgressHandler != null) + XHRLoader.loaderProgressHandler.onProgressUpdate(loadHandlers.size()); } } }); From d83d76976a1d8c07d0561cd02adbac34c9cc0b67 Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 9 Feb 2015 16:22:38 +0300 Subject: [PATCH 29/75] Updated loaders --- .../core/client/context/Canvas3d.java | 1 - .../client/textures/RenderTargetTexture.java | 1 - .../shared/cameras/OrthographicCamera.java | 1 - .../parallax/core/shared/core/Geometry.java | 1 + .../parallax/loader/shared/ColladaLoader.java | 9 +++++- .../parallax/loader/shared/JsonLoader.java | 9 +++++- .../parallax/loader/shared/STLLoader.java | 17 ++++++----- .../parallax/loader/shared/XHRLoader.java | 28 ++++++++++++------- .../parallax/plugins/effects/Anaglyph.java | 1 - .../parallax/plugins/effects/Effect.java | 4 +-- .../parallax/plugins/effects/OculusRift.java | 1 - 11 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/thothbot/parallax/core/client/context/Canvas3d.java b/src/thothbot/parallax/core/client/context/Canvas3d.java index 4d4eef80..facc8485 100644 --- a/src/thothbot/parallax/core/client/context/Canvas3d.java +++ b/src/thothbot/parallax/core/client/context/Canvas3d.java @@ -24,7 +24,6 @@ import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.dom.client.CanvasElement; import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.Element; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.ui.FocusWidget; diff --git a/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java b/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java index 061a71cb..ad8ceb2c 100644 --- a/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java +++ b/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java @@ -18,7 +18,6 @@ package thothbot.parallax.core.client.textures; -import thothbot.parallax.core.client.gl2.WebGLConstants; import thothbot.parallax.core.client.gl2.WebGLFramebuffer; import thothbot.parallax.core.client.gl2.WebGLRenderbuffer; import thothbot.parallax.core.client.gl2.WebGLRenderingContext; diff --git a/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java b/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java index 59f669f4..158d2529 100644 --- a/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java +++ b/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java @@ -19,7 +19,6 @@ package thothbot.parallax.core.shared.cameras; import thothbot.parallax.core.client.events.ViewportResizeEvent; -import thothbot.parallax.core.shared.Log; /** * Camera with orthographic projection diff --git a/src/thothbot/parallax/core/shared/core/Geometry.java b/src/thothbot/parallax/core/shared/core/Geometry.java index 7d719dca..0e58d382 100644 --- a/src/thothbot/parallax/core/shared/core/Geometry.java +++ b/src/thothbot/parallax/core/shared/core/Geometry.java @@ -37,6 +37,7 @@ import thothbot.parallax.core.shared.objects.Bone; import thothbot.parallax.core.shared.objects.Line; import thothbot.parallax.core.shared.objects.Mesh; +import thothbot.parallax.core.shared.objects.PointCloud; import com.google.gwt.core.client.GWT; diff --git a/src/thothbot/parallax/loader/shared/ColladaLoader.java b/src/thothbot/parallax/loader/shared/ColladaLoader.java index 5b8e1f62..63a036f9 100644 --- a/src/thothbot/parallax/loader/shared/ColladaLoader.java +++ b/src/thothbot/parallax/loader/shared/ColladaLoader.java @@ -28,8 +28,15 @@ public class ColladaLoader extends XHRLoader { private DaeDocument daeDocument; private Document document; + + public ColladaLoader(String url, ModelLoadHandler modelLoadHandler) + { + super(url, modelLoadHandler); + + load(); + } - public AbstractGeometry parse(String xmlString) + protected AbstractGeometry parse(String xmlString) { document = XMLParser.parse(xmlString); daeDocument = new DaeDocument(document); diff --git a/src/thothbot/parallax/loader/shared/JsonLoader.java b/src/thothbot/parallax/loader/shared/JsonLoader.java index 02104c86..7198057f 100644 --- a/src/thothbot/parallax/loader/shared/JsonLoader.java +++ b/src/thothbot/parallax/loader/shared/JsonLoader.java @@ -73,8 +73,15 @@ public class JsonLoader extends XHRLoader private List materials; + public JsonLoader(String url, ModelLoadHandler modelLoadHandler) + { + super(url, modelLoadHandler); + + load(); + } + @Override - public AbstractGeometry parse(String string) + protected AbstractGeometry parse(String string) { if(!isThisJsonStringValid(string)) return null; diff --git a/src/thothbot/parallax/loader/shared/STLLoader.java b/src/thothbot/parallax/loader/shared/STLLoader.java index b99340a9..4cdbaa6c 100644 --- a/src/thothbot/parallax/loader/shared/STLLoader.java +++ b/src/thothbot/parallax/loader/shared/STLLoader.java @@ -18,10 +18,6 @@ package thothbot.parallax.loader.shared; -import com.google.gwt.regexp.shared.MatchResult; -import com.google.gwt.regexp.shared.RegExp; -import com.google.gwt.xhr.client.XMLHttpRequest.ResponseType; - import thothbot.parallax.core.client.gl2.arrays.ArrayBuffer; import thothbot.parallax.core.client.gl2.arrays.DataView; import thothbot.parallax.core.client.gl2.arrays.Float32Array; @@ -33,6 +29,10 @@ import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.math.Vector3; +import com.google.gwt.regexp.shared.MatchResult; +import com.google.gwt.regexp.shared.RegExp; +import com.google.gwt.xhr.client.XMLHttpRequest.ResponseType; + public class STLLoader extends XHRLoader { private ArrayBuffer binData; @@ -40,10 +40,13 @@ public class STLLoader extends XHRLoader { private boolean hasColors; private double alpha; - public STLLoader() + public STLLoader(String url, ModelLoadHandler modelLoadHandler) { + super(url, modelLoadHandler); // Load binary data by default setResponseType(ResponseType.ArrayBuffer); + + load(); } public boolean isHasColors() { @@ -55,7 +58,7 @@ public double getAlpha() { } @Override - public AbstractGeometry parse(ArrayBuffer buffer) + protected AbstractGeometry parse(ArrayBuffer buffer) { this.binData = buffer; @@ -67,7 +70,7 @@ public AbstractGeometry parse(ArrayBuffer buffer) } @Override - public AbstractGeometry parse(String string) + protected AbstractGeometry parse(String string) { return null; } diff --git a/src/thothbot/parallax/loader/shared/XHRLoader.java b/src/thothbot/parallax/loader/shared/XHRLoader.java index d387c7f6..bc86636e 100644 --- a/src/thothbot/parallax/loader/shared/XHRLoader.java +++ b/src/thothbot/parallax/loader/shared/XHRLoader.java @@ -25,7 +25,6 @@ import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.core.AbstractGeometry; -import com.google.gwt.http.client.RequestException; import com.google.gwt.xhr.client.ReadyStateChangeHandler; import com.google.gwt.xhr.client.XMLHttpRequest; import com.google.gwt.xhr.client.XMLHttpRequest.ResponseType; @@ -46,16 +45,24 @@ public interface LoaderProgressHandler public interface ModelLoadHandler { - public void onModelLoaded(AbstractGeometry geometry); + public void onModelLoaded(XHRLoader loader, AbstractGeometry geometry); } - + + private String url; private String texturePath; + private ModelLoadHandler modelLoadHandler; private ResponseType responseType = ResponseType.Default; - public void load(final String url, final ModelLoadHandler modelLoadHandler) throws RequestException + public XHRLoader(String url, ModelLoadHandler modelLoadHandler) { - texturePath = extractUrlBase(url); + this.url = url; + this.texturePath = extractUrlBase(url); + this.modelLoadHandler = modelLoadHandler; + } + + protected void load() + { final XMLHttpRequest request = XMLHttpRequest.create(); request.open( "GET", url ); request.setResponseType(this.responseType); @@ -70,8 +77,9 @@ public void load(final String url, final ModelLoadHandler modelLoadHandler) thro public void onReadyStateChange(XMLHttpRequest xhr) { if(xhr.getReadyState() == XMLHttpRequest.DONE) { - if (xhr.getStatus() >= 400) { - Log.error("Error while loading file: " + url); + if (xhr.getStatus() >= 400) + { + Log.error("Error while loading file: " + url + ", status: " + xhr.getStatus()); } else { @@ -84,7 +92,7 @@ public void onReadyStateChange(XMLHttpRequest xhr) { } else geometry = parse(xhr.getResponseText()); - modelLoadHandler.onModelLoaded(geometry); + modelLoadHandler.onModelLoaded(XHRLoader.this, geometry); } request.clearOnReadyStateChange(); @@ -98,8 +106,8 @@ public void onReadyStateChange(XMLHttpRequest xhr) { }); } - public abstract AbstractGeometry parse(String string); - public AbstractGeometry parse(ArrayBuffer buffer) { + protected abstract AbstractGeometry parse(String string); + protected AbstractGeometry parse(ArrayBuffer buffer) { return null; } diff --git a/src/thothbot/parallax/plugins/effects/Anaglyph.java b/src/thothbot/parallax/plugins/effects/Anaglyph.java index 3cf63970..ddaeeb2c 100644 --- a/src/thothbot/parallax/plugins/effects/Anaglyph.java +++ b/src/thothbot/parallax/plugins/effects/Anaglyph.java @@ -27,7 +27,6 @@ import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.textures.RenderTargetTexture; -import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.OrthographicCamera; import thothbot.parallax.core.shared.cameras.PerspectiveCamera; diff --git a/src/thothbot/parallax/plugins/effects/Effect.java b/src/thothbot/parallax/plugins/effects/Effect.java index 4165a087..888cae2e 100644 --- a/src/thothbot/parallax/plugins/effects/Effect.java +++ b/src/thothbot/parallax/plugins/effects/Effect.java @@ -18,8 +18,6 @@ package thothbot.parallax.plugins.effects; -import com.google.gwt.event.shared.HandlerRegistration; - import thothbot.parallax.core.client.events.HasEventBus; import thothbot.parallax.core.client.events.ViewportResizeEvent; import thothbot.parallax.core.client.events.ViewportResizeHandler; @@ -27,6 +25,8 @@ import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.shared.scenes.Scene; +import com.google.gwt.event.shared.HandlerRegistration; + public abstract class Effect extends Plugin implements HasEventBus, ViewportResizeHandler { public Effect(WebGLRenderer renderer, Scene scene) { diff --git a/src/thothbot/parallax/plugins/effects/OculusRift.java b/src/thothbot/parallax/plugins/effects/OculusRift.java index 22ee1e8c..638898cf 100644 --- a/src/thothbot/parallax/plugins/effects/OculusRift.java +++ b/src/thothbot/parallax/plugins/effects/OculusRift.java @@ -27,7 +27,6 @@ import thothbot.parallax.core.client.gl2.enums.TextureMinFilter; import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.textures.RenderTargetTexture; -import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.OrthographicCamera; import thothbot.parallax.core.shared.cameras.PerspectiveCamera; From 0cf5992f8d2259baa8316af092f4a7b31e9d7721 Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 10 Feb 2015 16:29:12 +0300 Subject: [PATCH 30/75] Added javadoc config --- javadoc.xml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 javadoc.xml diff --git a/javadoc.xml b/javadoc.xml new file mode 100644 index 00000000..848fc369 --- /dev/null +++ b/javadoc.xml @@ -0,0 +1,6 @@ + + + + + + From 56d6743008068c12c0c7d98a0a130bc1985f4502 Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 10 Feb 2015 17:07:47 +0300 Subject: [PATCH 31/75] Fixed issue in camera helper --- .../parallax/core/shared/helpers/CameraHelper.java | 11 ++++++----- src/thothbot/parallax/core/shared/math/Vector3.java | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/thothbot/parallax/core/shared/helpers/CameraHelper.java b/src/thothbot/parallax/core/shared/helpers/CameraHelper.java index 23782c05..1fe26901 100644 --- a/src/thothbot/parallax/core/shared/helpers/CameraHelper.java +++ b/src/thothbot/parallax/core/shared/helpers/CameraHelper.java @@ -145,6 +145,9 @@ private void addPoint( String id, int hex ) this.pointMap.get( id ).add(((Geometry)getGeometry()).getVertices().size() - 1 ); } + + Vector3 _vector = new Vector3(); + Camera _camera = new Camera(); public void update() { @@ -154,8 +157,7 @@ public void update() // we need just camera projection matrix // world matrix must be identity - Camera camera = new Camera(); - camera.getProjectionMatrix().copy( this.camera.getProjectionMatrix() ); + _camera.getProjectionMatrix().copy( this.camera.getProjectionMatrix() ); // center / target @@ -199,8 +201,7 @@ public void update() private void setPoint( String point, double x, double y, double z ) { - Vector3 vector = new Vector3(); - vector.set( x, y, z ).unproject( camera ); + _vector.set( x, y, z ).unproject( _camera ); List points = this.pointMap.get( point ); @@ -209,7 +210,7 @@ private void setPoint( String point, double x, double y, double z ) for ( int i = 0, il = points.size(); i < il; i ++ ) { int j = points.get( i ); - ((Geometry)getGeometry()).getVertices().get( j ).copy( vector ); + ((Geometry)getGeometry()).getVertices().get( j ).copy( _vector ); } } } diff --git a/src/thothbot/parallax/core/shared/math/Vector3.java b/src/thothbot/parallax/core/shared/math/Vector3.java index 8682d9de..791e71fc 100644 --- a/src/thothbot/parallax/core/shared/math/Vector3.java +++ b/src/thothbot/parallax/core/shared/math/Vector3.java @@ -280,7 +280,7 @@ public Vector3 applyProjection( Matrix4 m ) double x = this.x, y = this.y, z = this.z; Float32Array e = m.getArray(); - double d = 1 / ( e.get(3) * x + e.get(7) * y + e.get(11) * z + e.get(15) ); // perspective divide + double d = 1.0 / ( e.get(3) * x + e.get(7) * y + e.get(11) * z + e.get(15) ); // perspective divide this.x = ( e.get(0) * x + e.get(4) * y + e.get(8) * z + e.get(12) ) * d; this.y = ( e.get(1) * x + e.get(5) * y + e.get(9) * z + e.get(13) ) * d; From 57480f6ae4707b39c22bfb25b77d59a8e9034671 Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 10 Feb 2015 19:44:02 +0300 Subject: [PATCH 32/75] Fixed some issues in animation --- .../core/client/textures/RenderTargetTexture.java | 5 +++++ .../core/shared/cameras/OrthographicCamera.java | 1 + .../parallax/core/shared/materials/HasShading.java | 3 ++- .../parallax/core/shared/materials/Material.java | 13 ++----------- .../core/shared/materials/MeshBasicMaterial.java | 9 --------- .../core/shared/materials/MeshPhongMaterial.java | 8 -------- src/thothbot/parallax/core/shared/objects/Mesh.java | 6 +----- .../parallax/core/shared/objects/MorphAnimMesh.java | 8 +++----- 8 files changed, 14 insertions(+), 39 deletions(-) diff --git a/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java b/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java index ad8ceb2c..464e9885 100644 --- a/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java +++ b/src/thothbot/parallax/core/client/textures/RenderTargetTexture.java @@ -72,6 +72,11 @@ public RenderTargetTexture(int width, int height, setType( type ); } + public void setSize(int width, int height) { + setWidth(width); + setHeight(height); + } + public int getWidth() { return width; } diff --git a/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java b/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java index 158d2529..59f669f4 100644 --- a/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java +++ b/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java @@ -19,6 +19,7 @@ package thothbot.parallax.core.shared.cameras; import thothbot.parallax.core.client.events.ViewportResizeEvent; +import thothbot.parallax.core.shared.Log; /** * Camera with orthographic projection diff --git a/src/thothbot/parallax/core/shared/materials/HasShading.java b/src/thothbot/parallax/core/shared/materials/HasShading.java index b4fefe04..729ac657 100644 --- a/src/thothbot/parallax/core/shared/materials/HasShading.java +++ b/src/thothbot/parallax/core/shared/materials/HasShading.java @@ -18,7 +18,8 @@ package thothbot.parallax.core.shared.materials; -public interface HasShading { +public interface HasShading +{ public Material.SHADING getShading(); public void setShading(Material.SHADING shading); diff --git a/src/thothbot/parallax/core/shared/materials/Material.java b/src/thothbot/parallax/core/shared/materials/Material.java index d875f650..2630dbf6 100644 --- a/src/thothbot/parallax/core/shared/materials/Material.java +++ b/src/thothbot/parallax/core/shared/materials/Material.java @@ -856,16 +856,7 @@ public boolean materialNeedsSmoothNormals() return this instanceof HasShading && ((HasShading)this).getShading() != null && ((HasShading)this).getShading() == Material.SHADING.SMOOTH; } - public Material.SHADING bufferGuessNormalType () - { - // only MeshBasicMaterial and MeshDepthMaterial don't need normals - if (materialNeedsSmoothNormals()) - return Material.SHADING.SMOOTH; - else - return Material.SHADING.FLAT; - } - - public Material.COLORS bufferGuessVertexColorType () + public Material.COLORS bufferGuessVertexColorType() { if(this instanceof HasVertexColors && ((HasVertexColors)this).isVertexColors() != Material.COLORS.NO) return ((HasVertexColors)this).isVertexColors(); @@ -873,7 +864,7 @@ public Material.COLORS bufferGuessVertexColorType () return null; } - public boolean bufferGuessUVType () + public boolean bufferGuessUVType() { if(this instanceof HasMap && ((HasMap)this).getMap() != null) return true; diff --git a/src/thothbot/parallax/core/shared/materials/MeshBasicMaterial.java b/src/thothbot/parallax/core/shared/materials/MeshBasicMaterial.java index e959baba..12f40923 100644 --- a/src/thothbot/parallax/core/shared/materials/MeshBasicMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/MeshBasicMaterial.java @@ -86,15 +86,6 @@ public Shader getAssociatedShader() { return new BasicShader(); } - - public Material.SHADING bufferGuessNormalType () - { - // only MeshBasicMaterial and MeshDepthMaterial don't need normals - if (this.envMap == null) - return null; - - return super.bufferGuessNormalType(); - } @Override public boolean isWireframe() { diff --git a/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java b/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java index 0f63ac13..fff28a8d 100644 --- a/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java @@ -137,14 +137,6 @@ public void setShininess(double shininess) { this.shininess = shininess; } -// public boolean isPerPixel() { -// return this.isPerPixel; -// } -// -// public void setPerPixel(boolean isPerPixel) { -// this.isPerPixel = isPerPixel; -// } - public boolean isMetal() { return this.isMetal; } diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index 8bb99c70..634ca9b4 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -518,10 +518,6 @@ public void initBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup) int nlines = faces3.size() * 3; Material material = Material.getBufferMaterial(this, geometryGroup); - - boolean uvType = material.bufferGuessUVType(); - Material.SHADING normalType = material.bufferGuessNormalType(); - Material.COLORS vertexColorType = material.bufferGuessVertexColorType(); geometryGroup.__vertexArray = Float32Array.create( nvertices * 3 ); geometryGroup.__normalArray = Float32Array.create( nvertices * 3 ); @@ -736,7 +732,7 @@ public void setBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup, Bu return; boolean needsSmoothNormals = material.materialNeedsSmoothNormals(); - + int vertexIndex = 0, offset = 0, diff --git a/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java b/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java index 2fa5bffb..b20fd004 100644 --- a/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java +++ b/src/thothbot/parallax/core/shared/objects/MorphAnimMesh.java @@ -174,13 +174,11 @@ public void playAnimation( String label, int fps ) } } - public void updateAnimation( int delta ) + public void updateAnimation( double delta ) { -// if(this.getGeometry() == null) -// return; + if(this.getGeometry() == null) + return; -// delta = 8; - double frameTime = (double)this.duration / this.length; this.time += this.direction * delta; From 32649243c7c79116c8da0a5cc2331ba5191d5b7c Mon Sep 17 00:00:00 2001 From: thothbot Date: Wed, 11 Feb 2015 02:36:05 +0300 Subject: [PATCH 33/75] Updated sprite plugin --- .../parallax/plugins/sprite/Sprite.java | 282 ++++++------------ .../plugins/sprite/SpriteMaterial.java | 100 +++++++ .../parallax/plugins/sprite/SpritePlugin.java | 278 ++++++++--------- .../plugins/sprite/shaders/SpriteShader.java | 11 +- .../plugins/sprite/shaders/source/sprite.fs | 33 +- .../plugins/sprite/shaders/source/sprite.vs | 23 +- 6 files changed, 372 insertions(+), 355 deletions(-) create mode 100644 src/thothbot/parallax/plugins/sprite/SpriteMaterial.java diff --git a/src/thothbot/parallax/plugins/sprite/Sprite.java b/src/thothbot/parallax/plugins/sprite/Sprite.java index afb2dbe8..2b80398d 100644 --- a/src/thothbot/parallax/plugins/sprite/Sprite.java +++ b/src/thothbot/parallax/plugins/sprite/Sprite.java @@ -18,237 +18,125 @@ package thothbot.parallax.plugins.sprite; -import thothbot.parallax.core.client.gl2.enums.BlendEquationMode; -import thothbot.parallax.core.client.gl2.enums.BlendingFactorDest; -import thothbot.parallax.core.client.gl2.enums.BlendingFactorSrc; -import thothbot.parallax.core.client.textures.Texture; -import thothbot.parallax.core.shared.core.Object3D; +import java.util.List; + +import thothbot.parallax.core.client.gl2.arrays.Float32Array; +import thothbot.parallax.core.client.gl2.arrays.Uint16Array; +import thothbot.parallax.core.client.renderers.WebGLGeometry; +import thothbot.parallax.core.client.renderers.WebGLRenderer; +import thothbot.parallax.core.shared.core.AbstractGeometry; +import thothbot.parallax.core.shared.core.BufferAttribute; +import thothbot.parallax.core.shared.core.BufferGeometry; +import thothbot.parallax.core.shared.core.GeometryObject; +import thothbot.parallax.core.shared.core.Raycaster; +import thothbot.parallax.core.shared.core.Raycaster.Intersect; import thothbot.parallax.core.shared.materials.Material; -import thothbot.parallax.core.shared.math.Color; -import thothbot.parallax.core.shared.math.Euler; -import thothbot.parallax.core.shared.math.Vector2; +import thothbot.parallax.core.shared.math.Vector3; -public class Sprite extends Object3D implements Comparable +public class Sprite extends GeometryObject implements Comparable { - /* - * Alignment - */ - public static enum ALIGNMENT - { - TOP_LEFT(1, -1), - TOP_CENTER(0, -1), - TOP_RIGHT(-1, -1), - CENTER_LEFT(1, 0), - CENTER(0, 0), - CENTER_RIGHT(-1, 0), - BOTTOM_LEFT(1, 1), - BOTTOM_CENTER(0, 1), - BOTTOM_RIGHT(-1, 1); - - double x, y; - ALIGNMENT(double x, double y) { - this.x = x; - this.y = y; - } + private static SpriteMaterial defaultMaterial = new SpriteMaterial(); + + private static BufferGeometry defaultGeometry = new BufferGeometry(); + static { + Uint16Array indices = Uint16Array.create( + 0, 1, 2, + 0, 2, 3 ); + Float32Array vertices = Float32Array.create( + - 0.5, - 0.5, 0, + 0.5, - 0.5, 0, + 0.5, 0.5, 0, + - 0.5, 0.5, 0); + Float32Array uvs = Float32Array.create( + 0, 0, + 1, 0, + 1, 1, + 0, 1); - public Vector2 get() { - return new Vector2(this.x, this.y); - } - } - - private Color color; - private Euler rotation3d; - private Texture map; - - private Material.BLENDING blending = Material.BLENDING.NORMAL; - private BlendingFactorSrc blendSrc = BlendingFactorSrc.SRC_ALPHA; - private BlendingFactorDest blendDst = BlendingFactorDest.ONE_MINUS_SRC_ALPHA; - private BlendEquationMode blendEquation = BlendEquationMode.FUNC_ADD; - - private boolean useScreenCoordinates = true; - private boolean mergeWith3D; - private boolean affectedByDistance; - private boolean scaleByViewport; - - private Sprite.ALIGNMENT alignment = Sprite.ALIGNMENT.CENTER; - - private Vector2 uvOffset; - private Vector2 uvScale; - - private double opacity = 1.0; - - private double rotationFactor; + defaultGeometry.addAttribute( "index", new BufferAttribute( indices, 1 ) ); + defaultGeometry.addAttribute( "position", new BufferAttribute( vertices, 3 ) ); + defaultGeometry.addAttribute( "uv", new BufferAttribute( uvs, 2 ) ); + }; - private double z; + double z; public Sprite() { - this.color = new Color( 0xffffff ); - this.map = new Texture(); - - this.mergeWith3D = !this.useScreenCoordinates; - this.affectedByDistance = !this.useScreenCoordinates; - this.scaleByViewport = !this.affectedByDistance; - - this.rotation3d = this.getRotation(); - this.rotationFactor = 0; - - this.uvOffset = new Vector2( 0, 0 ); - this.uvScale = new Vector2( 1, 1 ); + this(defaultMaterial); } - public Color getColor() { - return color; - } - - public void setColor(Color color) { - this.color = color; - } - - public Texture getMap() { - return map; - } - - public void setMap(Texture map) { - this.map = map; - } - - public Material.BLENDING getBlending() { - return blending; - } - - public void setBlending(Material.BLENDING blending) { - this.blending = blending; - } - - public BlendingFactorSrc getBlendSrc() { - return blendSrc; - } - - public void setBlendSrc(BlendingFactorSrc blendSrc) { - this.blendSrc = blendSrc; - } - - public BlendingFactorDest getBlendDst() { - return blendDst; - } - - public void setBlendDst(BlendingFactorDest blendDst) { - this.blendDst = blendDst; - } - - public BlendEquationMode getBlendEquation() { - return blendEquation; - } - - public void setBlendEquation(BlendEquationMode blendEquation) { - this.blendEquation = blendEquation; - } - - public Sprite.ALIGNMENT getAlignment() { - return alignment; - } - - public void setAlignment(Sprite.ALIGNMENT alignment) { - this.alignment = alignment; + public Sprite(SpriteMaterial material) + { + this(defaultGeometry, material); } - - public Vector2 getUvOffset() { - return uvOffset; + + public Sprite(AbstractGeometry geometry, Material material) + { + super(geometry, material); } - - public void setUvOffset(Vector2 uvOffset) { - this.uvOffset = uvOffset; + + public double getZ() { + return z; } - public Vector2 getUvScale() { - return uvScale; + public void setZ(double z) { + this.z = z; } + + @Override + public void raycast(Raycaster raycaster, List intersects) { + Vector3 matrixPosition = new Vector3(); + + matrixPosition.setFromMatrixPosition( this.matrixWorld ); - public void setUvScale(Vector2 uvScale) { - this.uvScale = uvScale; - } + double distance = raycaster.getRay().distanceToPoint( matrixPosition ); - public double getOpacity() { - return opacity; - } + if ( distance > this.scale.getX() ) { - public void setOpacity(double opacity) { - this.opacity = opacity; - } + return; - public double getRotationFactor() { - return rotationFactor; - } + } - public void setRotationFactor(double rotation) { - this.rotationFactor = rotation; + Raycaster.Intersect intersect = new Raycaster.Intersect(); + intersect.distance = distance; + intersect.point = this.position; + intersect.object = this; + intersects.add( intersect ); + } - public boolean isUseScreenCoordinates() { - return useScreenCoordinates; - } - - public void setUseScreenCoordinates(boolean useScreenCoordinates) { - this.useScreenCoordinates = useScreenCoordinates; - } - - public boolean isMergeWith3D() { - return mergeWith3D; + @Override + public void renderBuffer(WebGLRenderer renderer, + WebGLGeometry geometryBuffer, boolean updateBuffers) { + // TODO Auto-generated method stub + } - public void setMergeWith3D(boolean mergeWith3D) { - this.mergeWith3D = mergeWith3D; - } - - public boolean isAffectedByDistance() { - return affectedByDistance; - } + public Sprite clone() + { - public void setAffectedByDistance(boolean affectedByDistance) { - this.affectedByDistance = affectedByDistance; - } + Sprite object = new Sprite( (SpriteMaterial) this.material ); - public boolean isScaleByViewport() { - return scaleByViewport; - } + super.clone( object ); - public void setScaleByViewport(boolean scaleByViewport) { - this.scaleByViewport = scaleByViewport; - } + return object; - public double getZ() { - return z; } + + @Override + public int compareTo(Sprite b) + { + Sprite a = this; + if ( a.z != b.z ) { - public void setZ(double z) { - this.z = z; - } + return (int) (b.z - a.z); - /* - * Custom update matrix - */ - public void updateMatrix() - { - this.matrix.setPosition( this.position ); + } else { - this.rotation3d.set( 0.0, 0.0, this.rotationFactor ); - this.matrix.makeRotationFromEuler( this.rotation3d ); + return b.id - a.id; - if ( this.scale.getX() != 1 || this.scale.getY() != 1 ) - { - this.matrix.scale( this.scale ); -// this.boundRadiusScale = Math.max( this.scale.getX(), this.scale.getY() ); } - this.matrixWorldNeedsUpdate = true; - } - - @Override - public int compareTo(Sprite o) - { - double result = o.z - this.z; - return (result == 0) ? 0 - : (result > 0) ? 1 : -1; } + } diff --git a/src/thothbot/parallax/plugins/sprite/SpriteMaterial.java b/src/thothbot/parallax/plugins/sprite/SpriteMaterial.java new file mode 100644 index 00000000..e36d6556 --- /dev/null +++ b/src/thothbot/parallax/plugins/sprite/SpriteMaterial.java @@ -0,0 +1,100 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.plugins.sprite; + +import thothbot.parallax.core.client.shaders.Shader; +import thothbot.parallax.core.client.textures.Texture; +import thothbot.parallax.core.shared.materials.HasColor; +import thothbot.parallax.core.shared.materials.Material; +import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.plugins.sprite.shaders.SpriteShader; + +public class SpriteMaterial extends Material implements HasColor { + + private Color color; + + private Texture map; + + private double rotation = 0; + + private boolean isFog = false; + + public SpriteMaterial() + { + setColor(new Color(0xffffff)); + } + + @Override + protected Shader getAssociatedShader() + { + return null; + } + + @Override + public Color getColor() { + return this.color; + } + + @Override + public void setColor(Color color) { + this.color = color; + + } + + public Texture getMap() { + return map; + } + + public void setMap(Texture map) { + this.map = map; + } + + public double getRotation() { + return rotation; + } + + public void setRotation(double rotation) { + this.rotation = rotation; + } + + public boolean isFog() { + return isFog; + } + + public void setFog(boolean isFog) { + this.isFog = isFog; + } + + @Override + public SpriteMaterial clone() + { + SpriteMaterial material = new SpriteMaterial(); + + super.clone( material ); + + material.color.copy( this.color ); + material.map = this.map; + + material.rotation = this.rotation; + + material.isFog = this.isFog; + + return material; + } +} diff --git a/src/thothbot/parallax/plugins/sprite/SpritePlugin.java b/src/thothbot/parallax/plugins/sprite/SpritePlugin.java index 33ca2a3c..d774bfaf 100644 --- a/src/thothbot/parallax/plugins/sprite/SpritePlugin.java +++ b/src/thothbot/parallax/plugins/sprite/SpritePlugin.java @@ -39,68 +39,60 @@ import thothbot.parallax.core.client.shaders.Uniform; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.lights.Light; +import thothbot.parallax.core.shared.math.Quaternion; +import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.scenes.AbstractFog; +import thothbot.parallax.core.shared.scenes.Fog; +import thothbot.parallax.core.shared.scenes.FogExp2; import thothbot.parallax.core.shared.scenes.Scene; import thothbot.parallax.plugins.sprite.shaders.SpriteShader; public final class SpritePlugin extends Plugin { - private class SpriteGeometry - { - Float32Array vertices; - Uint16Array faces; - - WebGLBuffer vertexBuffer; - WebGLBuffer elementBuffer; - - SpriteShader shader; - - boolean attributesEnabled; - } - - private SpriteGeometry sprite; private List objects; + Float32Array vertices; + Uint16Array faces; + + WebGLBuffer vertexBuffer; + WebGLBuffer elementBuffer; + + SpriteShader shader; + + // decompose matrixWorld + + Vector3 spritePosition = new Vector3(); + Quaternion spriteRotation = new Quaternion(); + Vector3 spriteScale = new Vector3(); + public SpritePlugin(WebGLRenderer renderer, Scene scene) { super(renderer, scene); - - this.sprite = new SpriteGeometry(); - + WebGLRenderingContext gl = getRenderer().getGL(); - sprite.vertices = Float32Array.create( 8 + 8 ); - sprite.faces = Uint16Array.create( 6 ); + vertices = Float32Array.create( + - 0.5, - 0.5, 0, 0, + 0.5, - 0.5, 1, 0, + 0.5, 0.5, 1, 1, + - 0.5, 0.5, 0, 1 + ); + faces = Uint16Array.create( + 0, 1, 2, + 0, 2, 3 + ); - int i = 0; - - sprite.vertices.set( i++, -1); sprite.vertices.set( i++, -1); // vertex 0 - sprite.vertices.set( i++, 0); sprite.vertices.set( i++, 1); // uv 0 - - sprite.vertices.set( i++, 1); sprite.vertices.set( i++, -1); // vertex 1 - sprite.vertices.set( i++, 1); sprite.vertices.set( i++, 1); // uv 1 + vertexBuffer = gl.createBuffer(); + elementBuffer = gl.createBuffer(); - sprite.vertices.set( i++, 1); sprite.vertices.set( i++, 1); // vertex 2 - sprite.vertices.set( i++, 1); sprite.vertices.set( i++, 0); // uv 2 + gl.bindBuffer( BufferTarget.ARRAY_BUFFER, vertexBuffer ); + gl.bufferData( BufferTarget.ARRAY_BUFFER, vertices, BufferUsage.STATIC_DRAW ); - sprite.vertices.set( i++, -1); sprite.vertices.set( i++, 1); // vertex 3 - sprite.vertices.set( i++, 0); sprite.vertices.set( i++, 0); // uv 3 + gl.bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, elementBuffer ); + gl.bufferData( BufferTarget.ELEMENT_ARRAY_BUFFER, faces, BufferUsage.STATIC_DRAW ); - i = 0; - - sprite.faces.set( i++, 0); sprite.faces.set( i++, 1); sprite.faces.set( i++, 2); - sprite.faces.set( i++, 0); sprite.faces.set( i++, 2); sprite.faces.set( i++, 3); - - sprite.vertexBuffer = gl.createBuffer(); - sprite.elementBuffer = gl.createBuffer(); - - gl.bindBuffer( BufferTarget.ARRAY_BUFFER, sprite.vertexBuffer ); - gl.bufferData( BufferTarget.ARRAY_BUFFER, sprite.vertices, BufferUsage.STATIC_DRAW ); - - gl.bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, sprite.elementBuffer ); - gl.bufferData( BufferTarget.ELEMENT_ARRAY_BUFFER, sprite.faces, BufferUsage.STATIC_DRAW ); - - sprite.shader = new SpriteShader(); - sprite.shader.buildProgram(gl); + shader = new SpriteShader(); + shader.buildProgram(gl); } @Override @@ -111,7 +103,7 @@ public Plugin.TYPE getType() public List getObjects() { - if(this.objects == null) + if(this.objects == null || this.objects.size() == 0) { this.objects = (List)(ArrayList)getScene().getChildrenByClass(Sprite.class, true); } @@ -129,42 +121,65 @@ public void render( Camera camera, List lights, int viewportWidth, int vi WebGLRenderingContext gl = getRenderer().getGL(); - Map uniforms = this.sprite.shader.getUniforms(); - Map attributesLocations = this.sprite.shader.getAttributesLocations(); - - double invAspect = (double)viewportHeight / viewportWidth; - - double halfViewportWidth = viewportWidth * 0.5; - double halfViewportHeight = viewportHeight * 0.5; - - boolean mergeWith3D = true; + Map uniforms = this.shader.getUniforms(); + Map attributesLocations = this.shader.getAttributesLocations(); // setup gl - gl.useProgram( this.sprite.shader.getProgram() ); + gl.useProgram( this.shader.getProgram() ); - if ( ! sprite.attributesEnabled ) - { - gl.enableVertexAttribArray( attributesLocations.get("position") ); - gl.enableVertexAttribArray( attributesLocations.get("uv") ); - - sprite.attributesEnabled = true; - } + gl.enableVertexAttribArray( attributesLocations.get("position") ); + gl.enableVertexAttribArray( attributesLocations.get("uv") ); gl.disable( EnableCap.CULL_FACE ); gl.enable( EnableCap.BLEND ); - gl.depthMask( true ); - gl.bindBuffer( BufferTarget.ARRAY_BUFFER, sprite.vertexBuffer ); + gl.bindBuffer( BufferTarget.ARRAY_BUFFER, vertexBuffer ); gl.vertexAttribPointer( attributesLocations.get("position"), 2, DataType.FLOAT, false, 2 * 8, 0 ); gl.vertexAttribPointer( attributesLocations.get("uv"), 2, DataType.FLOAT, false, 2 * 8, 8 ); - gl.bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, sprite.elementBuffer ); + gl.bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, elementBuffer ); gl.uniformMatrix4fv( uniforms.get("projectionMatrix").getLocation(), false, camera.getProjectionMatrix().getArray() ); gl.activeTexture( TextureUnit.TEXTURE0 ); gl.uniform1i( uniforms.get("map").getLocation(), 0 ); + + int oldFogType = 0; + int sceneFogType = 0; + AbstractFog fog = scene.getFog(); + + if ( fog != null ) { + + gl.uniform3f( uniforms.get("fogColor").getLocation(), fog.getColor().getR(), fog.getColor().getG(), fog.getColor().getB() ); + + if ( fog instanceof Fog ) { + + gl.uniform1f( uniforms.get("fogNear").getLocation(), ((Fog)fog).getNear() ); + gl.uniform1f( uniforms.get("fogFar").getLocation(), ((Fog)fog).getFar() ); + + gl.uniform1i( uniforms.get("fogType").getLocation(), 1 ); + oldFogType = 1; + sceneFogType = 1; + + } else if ( fog instanceof FogExp2 ) { + + gl.uniform1f( uniforms.get("fogDensity").getLocation(), ((FogExp2)fog).getDensity() ); + + gl.uniform1i( uniforms.get("fogType").getLocation(), 2 ); + oldFogType = 2; + sceneFogType = 2; + + } + + } else { + + gl.uniform1i( uniforms.get("fogType").getLocation(), 0 ); + oldFogType = 0; + sceneFogType = 0; + + } + // update positions and sort @@ -172,17 +187,10 @@ public void render( Camera camera, List lights, int viewportWidth, int vi { Sprite sprite = sprites.get( i ); - if ( ! sprite.isVisible() || sprite.getOpacity() == 0 ) continue; + if ( ! sprite.isVisible() ) continue; - if( ! sprite.isUseScreenCoordinates() ) - { - sprite._modelViewMatrix.multiply( camera.getMatrixWorldInverse(), sprite.getMatrixWorld()); - sprite.setZ( - sprite._modelViewMatrix.getArray().get(14) ); - } - else - { - sprite.setZ( - sprite.getPosition().getZ() ); - } + sprite._modelViewMatrix.multiply( camera.getMatrixWorldInverse(), sprite.getMatrixWorld()); + sprite.setZ( - sprite._modelViewMatrix.getArray().get(14) ); } Collections.sort((List)(ArrayList)sprites); @@ -192,71 +200,71 @@ public void render( Camera camera, List lights, int viewportWidth, int vi for( int i = 0; i < nSprites; i ++ ) { Sprite sprite = sprites.get( i ); + SpriteMaterial material = (SpriteMaterial) sprite.getMaterial(); + + if ( ! sprite.isVisible() ) continue; + + gl.uniform1f( uniforms.get("alphaTest").getLocation(), material.getAlphaTest() ); + gl.uniformMatrix4fv( uniforms.get("modelViewMatrix").getLocation(), false, sprite._modelViewMatrix.getArray()); + + sprite.getMatrixWorld().decompose( spritePosition, spriteRotation, spriteScale ); + + int fogType = 0; + + if ( scene.getFog() != null && material.isFog() ) { + + fogType = sceneFogType; + + } + + if ( oldFogType != fogType ) { + + gl.uniform1i( uniforms.get("fogType").getLocation(), fogType ); + oldFogType = fogType; - if ( ! sprite.isVisible() || sprite.getOpacity() == 0 ) continue; - - if ( sprite.getMap() != null - && sprite.getMap().getImage() != null - && sprite.getMap().getImage().getOffsetWidth() > 0 ) - { - if ( sprite.isUseScreenCoordinates() ) - { - gl.uniform1i( uniforms.get("useScreenCoordinates").getLocation(), 1 ); - gl.uniform3f( uniforms.get("screenPosition").getLocation(), ( sprite.getPosition().getX() - halfViewportWidth ) / halfViewportWidth, - ( halfViewportHeight - sprite.getPosition().getY() ) / halfViewportHeight, - Math.max( 0, Math.min( 1, sprite.getPosition().getZ() ) ) ); - } - else - { - gl.uniform1i( uniforms.get("useScreenCoordinates").getLocation(), 0 ); - gl.uniform1i( uniforms.get("affectedByDistance").getLocation(), sprite.isAffectedByDistance() ? 1 : 0 ); - gl.uniformMatrix4fv( uniforms.get("modelViewMatrix").getLocation(), false, sprite._modelViewMatrix.getArray()); - } - - double size = sprite.getMap().getImage().getOffsetWidth() - / ( sprite.isScaleByViewport() ? viewportHeight : 1.0 ); - - double[] scale = { - size * invAspect * sprite.getScale().getX(), - size * sprite.getScale().getY() }; - - gl.uniform2f( uniforms.get("uvScale").getLocation(), sprite.getUvScale().getX(), sprite.getUvScale().getY() ); - gl.uniform2f( uniforms.get("uvOffset").getLocation(), sprite.getUvOffset().getX(), sprite.getUvOffset().getY() ); - gl.uniform2f( uniforms.get("alignment").getLocation(), sprite.getAlignment().get().getX(), sprite.getAlignment().get().getY() ); - - gl.uniform1f( uniforms.get("opacity").getLocation(), sprite.getOpacity() ); - gl.uniform3f( uniforms.get("color").getLocation(), - sprite.getColor().getR(), - sprite.getColor().getG(), - sprite.getColor().getB() ); - - gl.uniform1f( uniforms.get("rotation").getLocation(), sprite.getRotationFactor() ); - gl.uniform2fv( uniforms.get("scale").getLocation(), scale ); - - if ( sprite.isMergeWith3D() && !mergeWith3D ) - { - gl.enable( EnableCap.DEPTH_TEST ); - mergeWith3D = true; - } - else if ( ! sprite.isMergeWith3D() && mergeWith3D ) - { - gl.disable( EnableCap.DEPTH_TEST ); - mergeWith3D = false; - } - - // renderer.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst ); - getRenderer().setBlending( sprite.getBlending() ); - getRenderer().setTexture( sprite.getMap(), 0 ); - - gl.drawElements( BeginMode.TRIANGLES, 6, DrawElementsType.UNSIGNED_SHORT, 0 ); } + + if ( material.getMap() != null + && material.getMap().getImage() != null + && material.getMap().getImage().getOffsetWidth() > 0 ) { + + gl.uniform2f( uniforms.get("uvOffset").getLocation(), material.getMap().getOffset().getX(), material.getMap().getOffset().getY() ); + gl.uniform2f( uniforms.get("uvScale").getLocation(), material.getMap().getRepeat().getX(), material.getMap().getRepeat().getY() ); + + } else { + + gl.uniform2f( uniforms.get("uvOffset").getLocation(), 0.0, 0.0 ); + gl.uniform2f( uniforms.get("uvScale").getLocation(), 1.0, 1.0 ); + + } + + gl.uniform1f( uniforms.get("opacity").getLocation(), material.getOpacity() ); + gl.uniform3f( uniforms.get("color").getLocation(), + material.getColor().getR(), material.getColor().getG(), material.getColor().getB() ); + + gl.uniform1f( uniforms.get("rotation").getLocation(), material.getRotation() ); + gl.uniform2fv( uniforms.get("scale").getLocation(), new double[]{spriteScale.getX(), spriteScale.getY()} ); + + // renderer.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst ); + getRenderer().setBlending( material.getBlending() ); + getRenderer().setDepthTest( material.isDepthTest() ); + getRenderer().setDepthWrite( material.isDepthWrite() ); + + + if ( material.getMap() != null + && material.getMap().getImage() != null + && material.getMap().getImage().getOffsetWidth() > 0 ) { + + getRenderer().setTexture( material.getMap(), 0 ); + } + + gl.drawElements( BeginMode.TRIANGLES, 6, DrawElementsType.UNSIGNED_SHORT, 0 ); } // restore gl gl.enable( EnableCap.CULL_FACE ); - gl.enable( EnableCap.DEPTH_TEST ); - gl.depthMask( true ); + getRenderer().resetGLState(); } } diff --git a/src/thothbot/parallax/plugins/sprite/shaders/SpriteShader.java b/src/thothbot/parallax/plugins/sprite/shaders/SpriteShader.java index 566aead4..c331261d 100644 --- a/src/thothbot/parallax/plugins/sprite/shaders/SpriteShader.java +++ b/src/thothbot/parallax/plugins/sprite/shaders/SpriteShader.java @@ -54,14 +54,17 @@ protected void initUniforms() this.addUniform("rotation", new Uniform(Uniform.TYPE.F, 1.0 )); this.addUniform("scale", new Uniform(Uniform.TYPE.V2, new Vector2( 1.0, 1.0 ) )); - this.addUniform("alignment", new Uniform(Uniform.TYPE.V2, new Vector2( 0.0, 0.0 ) )); this.addUniform("color", new Uniform(Uniform.TYPE.C, new Color( 0xffffff ) )); this.addUniform("map", new Uniform(Uniform.TYPE.T) ); this.addUniform("opacity", new Uniform(Uniform.TYPE.F, 1.0 )); + + this.addUniform("fogType", new Uniform(Uniform.TYPE.I, 0 )); + this.addUniform("fogDensity", new Uniform(Uniform.TYPE.F, 0.00025 )); + this.addUniform("fogNear", new Uniform(Uniform.TYPE.F, 1.0 )); + this.addUniform("fogFar", new Uniform(Uniform.TYPE.F, 2000.0 )); + this.addUniform("fogColor", new Uniform(Uniform.TYPE.C, new Color( 0xffffff ))); - this.addUniform("useScreenCoordinates", new Uniform(Uniform.TYPE.I, 1 )); - this.addUniform("affectedByDistance", new Uniform(Uniform.TYPE.I, 1 )); - this.addUniform("screenPosition", new Uniform(Uniform.TYPE.V3, new Vector3( 0.0, 0.0, 0.0 ) )); + this.addUniform("alphaTest", new Uniform(Uniform.TYPE.F, 0 )); } } diff --git a/src/thothbot/parallax/plugins/sprite/shaders/source/sprite.fs b/src/thothbot/parallax/plugins/sprite/shaders/source/sprite.fs index b5c39924..9e8bf598 100644 --- a/src/thothbot/parallax/plugins/sprite/shaders/source/sprite.fs +++ b/src/thothbot/parallax/plugins/sprite/shaders/source/sprite.fs @@ -1,14 +1,43 @@ -precision mediump float; - uniform vec3 color; uniform sampler2D map; uniform float opacity; +uniform int fogType; +uniform vec3 fogColor; +uniform float fogDensity; +uniform float fogNear; +uniform float fogFar; +uniform float alphaTest; + varying vec2 vUV; void main() { vec4 texture = texture2D( map, vUV ); + + if ( texture.a < alphaTest ) discard; + gl_FragColor = vec4( color * texture.xyz, texture.a * opacity ); + if ( fogType > 0 ) { + + float depth = gl_FragCoord.z / gl_FragCoord.w; + float fogFactor = 0.0; + + if ( fogType == 1 ) { + + fogFactor = smoothstep( fogNear, fogFar, depth ); + + } else { + + const float LOG2 = 1.442695; + float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 ); + fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 ); + + } + + gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor ); + + } + } diff --git a/src/thothbot/parallax/plugins/sprite/shaders/source/sprite.vs b/src/thothbot/parallax/plugins/sprite/shaders/source/sprite.vs index 216a44b2..83ae825a 100644 --- a/src/thothbot/parallax/plugins/sprite/shaders/source/sprite.vs +++ b/src/thothbot/parallax/plugins/sprite/shaders/source/sprite.vs @@ -1,11 +1,7 @@ -uniform int useScreenCoordinates; -uniform int affectedByDistance; -uniform vec3 screenPosition; uniform mat4 modelViewMatrix; uniform mat4 projectionMatrix; uniform float rotation; uniform vec2 scale; -uniform vec2 alignment; uniform vec2 uvOffset; uniform vec2 uvScale; @@ -18,24 +14,17 @@ void main() { vUV = uvOffset + uv * uvScale; - vec2 alignedPosition = position + alignment; + vec2 alignedPosition = position * scale; vec2 rotatedPosition; - rotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x; - rotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y; + rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y; + rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y; vec4 finalPosition; - if( useScreenCoordinates != 0 ) { - - finalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 ); - - } else { - - finalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 ); - finalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z ); - - } + finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 ); + finalPosition.xy += rotatedPosition; + finalPosition = projectionMatrix * finalPosition; gl_Position = finalPosition; From 152ba1a21c8b99f66f8af46340a5bb1244764c41 Mon Sep 17 00:00:00 2001 From: thothbot Date: Wed, 11 Feb 2015 02:52:13 +0300 Subject: [PATCH 34/75] Some fixed in plugins --- .../core/client/renderers/WebGLRenderer.java | 18 +++++++++++------- .../core/shared/core/GeometryObject.java | 4 ++-- .../parallax/core/shared/objects/Mesh.java | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index 365a95cb..ed2ad5e1 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -113,6 +113,7 @@ import thothbot.parallax.core.shared.scenes.AbstractFog; import thothbot.parallax.core.shared.scenes.FogExp2; import thothbot.parallax.core.shared.scenes.Scene; +import thothbot.parallax.plugins.postprocessing.Postprocessing; import com.google.gwt.canvas.dom.client.Context2d; import com.google.gwt.core.client.GWT; @@ -1796,9 +1797,9 @@ public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget public void render( Scene scene, Camera camera, RenderTargetTexture renderTarget, boolean forceClear ) { // Render basic plugins - if(renderPlugins( this.plugins, camera, Plugin.TYPE.BASIC_RENDER )) + if(renderPlugins( this.plugins, scene, camera, Plugin.TYPE.BASIC_RENDER )) return; - + Log.debug("Called render()"); AbstractFog fog = scene.getFog(); @@ -1874,7 +1875,7 @@ public int compare(WebGLObject a, WebGLObject b) { } // custom render plugins (pre pass) - renderPlugins( this.plugins, camera, Plugin.TYPE.PRE_RENDER ); + renderPlugins( this.plugins, scene, camera, Plugin.TYPE.PRE_RENDER ); this.getInfo().getRender().calls = 0; this.getInfo().getRender().vertices = 0; @@ -1939,7 +1940,7 @@ public int compare(WebGLObject a, WebGLObject b) { } // custom render plugins (post pass) - renderPlugins( this.plugins, camera, Plugin.TYPE.POST_RENDER ); + renderPlugins( this.plugins, scene, camera, Plugin.TYPE.POST_RENDER ); // Generate mipmap if we're using any kind of mipmap filtering if ( renderTarget != null && renderTarget.isGenerateMipmaps() @@ -2019,7 +2020,7 @@ public void renderImmediateObject( Camera camera, List lights, AbstractFo } - private boolean renderPlugins( List plugins, Camera camera, Plugin.TYPE type ) + private boolean renderPlugins( List plugins, Scene scene, Camera camera, Plugin.TYPE type ) { if ( plugins.size() == 0 ) return false; @@ -2029,9 +2030,12 @@ private boolean renderPlugins( List plugins, Camera camera, Plugin.TYPE { Plugin plugin = plugins.get( i ); - if( ! plugin.isEnabled() || plugin.isRendering() || plugin.getType() != type ) + if( ! plugin.isEnabled() + || plugin.isRendering() + || plugin.getType() != type + || ( !(plugin instanceof Postprocessing) && !plugin.getScene().equals(scene))) continue; - + plugin.setRendering(true); Log.debug("Called renderPlugins(): " + plugin.getClass().getName()); diff --git a/src/thothbot/parallax/core/shared/core/GeometryObject.java b/src/thothbot/parallax/core/shared/core/GeometryObject.java index f1f21bc9..fa147969 100644 --- a/src/thothbot/parallax/core/shared/core/GeometryObject.java +++ b/src/thothbot/parallax/core/shared/core/GeometryObject.java @@ -34,9 +34,9 @@ public abstract class GeometryObject extends Object3D { - private AbstractGeometry geometry; + protected AbstractGeometry geometry; // protected GeometryBuffer geometryBuffer; - private Material material; + protected Material material; // protected Material customDepthMaterial; private double _oldLineWidth = -1; diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index 634ca9b4..2e809645 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -579,6 +579,7 @@ public void initBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup) // custom attributes + Map attributes = material.getShader().getAttributes(); if (attributes != null) From dabd96433d9496222341106917cb6cda1a56e88f Mon Sep 17 00:00:00 2001 From: thothbot Date: Wed, 11 Feb 2015 19:34:53 +0300 Subject: [PATCH 35/75] Fixed issues in JSON Loader --- .../core/client/renderers/WebGLObject.java | 3 +- .../core/client/renderers/WebGLRenderer.java | 8 +-- .../parallax/core/shared/objects/Line.java | 2 +- .../parallax/core/shared/objects/Mesh.java | 2 +- .../core/shared/objects/PointCloud.java | 2 +- .../parallax/loader/shared/JsonLoader.java | 70 +++++++++++++------ .../loader/shared/json/JsoMaterial.java | 11 +++ .../postprocessing/Postprocessing.java | 2 +- 8 files changed, 70 insertions(+), 30 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLObject.java b/src/thothbot/parallax/core/client/renderers/WebGLObject.java index b7636ef6..aa0fbe0a 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLObject.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLObject.java @@ -20,6 +20,7 @@ import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.BufferGeometry; +import thothbot.parallax.core.shared.core.GeometryGroup; import thothbot.parallax.core.shared.core.GeometryObject; import thothbot.parallax.core.shared.materials.Material; import thothbot.parallax.core.shared.materials.MeshFaceMaterial; @@ -77,7 +78,7 @@ public void unrollBufferMaterial(WebGLRenderer renderer) if ( material instanceof MeshFaceMaterial ) { - int materialIndex = geometry instanceof BufferGeometry ? 0 : 0; //((BufferGeometry)buffer).; + int materialIndex = geometry instanceof BufferGeometry ? 0 : ((GeometryGroup)buffer).materialIndex; material = ((MeshFaceMaterial)material).getMaterials().get( materialIndex ); diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index ed2ad5e1..bdaad875 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -2150,11 +2150,11 @@ public void renderBuffer( Camera camera, List lights, AbstractFog fog, Ma int geometryGroupHash = ( geometry.getId() * 0xffffff ) + ( material.getShader().getId() * 2 ) + wireframeBit; -// GWT.log("--- renderBuffer() geometryGroupHash=" + geometryGroupHash +// Log.error("--- renderBuffer() geometryGroupHash=" + geometryGroupHash // + ", _currentGeometryGroupHash=" + this._currentGeometryGroupHash -// + ", program.id=" + program.id -// + ", geometryGroup.id=" + geometryBuffer.getId() -// + ", __webglLineCount=" + geometryBuffer.__webglLineCount +// + ", program.id=" + program.getId() +//// + ", geometryGroup.id=" + geometryBuffer.getId() +//// + ", __webglLineCount=" + geometryBuffer.__webglLineCount // + ", object.id=" + object.getId() // + ", wireframeBit=" + wireframeBit); diff --git a/src/thothbot/parallax/core/shared/objects/Line.java b/src/thothbot/parallax/core/shared/objects/Line.java index 31ba91d8..79f1661d 100644 --- a/src/thothbot/parallax/core/shared/objects/Line.java +++ b/src/thothbot/parallax/core/shared/objects/Line.java @@ -72,7 +72,7 @@ public static enum MODE private static LineBasicMaterial defaultMaterial = new LineBasicMaterial(); static { - defaultMaterial.setColor( new Color((int)Math.random() * 0xffffff) ); + defaultMaterial.setColor( new Color((int)(Math.random() * 0xffffff)) ); }; public Line() { diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index 2e809645..39f87c89 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -81,7 +81,7 @@ public class Mesh extends GeometryObject private static MeshBasicMaterial defaultMaterial = new MeshBasicMaterial(); static { - defaultMaterial.setColor( new Color((int) Math.random() * 0xffffff) ); + defaultMaterial.setColor( new Color((int)(Math.random() * 0xffffff)) ); defaultMaterial.setWireframe( true ); }; diff --git a/src/thothbot/parallax/core/shared/objects/PointCloud.java b/src/thothbot/parallax/core/shared/objects/PointCloud.java index 90352785..863e8dab 100644 --- a/src/thothbot/parallax/core/shared/objects/PointCloud.java +++ b/src/thothbot/parallax/core/shared/objects/PointCloud.java @@ -56,7 +56,7 @@ public class PointCloud extends GeometryObject private static PointCloudMaterial defaultMaterial = new PointCloudMaterial(); static { - defaultMaterial.setColor( new Color((int)Math.random() * 0xffffff) ); + defaultMaterial.setColor( new Color((int)(Math.random() * 0xffffff)) ); }; public PointCloud() { diff --git a/src/thothbot/parallax/loader/shared/JsonLoader.java b/src/thothbot/parallax/loader/shared/JsonLoader.java index 7198057f..3791ce5e 100644 --- a/src/thothbot/parallax/loader/shared/JsonLoader.java +++ b/src/thothbot/parallax/loader/shared/JsonLoader.java @@ -32,6 +32,7 @@ import thothbot.parallax.core.shared.core.Face3; import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.core.Geometry.MorphColor; +import thothbot.parallax.core.shared.materials.HasAlphaMap; import thothbot.parallax.core.shared.materials.HasAmbientEmissiveColor; import thothbot.parallax.core.shared.materials.HasBumpMap; import thothbot.parallax.core.shared.materials.HasColor; @@ -215,7 +216,6 @@ else if(jsonMaterial.getShading().compareToIgnoreCase("basic") == 0) } else if(material instanceof HasColor) { - ((HasColor) material).setColor(diffuseColor); } } @@ -248,6 +248,20 @@ else if( material instanceof HasAmbientEmissiveColor) } } + if(jsonMaterial.getColorEmissive() != null ) + { + Color color = getColor(jsonMaterial.getColorEmissive()); + if(material instanceof ShaderMaterial) + { + Map uniforms = material.getShader().getUniforms(); + uniforms.get( "emissive" ).setValue(color); + } + else if( material instanceof HasAmbientEmissiveColor) + { + ((HasAmbientEmissiveColor)material).setEmissive(color); + } + } + if(jsonMaterial.getTransparent()) { if(material instanceof ShaderMaterial) @@ -317,26 +331,6 @@ else if(material instanceof HasLightMap) } } - if ( jsonMaterial.getMapSpecular() != null) - { - Texture texture = create_texture(jsonMaterial.getMapSpecular(), - jsonMaterial.getMapSpecularRepeat(), - jsonMaterial.getMapSpecularOffset(), - jsonMaterial.getMapSpecularWrap(), - jsonMaterial.getMapSpecularAnisotropy()); - - if(material instanceof ShaderMaterial) - { - Map uniforms = material.getShader().getUniforms(); - uniforms.get( "tSpecular" ).setValue(texture); - uniforms.get( "enableSpecular" ).setValue(true); - } - else if( material instanceof HasSpecularMap ) - { - ((HasSpecularMap)material).setSpecularMap(texture); - } - } - if ( jsonMaterial.getMapBump() != null && material instanceof HasBumpMap) { ((HasBumpMap)material).setBumpMap( @@ -368,6 +362,40 @@ else if( material instanceof HasSpecularMap ) jsonMaterial.getMapNormalFactor(), jsonMaterial.getMapNormalFactor() ); } } + + if ( jsonMaterial.getMapSpecular() != null) + { + Texture texture = create_texture(jsonMaterial.getMapSpecular(), + jsonMaterial.getMapSpecularRepeat(), + jsonMaterial.getMapSpecularOffset(), + jsonMaterial.getMapSpecularWrap(), + jsonMaterial.getMapSpecularAnisotropy()); + + if(material instanceof ShaderMaterial) + { + Map uniforms = material.getShader().getUniforms(); + uniforms.get( "tSpecular" ).setValue(texture); + uniforms.get( "enableSpecular" ).setValue(true); + } + else if( material instanceof HasSpecularMap ) + { + ((HasSpecularMap)material).setSpecularMap(texture); + } + } + + if ( jsonMaterial.getMapAlpha() != null) + { + Texture texture = create_texture(jsonMaterial.getMapAlpha(), + jsonMaterial.getMapAlphaRepeat(), + jsonMaterial.getMapAlphaOffset(), + jsonMaterial.getMapAlphaWrap(), + jsonMaterial.getMapAlphaAnisotropy()); + + if( material instanceof HasAlphaMap ) + { + ((HasAlphaMap)material).setAlphaMap(texture); + } + } if(jsonMaterial.getDbgName() != null) { diff --git a/src/thothbot/parallax/loader/shared/json/JsoMaterial.java b/src/thothbot/parallax/loader/shared/json/JsoMaterial.java index df438383..2165f6a5 100644 --- a/src/thothbot/parallax/loader/shared/json/JsoMaterial.java +++ b/src/thothbot/parallax/loader/shared/json/JsoMaterial.java @@ -48,6 +48,11 @@ public interface JsoMaterial */ List getColorSpecular(); + /** + * List of R, G, B + */ + List getColorEmissive(); + double getIllumination(); double getOpticalDensity(); @@ -105,4 +110,10 @@ public interface JsoMaterial List getMapSpecularWrap(); int getMapSpecularAnisotropy(); List getMapSpecularOffset(); + + String getMapAlpha(); + List getMapAlphaRepeat(); + List getMapAlphaWrap(); + int getMapAlphaAnisotropy(); + List getMapAlphaOffset(); } diff --git a/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java b/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java index 67700968..9fe80667 100644 --- a/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java +++ b/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java @@ -143,7 +143,7 @@ public void render( Camera camera, List lights, int currentWidth, int cur for ( Pass pass : this.passes ) { - Log.error("Called pass", pass.getClass().getName() ); + Log.info("Postprocessing.render(): pass " + pass.getClass().getSimpleName() ); if ( !pass.isEnabled() ) continue; From da83e9c5520b60cdef16828fe553469261f01989 Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 13 Feb 2015 01:43:37 +0300 Subject: [PATCH 36/75] Some code refactoring --- .../core/client/renderers/WebGLRenderer.java | 69 ++++++------ .../client/shaders/ProgramParameters.java | 28 +++-- .../core/shared/core/AbstractGeometry.java | 100 +++++++++++++++--- .../core/shared/helpers/ArrowHelper.java | 5 +- .../core/shared/helpers/CameraHelper.java | 2 +- .../core/shared/materials/Material.java | 19 ++-- .../parallax/core/shared/objects/Line.java | 6 +- .../parallax/core/shared/objects/Mesh.java | 14 +-- .../core/shared/objects/PointCloud.java | 6 +- 9 files changed, 171 insertions(+), 78 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index bdaad875..a80ce36b 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -1425,13 +1425,13 @@ public void initGeometryGroups( Object3D scene, Mesh object, Geometry geometry ) Material material = object.getMaterial(); boolean addBuffers = false; - if ( GeometryGroup.geometryGroups.get( geometry.getId() + "" ) == null || geometry.groupsNeedUpdate == true ) { + if ( GeometryGroup.geometryGroups.get( geometry.getId() + "" ) == null || geometry.isGroupsNeedUpdate() ) { this._webglObjects.put(object.getId() + "", new ArrayList()); GeometryGroup.geometryGroups.put( geometry.getId() + "", makeGroups( geometry, material instanceof MeshFaceMaterial )); - geometry.groupsNeedUpdate = false; + geometry.setGroupsNeedUpdate( false ); } @@ -1450,13 +1450,13 @@ public void initGeometryGroups( Object3D scene, Mesh object, Geometry geometry ) ((Mesh)object).createBuffers(this, geometryGroup); ((Mesh)object).initBuffers(gl, geometryGroup); - geometry.verticesNeedUpdate = true; - geometry.morphTargetsNeedUpdate = true; - geometry.elementsNeedUpdate = true; - geometry.uvsNeedUpdate = true; - geometry.normalsNeedUpdate = true; - geometry.tangentsNeedUpdate = true; - geometry.colorsNeedUpdate = true; + geometry.setVerticesNeedUpdate( true ); + geometry.setMorphTargetsNeedUpdate( true ); + geometry.setElementsNeedUpdate( true ); + geometry.setUvsNeedUpdate( true ); + geometry.setNormalsNeedUpdate( true ); + geometry.setTangentsNeedUpdate( true ); + geometry.setColorsNeedUpdate( true ); addBuffers = true; @@ -1514,9 +1514,9 @@ private void initObject( Object3D object, Object3D scene ) { ((Line)object).createBuffers(this); ((Line)object).initBuffers(gl); - geometry.verticesNeedUpdate = true; - geometry.colorsNeedUpdate = true; - geometry.lineDistancesNeedUpdate = true; + geometry.setVerticesNeedUpdate( true ); + geometry.setColorsNeedUpdate( true ); + geometry.setLineDistancesNeedUpdate( true ); } @@ -1527,8 +1527,8 @@ private void initObject( Object3D object, Object3D scene ) { ((PointCloud)object).createBuffers(this); ((PointCloud)object).initBuffers(gl); - geometry.verticesNeedUpdate = true; - geometry.colorsNeedUpdate = true; + geometry.setVerticesNeedUpdate( true ); + geometry.setColorsNeedUpdate( true ); } @@ -1660,7 +1660,8 @@ private void projectObject( Object3D scene, Object3D object ) { } - public Material getBufferMaterial( GeometryObject object, GeometryGroup geometryGroup ) { + public Material getBufferMaterial( GeometryObject object, GeometryGroup geometryGroup ) + { return object.getMaterial() instanceof MeshFaceMaterial ? ((MeshFaceMaterial)object.getMaterial()).getMaterials().get( geometryGroup.materialIndex ) @@ -1689,7 +1690,7 @@ public void updateObject( GeometryObject object, Object3D scene ) // check all geometry groups - if ( geometry.groupsNeedUpdate == true ) { + if ( geometry.isGroupsNeedUpdate() ) { initGeometryGroups( scene, (Mesh)object, (Geometry)geometry ); @@ -1703,7 +1704,7 @@ public void updateObject( GeometryObject object, Object3D scene ) material = getBufferMaterial( object, geometryGroup ); - if ( geometry.groupsNeedUpdate == true ) { + if ( geometry.isGroupsNeedUpdate() ) { ((Mesh)object).initBuffers( gl, geometryGroup ); @@ -1711,9 +1712,9 @@ public void updateObject( GeometryObject object, Object3D scene ) boolean customAttributesDirty = (material instanceof ShaderMaterial) && ((ShaderMaterial)material).getShader().areCustomAttributesDirty(); - if ( geometry.verticesNeedUpdate || geometry.morphTargetsNeedUpdate || geometry.elementsNeedUpdate || - geometry.uvsNeedUpdate || geometry.normalsNeedUpdate || - geometry.colorsNeedUpdate || geometry.tangentsNeedUpdate || customAttributesDirty ) { + if ( geometry.isVerticesNeedUpdate() || geometry.isMorphTargetsNeedUpdate() || geometry.isElementsNeedUpdate() || + geometry.isUvsNeedUpdate() || geometry.isNormalsNeedUpdate() || + geometry.isColorsNeedUpdate() || geometry.isTangentsNeedUpdate() || customAttributesDirty ) { ((Mesh)object).setBuffers( gl, geometryGroup, BufferUsage.DYNAMIC_DRAW, ! ((Geometry)geometry).isDynamic(), material ); @@ -1721,13 +1722,13 @@ public void updateObject( GeometryObject object, Object3D scene ) } - geometry.verticesNeedUpdate = false; - geometry.morphTargetsNeedUpdate = false; - geometry.elementsNeedUpdate = false; - geometry.uvsNeedUpdate = false; - geometry.normalsNeedUpdate = false; - geometry.colorsNeedUpdate = false; - geometry.tangentsNeedUpdate = false; + geometry.setVerticesNeedUpdate( false ); + geometry.setMorphTargetsNeedUpdate( false ); + geometry.setElementsNeedUpdate( false ); + geometry.setUvsNeedUpdate( false ); + geometry.setNormalsNeedUpdate( false ); + geometry.setColorsNeedUpdate( false ); + geometry.setTangentsNeedUpdate( false ); if(material instanceof ShaderMaterial ) { ((ShaderMaterial)material).getShader().clearCustomAttributes(); @@ -1739,15 +1740,15 @@ public void updateObject( GeometryObject object, Object3D scene ) boolean customAttributesDirty = (material instanceof ShaderMaterial) && ((ShaderMaterial)material).getShader().areCustomAttributesDirty(); - if ( geometry.verticesNeedUpdate || geometry.colorsNeedUpdate || geometry.lineDistancesNeedUpdate || customAttributesDirty ) { + if ( geometry.isVerticesNeedUpdate() || geometry.isColorsNeedUpdate() || geometry.isLineDistancesNeedUpdate() || customAttributesDirty ) { ((Line)object).setBuffers( gl, BufferUsage.DYNAMIC_DRAW ); } - geometry.verticesNeedUpdate = false; - geometry.colorsNeedUpdate = false; - geometry.lineDistancesNeedUpdate = false; + geometry.setVerticesNeedUpdate( false ); + geometry.setColorsNeedUpdate( false ); + geometry.setLineDistancesNeedUpdate( false ); if(material instanceof ShaderMaterial ) { ((ShaderMaterial)material).getShader().clearCustomAttributes(); @@ -1760,14 +1761,14 @@ public void updateObject( GeometryObject object, Object3D scene ) boolean customAttributesDirty = (material instanceof ShaderMaterial) && ((ShaderMaterial)material).getShader().areCustomAttributesDirty(); - if ( geometry.verticesNeedUpdate || geometry.colorsNeedUpdate || ((PointCloud)object).isSortParticles() || customAttributesDirty ) { + if ( geometry.isVerticesNeedUpdate() || geometry.isColorsNeedUpdate() || ((PointCloud)object).isSortParticles() || customAttributesDirty ) { ((PointCloud)object).setBuffers( this, BufferUsage.DYNAMIC_DRAW ); } - geometry.verticesNeedUpdate = false; - geometry.colorsNeedUpdate = false; + geometry.setVerticesNeedUpdate( false ); + geometry.setColorsNeedUpdate( false ); if(material instanceof ShaderMaterial ) { ((ShaderMaterial)material).getShader().clearCustomAttributes(); diff --git a/src/thothbot/parallax/core/client/shaders/ProgramParameters.java b/src/thothbot/parallax/core/client/shaders/ProgramParameters.java index cc0761fb..018105b2 100644 --- a/src/thothbot/parallax/core/client/shaders/ProgramParameters.java +++ b/src/thothbot/parallax/core/client/shaders/ProgramParameters.java @@ -72,12 +72,28 @@ public class ProgramParameters public String toString() { String retval = ""; - retval += maxDirLights + ", " + maxPointLights + ", " + maxSpotLights + ", " + maxHemiLights + "-1-" - + maxShadows + ", " + maxBones + ", " + useVertexTexture + "-2-" - + map + ", " + envMap + ", " + lightMap + ", " + bumpMap + ", " + normalMap + ", " + specularMap + ", " + vertexColors + ", " + skinning + ", " + morphTargets + "-3-" - + morphNormals + ", " + wrapAround + ", " + doubleSided + ", " + flipSided + "-4-" - + shadowMapEnabled + ", " + shadowMapSoft + ", " + shadowMapDebug + ", " + shadowMapCascade + ", " + sizeAttenuation + "-5-" - + alphaTest + ", " + useFog + ", " + useFog2 + ", " + metal + ", " + maxMorphTargets + ", " + maxMorphNormals + ", " + supportsVertexTextures; + retval += supportsVertexTextures + "-1-" + + + map + ", " + envMap + ", " + lightMap + ", " + bumpMap + ", " + normalMap + ", " + specularMap + ", " + alphaMap + "-2-" + + + vertexColors + "-3-" + + + useFog + ", " + useFog2 + "-4-" + + + sizeAttenuation + ", " + logarithmicDepthBuffer + "-5-" + + + skinning + ", " + maxBones + ", " + useVertexTexture + "-6-" + + + morphTargets + morphNormals + ", " + maxMorphTargets + ", " + maxMorphNormals + "-7-" + + + maxDirLights + ", " + maxPointLights + ", " + maxSpotLights + ", " + maxHemiLights + "-8-" + + + maxShadows + ", " + shadowMapEnabled + ", " + shadowMapSoft + ", " + shadowMapDebug + ", " + shadowMapCascade + "-9-" + + + alphaTest + ", " + metal + ", " + wrapAround + ", " + doubleSided + ", " + flipSided + "-10-" + + + gammaInput + ", " + gammaOutput + "-11-"; + return retval; } } diff --git a/src/thothbot/parallax/core/shared/core/AbstractGeometry.java b/src/thothbot/parallax/core/shared/core/AbstractGeometry.java index 1a5ccafa..0c5d6e84 100644 --- a/src/thothbot/parallax/core/shared/core/AbstractGeometry.java +++ b/src/thothbot/parallax/core/shared/core/AbstractGeometry.java @@ -24,7 +24,7 @@ public abstract class AbstractGeometry extends WebGLGeometry { - public static int Counter = 0; + private static int Counter = 0; private int id = 0; @@ -37,20 +37,20 @@ public abstract class AbstractGeometry extends WebGLGeometry protected Sphere boundingSphere = null; // update flags - public boolean verticesNeedUpdate = false; - public boolean elementsNeedUpdate = false; - public boolean normalsNeedUpdate = false; - public boolean colorsNeedUpdate = false; - public boolean uvsNeedUpdate = false; - public boolean tangentsNeedUpdate = false; - public boolean morphTargetsNeedUpdate = false; - public boolean lineDistancesNeedUpdate = false; - - public boolean groupsNeedUpdate = false; - + protected boolean verticesNeedUpdate = false; + protected boolean elementsNeedUpdate = false; + protected boolean normalsNeedUpdate = false; + protected boolean colorsNeedUpdate = false; + protected boolean uvsNeedUpdate = false; + protected boolean tangentsNeedUpdate = false; + protected boolean morphTargetsNeedUpdate = false; + protected boolean lineDistancesNeedUpdate = false; + + protected boolean groupsNeedUpdate = false; + public AbstractGeometry() { - this.id = BufferGeometry.Counter++; - + this.id = Counter++; + this.name = ""; } @@ -84,6 +84,78 @@ public int getId() return id; } + public boolean isVerticesNeedUpdate() { + return verticesNeedUpdate; + } + + public void setVerticesNeedUpdate(boolean verticesNeedUpdate) { + this.verticesNeedUpdate = verticesNeedUpdate; + } + + public boolean isElementsNeedUpdate() { + return elementsNeedUpdate; + } + + public void setElementsNeedUpdate(boolean elementsNeedUpdate) { + this.elementsNeedUpdate = elementsNeedUpdate; + } + + public boolean isNormalsNeedUpdate() { + return normalsNeedUpdate; + } + + public void setNormalsNeedUpdate(boolean normalsNeedUpdate) { + this.normalsNeedUpdate = normalsNeedUpdate; + } + + public boolean isColorsNeedUpdate() { + return colorsNeedUpdate; + } + + public void setColorsNeedUpdate(boolean colorsNeedUpdate) { + this.colorsNeedUpdate = colorsNeedUpdate; + } + + public boolean isUvsNeedUpdate() { + return uvsNeedUpdate; + } + + public void setUvsNeedUpdate(boolean uvsNeedUpdate) { + this.uvsNeedUpdate = uvsNeedUpdate; + } + + public boolean isTangentsNeedUpdate() { + return tangentsNeedUpdate; + } + + public void setTangentsNeedUpdate(boolean tangentsNeedUpdate) { + this.tangentsNeedUpdate = tangentsNeedUpdate; + } + + public boolean isMorphTargetsNeedUpdate() { + return morphTargetsNeedUpdate; + } + + public void setMorphTargetsNeedUpdate(boolean morphTargetsNeedUpdate) { + this.morphTargetsNeedUpdate = morphTargetsNeedUpdate; + } + + public boolean isLineDistancesNeedUpdate() { + return lineDistancesNeedUpdate; + } + + public void setLineDistancesNeedUpdate(boolean lineDistancesNeedUpdate) { + this.lineDistancesNeedUpdate = lineDistancesNeedUpdate; + } + + public boolean isGroupsNeedUpdate() { + return groupsNeedUpdate; + } + + public void setGroupsNeedUpdate(boolean groupsNeedUpdate) { + this.groupsNeedUpdate = groupsNeedUpdate; + } + public Box3 getBoundingBox() { return this.boundingBox; } diff --git a/src/thothbot/parallax/core/shared/helpers/ArrowHelper.java b/src/thothbot/parallax/core/shared/helpers/ArrowHelper.java index 6d427acc..a0525880 100644 --- a/src/thothbot/parallax/core/shared/helpers/ArrowHelper.java +++ b/src/thothbot/parallax/core/shared/helpers/ArrowHelper.java @@ -31,10 +31,9 @@ public class ArrowHelper extends Object3D { + private Line line; + private Mesh cone; - public Line line; - public Mesh cone; - public ArrowHelper ( Vector3 dir, Vector3 origin) { this(dir, origin, 1); diff --git a/src/thothbot/parallax/core/shared/helpers/CameraHelper.java b/src/thothbot/parallax/core/shared/helpers/CameraHelper.java index 1fe26901..9c73f68c 100644 --- a/src/thothbot/parallax/core/shared/helpers/CameraHelper.java +++ b/src/thothbot/parallax/core/shared/helpers/CameraHelper.java @@ -196,7 +196,7 @@ public void update() setPoint( "cn3", 0, -h, -1 ); setPoint( "cn4", 0, h, -1 ); - ((Geometry)getGeometry()).verticesNeedUpdate = true; + ((Geometry)getGeometry()).setVerticesNeedUpdate( true ); } private void setPoint( String point, double x, double y, double z ) diff --git a/src/thothbot/parallax/core/shared/materials/Material.java b/src/thothbot/parallax/core/shared/materials/Material.java index 2630dbf6..b5a02521 100644 --- a/src/thothbot/parallax/core/shared/materials/Material.java +++ b/src/thothbot/parallax/core/shared/materials/Material.java @@ -482,12 +482,13 @@ public Material clone( Material material ) { public void updateProgramParameters(ProgramParameters parameters) { - parameters.map = (this instanceof HasMap && ((HasMap)this).getMap() != null); - parameters.envMap = (this instanceof HasEnvMap && ((HasEnvMap)this).getEnvMap() != null); - parameters.lightMap = (this instanceof HasLightMap && ((HasLightMap)this).getLightMap() != null); - parameters.bumpMap = (this instanceof HasBumpMap && ((HasBumpMap)this).getBumpMap() != null); - parameters.normalMap = (this instanceof HasNormalMap && ((HasNormalMap)this).getNormalMap() != null); + parameters.map = (this instanceof HasMap && ((HasMap)this).getMap() != null); + parameters.envMap = (this instanceof HasEnvMap && ((HasEnvMap)this).getEnvMap() != null); + parameters.lightMap = (this instanceof HasLightMap && ((HasLightMap)this).getLightMap() != null); + parameters.bumpMap = (this instanceof HasBumpMap && ((HasBumpMap)this).getBumpMap() != null); + parameters.normalMap = (this instanceof HasNormalMap && ((HasNormalMap)this).getNormalMap() != null); parameters.specularMap = (this instanceof HasSpecularMap && ((HasSpecularMap)this).getSpecularMap() != null); + parameters.alphaMap = (this instanceof HasAlphaMap && ((HasAlphaMap)this).getAlphaMap() != null); parameters.vertexColors = (this instanceof HasVertexColors && ((HasVertexColors)this).isVertexColors() != Material.COLORS.NO); @@ -504,7 +505,6 @@ public void updateProgramParameters(ProgramParameters parameters) if(this instanceof MeshPhongMaterial) { parameters.metal = ((MeshPhongMaterial)this).isMetal(); -// parameters.perPixel = ((MeshPhongMaterial)this).isPerPixel(); } parameters.wrapAround = this instanceof HasWrap && ((HasWrap)this).isWrapAround(); @@ -818,7 +818,7 @@ else if(this instanceof HasNormalMap) uvScaleMap = ((HasNormalMap)this).getNormalMap(); else if(this instanceof HasBumpMap) uvScaleMap = ((HasBumpMap)this).getBumpMap(); - else if(this instanceof HasBumpMap) + else if(this instanceof HasAlphaMap) uvScaleMap = ((HasAlphaMap)this).getAlphaMap(); if(uvScaleMap != null) @@ -949,4 +949,9 @@ public void deallocate( WebGLRenderer renderer ) } } + + public String toString() + { + return this.getClass().getSimpleName() + " { id=" + this.getId() + " }"; + } } diff --git a/src/thothbot/parallax/core/shared/objects/Line.java b/src/thothbot/parallax/core/shared/objects/Line.java index 79f1661d..2b6fe698 100644 --- a/src/thothbot/parallax/core/shared/objects/Line.java +++ b/src/thothbot/parallax/core/shared/objects/Line.java @@ -282,9 +282,9 @@ public void setBuffers(WebGLRenderingContext gl, BufferUsage hint) Float32Array colorArray = geometry.__colorArray; Float32Array lineDistanceArray = geometry.__lineDistanceArray; - boolean dirtyVertices = geometry.verticesNeedUpdate; - boolean dirtyColors = geometry.colorsNeedUpdate; - boolean dirtyLineDistances = geometry.lineDistancesNeedUpdate; + boolean dirtyVertices = geometry.isVerticesNeedUpdate(); + boolean dirtyColors = geometry.isColorsNeedUpdate(); + boolean dirtyLineDistances = geometry.isLineDistancesNeedUpdate(); List customAttributes = geometry.__webglCustomAttributesList; diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index 39f87c89..45ebfae1 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -769,13 +769,13 @@ public void setBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup, Bu Geometry geometry = (Geometry)this.getGeometry(); // this is shared for all chunks - boolean dirtyVertices = geometry.verticesNeedUpdate, - dirtyElements = geometry.elementsNeedUpdate, - dirtyUvs = geometry.uvsNeedUpdate, - dirtyNormals = geometry.normalsNeedUpdate, - dirtyTangents = geometry.tangentsNeedUpdate, - dirtyColors = geometry.colorsNeedUpdate, - dirtyMorphTargets = geometry.morphTargetsNeedUpdate; + boolean dirtyVertices = geometry.isVerticesNeedUpdate(), + dirtyElements = geometry.isElementsNeedUpdate(), + dirtyUvs = geometry.isUvsNeedUpdate(), + dirtyNormals = geometry.isNormalsNeedUpdate(), + dirtyTangents = geometry.isTangentsNeedUpdate(), + dirtyColors = geometry.isColorsNeedUpdate(), + dirtyMorphTargets = geometry.isMorphTargetsNeedUpdate(); List vertices = geometry.getVertices(); List chunk_faces3 = geometryGroup.faces3; diff --git a/src/thothbot/parallax/core/shared/objects/PointCloud.java b/src/thothbot/parallax/core/shared/objects/PointCloud.java index 863e8dab..97737a3a 100644 --- a/src/thothbot/parallax/core/shared/objects/PointCloud.java +++ b/src/thothbot/parallax/core/shared/objects/PointCloud.java @@ -260,9 +260,9 @@ public void setBuffers(WebGLRenderer renderer, BufferUsage hint) // Float32Array sortArray = geometry.__sortArray; - boolean dirtyVertices = geometry.verticesNeedUpdate; - boolean dirtyElements = geometry.elementsNeedUpdate; - boolean dirtyColors = geometry.colorsNeedUpdate; + boolean dirtyVertices = geometry.isVerticesNeedUpdate(); + boolean dirtyElements = geometry.isElementsNeedUpdate(); + boolean dirtyColors = geometry.isColorsNeedUpdate(); List customAttributes = geometry.__webglCustomAttributesList; From d608bc24467826059e1a1408e5a0342db01a693f Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 13 Feb 2015 14:49:29 +0300 Subject: [PATCH 37/75] Some code refactoring --- .../core/client/renderers/WebGLRenderer.java | 6 +- .../parallax/core/shared/objects/Mesh.java | 6 -- .../parallax/core/shared/scenes/Scene.java | 62 ++++++++++++------- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index a80ce36b..113fa50c 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -1907,14 +1907,14 @@ public int compare(WebGLObject a, WebGLObject b) { } - Log.debug(" -- render() overrideMaterial : " + (scene.overrideMaterial != null) + Log.debug(" -- render() overrideMaterial : " + (scene.getOverrideMaterial() != null) + ", lights: " + lights.size() + ", opaqueObjects: " + opaqueObjects.size() + ", transparentObjects: " + transparentObjects.size() ); - if ( scene.overrideMaterial != null ) + if ( scene.getOverrideMaterial() != null ) { - Material material = scene.overrideMaterial; + Material material = scene.getOverrideMaterial(); this.setBlending( material.getBlending(), material.getBlendEquation(), material.getBlendSrc(), material.getBlendDst() ); this.setDepthTest( material.isDepthTest() ); diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index 45ebfae1..20858ce3 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -94,12 +94,6 @@ public Mesh(AbstractGeometry geometry) this(geometry, Mesh.defaultMaterial); } -// public Mesh(BufferGeometry geometry, Material material) -// { -// this(material); -// this.geometryBuffer = geometry; -// } - public Mesh(AbstractGeometry geometry, Material material) { super(geometry, material); diff --git a/src/thothbot/parallax/core/shared/scenes/Scene.java b/src/thothbot/parallax/core/shared/scenes/Scene.java index 2d7cf117..69c0eadb 100644 --- a/src/thothbot/parallax/core/shared/scenes/Scene.java +++ b/src/thothbot/parallax/core/shared/scenes/Scene.java @@ -38,9 +38,9 @@ public final class Scene extends Object3D */ private AbstractFog fog; - public Material overrideMaterial; + private Material overrideMaterial; - private boolean autoUpdate = true; + private boolean isAutoUpdate = true; /** * This default constructor will create new Scene instance. @@ -50,25 +50,6 @@ public Scene() super(); } - public Scene clone() { - return clone(new Scene()); - } - - public Scene clone(Scene object ) { - - super.clone(object); - - if ( this.fog != null ) - object.fog = this.fog.clone(); - if ( this.overrideMaterial != null ) - object.overrideMaterial = this.overrideMaterial.clone(); - - object.autoUpdate = this.autoUpdate; - object.matrixAutoUpdate = this.matrixAutoUpdate; - - return object; - - }; /** * Get fogAbstract associated with the Scene. @@ -89,4 +70,43 @@ public void setFog(AbstractFog fog) { this.fog = fog; } + + public Material getOverrideMaterial() { + return overrideMaterial; + } + + + public void setOverrideMaterial(Material overrideMaterial) { + this.overrideMaterial = overrideMaterial; + } + + + public boolean isAutoUpdate() { + return isAutoUpdate; + } + + + public void setAutoUpdate(boolean isAutoUpdate) { + this.isAutoUpdate = isAutoUpdate; + } + + public Scene clone() { + return clone(new Scene()); + } + + public Scene clone(Scene object ) { + + super.clone(object); + + if ( this.fog != null ) + object.fog = this.fog.clone(); + if ( this.overrideMaterial != null ) + object.overrideMaterial = this.overrideMaterial.clone(); + + object.isAutoUpdate = this.isAutoUpdate; + object.matrixAutoUpdate = this.matrixAutoUpdate; + + return object; + + }; } From 8223153a049d4f6c482079b587451dcc49bd6a2a Mon Sep 17 00:00:00 2001 From: thothbot Date: Sat, 14 Feb 2015 00:03:13 +0300 Subject: [PATCH 38/75] Code refactoring --- .../core/client/renderers/WebGLObject.java | 2 +- .../core/client/renderers/WebGLRenderer.java | 34 +++---- .../core/shared/core/BufferAttribute.java | 47 +++++++-- .../core/shared/core/BufferGeometry.java | 53 ++++++----- .../core/shared/core/GeometryGroup.java | 95 ++++++++++++++++--- .../core/shared/core/GeometryObject.java | 19 ---- .../core/shared/materials/Material.java | 4 +- .../parallax/core/shared/objects/Bone.java | 18 +++- .../parallax/core/shared/objects/LOD.java | 76 +++++++++++---- .../parallax/core/shared/objects/Mesh.java | 22 ++--- .../core/shared/objects/PointCloud.java | 2 +- .../parallax/plugins/sprite/Sprite.java | 2 +- 12 files changed, 261 insertions(+), 113 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLObject.java b/src/thothbot/parallax/core/client/renderers/WebGLObject.java index aa0fbe0a..f35328d5 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLObject.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLObject.java @@ -78,7 +78,7 @@ public void unrollBufferMaterial(WebGLRenderer renderer) if ( material instanceof MeshFaceMaterial ) { - int materialIndex = geometry instanceof BufferGeometry ? 0 : ((GeometryGroup)buffer).materialIndex; + int materialIndex = geometry instanceof BufferGeometry ? 0 : ((GeometryGroup)buffer).getMaterialIndex(); material = ((MeshFaceMaterial)material).getMaterials().get( materialIndex ); diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index 113fa50c..b63bbdb1 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -1101,7 +1101,7 @@ private void setupVertexAttributes( Material material, Shader program, BufferGeo int size = geometryAttribute.getItemSize(); - gl.bindBuffer( BufferTarget.ARRAY_BUFFER, geometryAttribute.buffer ); + gl.bindBuffer( BufferTarget.ARRAY_BUFFER, geometryAttribute.getBuffer() ); enableAttribute( programAttribute ); @@ -1173,7 +1173,7 @@ public void renderBufferDirect( Camera camera, List lights, AbstractFog f DrawElementsType type = DrawElementsType.UNSIGNED_SHORT; int size = 2; - List offsets = geometry.offsets; + List offsets = geometry.getDrawcalls(); if ( offsets.size() == 0 ) { @@ -1181,7 +1181,7 @@ public void renderBufferDirect( Camera camera, List lights, AbstractFog f setupVertexAttributes( material, program, geometry, 0 ); - getGL().bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, index.buffer ); + getGL().bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, index.getBuffer() ); } @@ -1206,7 +1206,7 @@ public void renderBufferDirect( Camera camera, List lights, AbstractFog f if ( updateBuffers ) { setupVertexAttributes( material, program, geometry, startIndex ); - getGL().bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, index.buffer ); + getGL().bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, index.getBuffer() ); } @@ -1289,14 +1289,14 @@ else if ( object instanceof Line ) // } - List offsets = geometry.getOffsets(); + List drawcalls = geometry.getDrawcalls(); - if ( offsets.size() == 0 ) { + if ( drawcalls.size() == 0 ) { if ( updateBuffers ) { setupVertexAttributes( material, program, geometry, 0 ); - gl.bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, index.buffer ); + gl.bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, index.getBuffer() ); } @@ -1311,25 +1311,25 @@ else if ( object instanceof Line ) // must set attribute pointers to use new offsets for each chunk // even if geometry and materials didn't change - if ( offsets.size() > 1 ) updateBuffers = true; + if ( drawcalls.size() > 1 ) updateBuffers = true; - for ( int i = 0, il = offsets.size(); i < il; i ++ ) { + for ( int i = 0, il = drawcalls.size(); i < il; i ++ ) { - int startIndex = offsets.get( i ).index; + int startIndex = drawcalls.get( i ).index; if ( updateBuffers ) { setupVertexAttributes( material, program, geometry, startIndex ); - gl.bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, index.buffer ); + gl.bindBuffer( BufferTarget.ELEMENT_ARRAY_BUFFER, index.getBuffer() ); } // render indexed lines - gl.drawElements( mode, offsets.get( i ).count, type, offsets.get( i ).start * size ); // 2 bytes per Uint16Array + gl.drawElements( mode, drawcalls.get( i ).count, type, drawcalls.get( i ).start * size ); // 2 bytes per Uint16Array this.info.getRender().calls ++; - this.info.getRender().vertices += offsets.get( i ).count; // not really true, here vertices can be shared + this.info.getRender().vertices += drawcalls.get( i ).count; // not really true, here vertices can be shared } @@ -1396,7 +1396,7 @@ public List makeGroups( Geometry geometry, boolean usesFaceMateri } - if ( groups.get( groupHash ).vertices + 3 > maxVerticesInGroup ) { + if ( groups.get( groupHash ).getVertices() + 3 > maxVerticesInGroup ) { hash_map.put( materialIndex.toString(), hash_map.get( materialIndex ) + 1 ); groupHash = materialIndex + "_" + hash_map.get( materialIndex ); @@ -1411,8 +1411,8 @@ public List makeGroups( Geometry geometry, boolean usesFaceMateri } - groups.get( groupHash ).faces3.add( f ); - groups.get( groupHash ).vertices += 3; + groups.get( groupHash ).getFaces3().add( f ); + groups.get( groupHash ).setVertices(groups.get( groupHash ).getVertices() + 3); } @@ -1664,7 +1664,7 @@ public Material getBufferMaterial( GeometryObject object, GeometryGroup geometry { return object.getMaterial() instanceof MeshFaceMaterial - ? ((MeshFaceMaterial)object.getMaterial()).getMaterials().get( geometryGroup.materialIndex ) + ? ((MeshFaceMaterial)object.getMaterial()).getMaterials().get( geometryGroup.getMaterialIndex() ) : object.getMaterial(); } diff --git a/src/thothbot/parallax/core/shared/core/BufferAttribute.java b/src/thothbot/parallax/core/shared/core/BufferAttribute.java index c1a6e350..fc51965f 100644 --- a/src/thothbot/parallax/core/shared/core/BufferAttribute.java +++ b/src/thothbot/parallax/core/shared/core/BufferAttribute.java @@ -28,10 +28,10 @@ public class BufferAttribute { private int itemSize; // TODO: Fix it (BufferGeometry) - public int numItems; + private int numItems; - public boolean needsUpdate = false; - public WebGLBuffer buffer; + private boolean needsUpdate = false; + private WebGLBuffer buffer; public BufferAttribute(TypeArray array, int itemSize) { this.array = array; @@ -56,10 +56,45 @@ public void setArray(Float32Array array) { this.array = array; } + /** + * @return the numItems + */ + public int getNumItems() { + return numItems; + } + + /** + * @param numItems the numItems to set + */ + public void setNumItems(int numItems) { + this.numItems = numItems; + } + + /** + * @return the needsUpdate + */ + public boolean isNeedsUpdate() { + return needsUpdate; + } + public void setNeedsUpdate(boolean needsUpdate) { this.needsUpdate = needsUpdate; } - + + /** + * @return the buffer + */ + public WebGLBuffer getBuffer() { + return buffer; + } + + /** + * @param buffer the buffer to set + */ + public void setBuffer(WebGLBuffer buffer) { + this.buffer = buffer; + } + public void copyAt( int index1, BufferAttribute attribute, int index2 ) { index1 *= this.itemSize; @@ -150,7 +185,7 @@ public BufferAttribute clone() { public String toString() { return "{array: " + this.array.getLength() + ", itemSize: " + this.itemSize - + ", needsUpdate: " + this.needsUpdate - + ", buffer: " + this.buffer + "}"; + + ", needsUpdate: " + this.isNeedsUpdate() + + ", buffer: " + this.getBuffer() + "}"; } } diff --git a/src/thothbot/parallax/core/shared/core/BufferGeometry.java b/src/thothbot/parallax/core/shared/core/BufferGeometry.java index f789801b..c17c8745 100644 --- a/src/thothbot/parallax/core/shared/core/BufferGeometry.java +++ b/src/thothbot/parallax/core/shared/core/BufferGeometry.java @@ -88,8 +88,7 @@ public DrawCall(int start, int count, int index) { private Map attributes; private Set attributesKeys; - public List drawcalls; - public List offsets; // backwards compatibility + private List drawcalls; public BufferGeometry() { @@ -98,8 +97,7 @@ public BufferGeometry() this.attributes = GWT.isScript() ? new FastMap() : new HashMap(); - this.drawcalls = new ArrayList(); - this.offsets = this.drawcalls; + this.setDrawcalls(new ArrayList()); this.boundingBox = null; this.boundingSphere = null; @@ -151,8 +149,15 @@ public BufferAttribute getAttribute( String name ) { * This may be necessary if, for instance, you have more than 65535 vertices in your object. * @return */ - public List getOffsets() { - return offsets; + public List getDrawcalls() { + return drawcalls; + } + + /** + * @param drawcalls the drawcalls to set + */ + public void setDrawcalls(List drawcalls) { + this.drawcalls = drawcalls; } public void addDrawCall( int start, int count ) { @@ -162,7 +167,7 @@ public void addDrawCall( int start, int count ) { public void addDrawCall( int start, int count, int indexOffset ) { DrawCall drawCall = new DrawCall(start, count, indexOffset); - this.drawcalls.add(drawCall); + this.getDrawcalls().add(drawCall); } /** @@ -486,8 +491,8 @@ public void computeVertexNormals() { Uint16Array indices = (Uint16Array) getAttribute("normal").getArray(); - List offsets = this.offsets.size() > 0 - ? this.offsets + List offsets = this.drawcalls.size() > 0 + ? this.drawcalls : Arrays.asList( new BufferGeometry.DrawCall(0, indices.getLength(), 0 ) ) ; for ( int j = 0, jl = offsets.size(); j < jl; ++ j ) { @@ -608,13 +613,13 @@ public void computeTangents() { Float32Array tangents = (Float32Array)getAttribute("tangent").getArray(); - if ( this.drawcalls.size() == 0 ) { + if ( this.getDrawcalls().size() == 0 ) { this.addDrawCall( 0, indices.getLength(), 0 ); } - List drawcalls = this.drawcalls; + List drawcalls = this.getDrawcalls(); for ( int j = 0, jl = drawcalls.size(); j < jl; ++ j ) { @@ -752,7 +757,7 @@ public List computeOffsets( int size /* indexBufferSize /* Move all attribute values to map to the new computed indices , also expand the vertice stack to match our new vertexPtr. */ this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr ); - this.offsets = offsets; + this.drawcalls = offsets; /* var orderTime = Date.now(); @@ -837,7 +842,7 @@ public void reorderBuffers( Float32Array indexBuffer, Int32Array indexMap, int v continue; this.attributes.get( attr ).setArray( sortedAttributes.get( attr ) ); - this.attributes.get( attr ).numItems = this.attributes.get( attr ).getItemSize() * vertexCount; + this.attributes.get( attr ).setNumItems(this.attributes.get( attr ).getItemSize() * vertexCount); } } @@ -850,11 +855,11 @@ public BufferGeometry clone() { geometry.addAttribute( attr, sourceAttr.clone() ); } - for ( int i = 0, il = this.offsets.size(); i < il; i ++ ) { + for ( int i = 0, il = this.drawcalls.size(); i < il; i ++ ) { - DrawCall offset = this.offsets.get( i ); + DrawCall offset = this.drawcalls.get( i ); - geometry.offsets.add( new DrawCall( + geometry.drawcalls.add( new DrawCall( offset.start, offset.index, @@ -963,21 +968,21 @@ public void setDirectBuffers( WebGLRenderingContext gl ) { String key = (String) this.attributesKeys.toArray()[ i ]; BufferAttribute attribute = this.attributes.get( key ); - if ( attribute.buffer == null ) { + if ( attribute.getBuffer() == null ) { - attribute.buffer = gl.createBuffer(); - attribute.needsUpdate = true; + attribute.setBuffer(gl.createBuffer()); + attribute.setNeedsUpdate(true); } - if ( attribute.needsUpdate == true ) { + if ( attribute.isNeedsUpdate() == true ) { BufferTarget bufferType = ( key == "index" ) ? BufferTarget.ELEMENT_ARRAY_BUFFER : BufferTarget.ARRAY_BUFFER; - gl.bindBuffer( bufferType, attribute.buffer ); + gl.bindBuffer( bufferType, attribute.getBuffer() ); gl.bufferData( bufferType, attribute.getArray(), BufferUsage.STATIC_DRAW ); - attribute.needsUpdate = false; + attribute.setNeedsUpdate(false); } @@ -988,7 +993,7 @@ public void setDirectBuffers( WebGLRenderingContext gl ) { public String toString() { return getClass().getSimpleName() + "{id: " + getId() - + ", offsets: " + this.offsets.size() - + ", drawcalls: " + this.drawcalls.size() + "}"; + + ", offsets: " + this.drawcalls.size() + + ", drawcalls: " + this.getDrawcalls().size() + "}"; } } diff --git a/src/thothbot/parallax/core/shared/core/GeometryGroup.java b/src/thothbot/parallax/core/shared/core/GeometryGroup.java index c16ada6a..673c0b19 100644 --- a/src/thothbot/parallax/core/shared/core/GeometryGroup.java +++ b/src/thothbot/parallax/core/shared/core/GeometryGroup.java @@ -34,18 +34,18 @@ public class GeometryGroup extends WebGLGeometry public static Map> geometryGroups = GWT.isScript() ? new FastMap>() : new HashMap>(); - public static int Counter = 0; + private static int Counter = 0; private int id = 0; - public List faces3; + private List faces3; - public int materialIndex = -1; + private int materialIndex = -1; - public int vertices; + private int vertices; - public int numMorphTargets; - public int numMorphNormals; + private int numMorphTargets; + private int numMorphNormals; public Float32Array __skinIndexArray; public Float32Array __skinWeightArray; @@ -63,17 +63,88 @@ public GeometryGroup(int materialIndex, int numMorphTargets, int numMorphNormals super(); this.id = GeometryGroup.Counter++; - this.faces3 = new ArrayList(); - this.materialIndex = materialIndex; - this.vertices = 0; - this.numMorphTargets = numMorphTargets; - this.numMorphNormals = numMorphNormals; + this.setFaces3(new ArrayList()); + this.setMaterialIndex(materialIndex); + this.setVertices(0); + this.setNumMorphTargets(numMorphTargets); + this.setNumMorphNormals(numMorphNormals); } public int getId() { return this.id; } - + + + /** + * @return the faces3 + */ + public List getFaces3() { + return faces3; + } + + /** + * @param faces3 the faces3 to set + */ + public void setFaces3(List faces3) { + this.faces3 = faces3; + } + + /** + * @return the materialIndex + */ + public int getMaterialIndex() { + return materialIndex; + } + + /** + * @param materialIndex the materialIndex to set + */ + public void setMaterialIndex(int materialIndex) { + this.materialIndex = materialIndex; + } + + /** + * @return the vertices + */ + public int getVertices() { + return vertices; + } + + /** + * @param vertices the vertices to set + */ + public void setVertices(int vertices) { + this.vertices = vertices; + } + + /** + * @return the numMorphTargets + */ + public int getNumMorphTargets() { + return numMorphTargets; + } + + /** + * @param numMorphTargets the numMorphTargets to set + */ + public void setNumMorphTargets(int numMorphTargets) { + this.numMorphTargets = numMorphTargets; + } + + /** + * @return the numMorphNormals + */ + public int getNumMorphNormals() { + return numMorphNormals; + } + + /** + * @param numMorphNormals the numMorphNormals to set + */ + public void setNumMorphNormals(int numMorphNormals) { + this.numMorphNormals = numMorphNormals; + } + @Override public void dispose() { diff --git a/src/thothbot/parallax/core/shared/core/GeometryObject.java b/src/thothbot/parallax/core/shared/core/GeometryObject.java index fa147969..aa216f47 100644 --- a/src/thothbot/parallax/core/shared/core/GeometryObject.java +++ b/src/thothbot/parallax/core/shared/core/GeometryObject.java @@ -35,17 +35,10 @@ public abstract class GeometryObject extends Object3D { protected AbstractGeometry geometry; -// protected GeometryBuffer geometryBuffer; protected Material material; -// protected Material customDepthMaterial; private double _oldLineWidth = -1; -// public GeometryBuffer getGeometryBuffer() -// { -// return this.geometryBuffer; -// } - public GeometryObject(AbstractGeometry geometry, Material material) { this.geometry = geometry; this.material = material; @@ -79,18 +72,6 @@ public void setMaterial(Material material) */ public abstract void raycast( Raycaster raycaster, List intersects); -// public Material getCustomDepthMaterial() { -// return customDepthMaterial; -// } -// -// public void setCustomDepthMaterial(Material customDepthMaterial) { -// this.customDepthMaterial = customDepthMaterial; -// } - -// public abstract void initBuffer(WebGLRenderer renderer); - -// public abstract void setBuffer(WebGLRenderer renderer); - public abstract void renderBuffer(WebGLRenderer renderer, WebGLGeometry geometryBuffer, boolean updateBuffers); // /** diff --git a/src/thothbot/parallax/core/shared/materials/Material.java b/src/thothbot/parallax/core/shared/materials/Material.java index b5a02521..ba85e711 100644 --- a/src/thothbot/parallax/core/shared/materials/Material.java +++ b/src/thothbot/parallax/core/shared/materials/Material.java @@ -889,9 +889,9 @@ public static Material getBufferMaterial( GeometryObject object, GeometryGroup g Material material = null; if ( object.getMaterial() instanceof MeshFaceMaterial ) { - material = ((MeshFaceMaterial)object.getMaterial()).getMaterials().get( geometryGroup.materialIndex ); + material = ((MeshFaceMaterial)object.getMaterial()).getMaterials().get( geometryGroup.getMaterialIndex() ); } - else if ( geometryGroup.materialIndex >= 0 ) + else if ( geometryGroup.getMaterialIndex() >= 0 ) { material = object.getMaterial(); } diff --git a/src/thothbot/parallax/core/shared/objects/Bone.java b/src/thothbot/parallax/core/shared/objects/Bone.java index 8ba0e6e8..6011e6be 100644 --- a/src/thothbot/parallax/core/shared/objects/Bone.java +++ b/src/thothbot/parallax/core/shared/objects/Bone.java @@ -27,7 +27,7 @@ public class Bone extends Object3D { - public SkinnedMesh skin; + private SkinnedMesh skin; /** * @@ -35,7 +35,21 @@ public class Bone extends Object3D */ public Bone(SkinnedMesh belongsToSkin) { - this.skin = belongsToSkin; + this.setSkin(belongsToSkin); + } + + /** + * @return the skin + */ + public SkinnedMesh getSkin() { + return skin; + } + + /** + * @param skin the skin to set + */ + public void setSkin(SkinnedMesh skin) { + this.skin = skin; } } diff --git a/src/thothbot/parallax/core/shared/objects/LOD.java b/src/thothbot/parallax/core/shared/objects/LOD.java index dcb6f8a8..4d6fb2db 100644 --- a/src/thothbot/parallax/core/shared/objects/LOD.java +++ b/src/thothbot/parallax/core/shared/objects/LOD.java @@ -29,13 +29,13 @@ public class LOD extends Object3D { - public List LODs; - public double visibleAtDistance; - public Object3D object3D; + private List LODs; + private double visibleAtDistance; + private Object3D object3D; public LOD() { - this.LODs = new ArrayList(); + this.setLODs(new ArrayList()); } public void addLevel ( Object3D object3D) @@ -48,21 +48,21 @@ public void addLevel ( Object3D object3D, double visibleAtDistance ) { visibleAtDistance = Math.abs( visibleAtDistance ); - for(LOD lod: this.LODs) - if(visibleAtDistance < lod.visibleAtDistance) + for(LOD lod: this.getLODs()) + if(visibleAtDistance < lod.getVisibleAtDistance()) break; // ?? - LOD lod = this.LODs.get(1); - lod.visibleAtDistance = visibleAtDistance; - lod.object3D = object3D; + LOD lod = this.getLODs().get(1); + lod.setVisibleAtDistance(visibleAtDistance); + lod.setObject3D(object3D); this.add( object3D ); } public void update ( Camera camera ) { - if(this.LODs.size() <= 1) return; + if(this.getLODs().size() <= 1) return; camera.getMatrixWorldInverse().getInverse( camera.getMatrixWorld() ); @@ -72,14 +72,14 @@ public void update ( Camera camera ) * this.matrixWorld.getArray().get(13) + inverse.getArray().get(10) * this.matrixWorld.getArray().get(14) + inverse.getArray().get(14) ); - this.LODs.get(0).object3D.setVisible(true); + this.getLODs().get(0).getObject3D().setVisible(true); - for ( int l = 1; l < this.LODs.size(); l ++ ) + for ( int l = 1; l < this.getLODs().size(); l ++ ) { - if( distance >= this.LODs.get( l ).visibleAtDistance ) + if( distance >= this.getLODs().get( l ).getVisibleAtDistance() ) { - this.LODs.get( l - 1 ).object3D.setVisible(false); - this.LODs.get( l ).object3D.setVisible(true); + this.getLODs().get( l - 1 ).getObject3D().setVisible(false); + this.getLODs().get( l ).getObject3D().setVisible(true); } else { @@ -87,7 +87,49 @@ public void update ( Camera camera ) } } - for(LOD lod: this.LODs) - lod.object3D.setVisible(false); + for(LOD lod: this.getLODs()) + lod.getObject3D().setVisible(false); + } + + /** + * @return the object3D + */ + public Object3D getObject3D() { + return object3D; + } + + /** + * @param object3d the object3D to set + */ + public void setObject3D(Object3D object3d) { + object3D = object3d; + } + + /** + * @return the visibleAtDistance + */ + public double getVisibleAtDistance() { + return visibleAtDistance; + } + + /** + * @param visibleAtDistance the visibleAtDistance to set + */ + public void setVisibleAtDistance(double visibleAtDistance) { + this.visibleAtDistance = visibleAtDistance; + } + + /** + * @return the lODs + */ + public List getLODs() { + return LODs; + } + + /** + * @param lODs the lODs to set + */ + public void setLODs(List lODs) { + LODs = lODs; } } diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index 20858ce3..ddab550e 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -179,7 +179,7 @@ public void raycast( Raycaster raycaster, List intersects) Uint16Array indices = (Uint16Array)bGeometry.getAttribute("index").getArray(); Float32Array positions = (Float32Array)bGeometry.getAttribute("position").getArray(); - List offsets = bGeometry.getOffsets(); + List offsets = bGeometry.getDrawcalls(); if ( offsets.size() == 0 ) { @@ -505,7 +505,7 @@ public void initBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup) { Geometry geometry = (Geometry) this.getGeometry(); - List faces3 = geometryGroup.faces3; + List faces3 = geometryGroup.getFaces3(); int nvertices = faces3.size() * 3 ; int ntris = faces3.size() * 1; @@ -544,11 +544,11 @@ public void initBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup) geometryGroup.__faceArray = Uint16Array.create( ntris * 3 ); geometryGroup.__lineArray = Uint16Array.create( nlines * 2 ); - if ( geometryGroup.numMorphTargets > 0 ) { + if ( geometryGroup.getNumMorphTargets() > 0 ) { geometryGroup.__morphTargetsArrays = new ArrayList(); - for ( int m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) { + for ( int m = 0, ml = geometryGroup.getNumMorphTargets(); m < ml; m ++ ) { geometryGroup.__morphTargetsArrays.add( Float32Array.create( nvertices * 3 ) ); @@ -556,11 +556,11 @@ public void initBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup) } - if ( geometryGroup.numMorphNormals > 0 ) { + if ( geometryGroup.getNumMorphNormals() > 0 ) { geometryGroup.__morphNormalsArrays = new ArrayList(); - for ( int m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) { + for ( int m = 0, ml = geometryGroup.getNumMorphNormals(); m < ml; m ++ ) { geometryGroup.__morphNormalsArrays.add( Float32Array.create( nvertices * 3 ) ); @@ -644,18 +644,18 @@ public void createBuffers(WebGLRenderer renderer, GeometryGroup geometryGroup) geometryGroup.__webglFaceBuffer = gl.createBuffer(); geometryGroup.__webglLineBuffer = gl.createBuffer(); - if (geometryGroup.numMorphTargets != 0) { + if (geometryGroup.getNumMorphTargets() != 0) { geometryGroup.__webglMorphTargetsBuffers = new ArrayList(); - for (int m = 0; m < geometryGroup.numMorphTargets; m++) { + for (int m = 0; m < geometryGroup.getNumMorphTargets(); m++) { geometryGroup.__webglMorphTargetsBuffers.add(gl.createBuffer()); } } - if (geometryGroup.numMorphNormals != 0) { + if (geometryGroup.getNumMorphNormals() != 0) { geometryGroup.__webglMorphNormalsBuffers = new ArrayList(); - for (int m = 0; m < geometryGroup.numMorphNormals; m++) { + for (int m = 0; m < geometryGroup.getNumMorphNormals(); m++) { geometryGroup.__webglMorphNormalsBuffers.add(gl.createBuffer()); } } @@ -772,7 +772,7 @@ public void setBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup, Bu dirtyMorphTargets = geometry.isMorphTargetsNeedUpdate(); List vertices = geometry.getVertices(); - List chunk_faces3 = geometryGroup.faces3; + List chunk_faces3 = geometryGroup.getFaces3(); List obj_faces = geometry.getFaces(); List> obj_uvs = geometry.getFaceVertexUvs().get( 0 ); diff --git a/src/thothbot/parallax/core/shared/objects/PointCloud.java b/src/thothbot/parallax/core/shared/objects/PointCloud.java index 97737a3a..12f3fdbb 100644 --- a/src/thothbot/parallax/core/shared/objects/PointCloud.java +++ b/src/thothbot/parallax/core/shared/objects/PointCloud.java @@ -111,7 +111,7 @@ public void raycast(Raycaster raycaster, List intersects) { if ( bGeometry.getAttribute("index") != null ) { Uint16Array indices = (Uint16Array)bGeometry.getAttribute("index").getArray(); - List offsets = bGeometry.getOffsets(); + List offsets = bGeometry.getDrawcalls(); if ( offsets.size() == 0 ) { diff --git a/src/thothbot/parallax/plugins/sprite/Sprite.java b/src/thothbot/parallax/plugins/sprite/Sprite.java index 2b80398d..d6daec3b 100644 --- a/src/thothbot/parallax/plugins/sprite/Sprite.java +++ b/src/thothbot/parallax/plugins/sprite/Sprite.java @@ -58,7 +58,7 @@ public class Sprite extends GeometryObject implements Comparable defaultGeometry.addAttribute( "uv", new BufferAttribute( uvs, 2 ) ); }; - double z; + private double z; public Sprite() { From e9f196d9f153ee7a1c84351cfd62fff74ade9ee1 Mon Sep 17 00:00:00 2001 From: thothbot Date: Sat, 14 Feb 2015 00:06:10 +0300 Subject: [PATCH 39/75] Code refactoring --- .../core/client/renderers/WebGLRenderer.java | 4 ++-- .../parallax/core/shared/core/Geometry.java | 18 ++++++++++++++++-- .../parallax/core/shared/core/Object3D.java | 19 +++++++++++++++++-- .../parallax/core/shared/core/Raycaster.java | 4 ++-- .../parallax/core/shared/objects/Line.java | 2 +- .../parallax/core/shared/objects/Mesh.java | 6 +++--- 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index b63bbdb1..8d00a25b 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -1629,9 +1629,9 @@ private void projectObject( Object3D scene, Object3D object ) { if ( this.sortObjects == true ) { - if ( object.renderDepth > 0 ) { + if ( object.getRenderDepth() > 0 ) { - webglObject.z = object.renderDepth; + webglObject.z = object.getRenderDepth(); } else { diff --git a/src/thothbot/parallax/core/shared/core/Geometry.java b/src/thothbot/parallax/core/shared/core/Geometry.java index 0e58d382..d3bff446 100644 --- a/src/thothbot/parallax/core/shared/core/Geometry.java +++ b/src/thothbot/parallax/core/shared/core/Geometry.java @@ -113,7 +113,7 @@ public class MorphTarget /* * True if geometry has tangents. Set in Geometry.computeTangents. */ - public boolean hasTangents = false; + private boolean hasTangents = false; /* * The intermediate typed arrays will be deleted when set to false @@ -262,6 +262,20 @@ public List getBones() { public void setBones(List bones) { this.bones = bones; } + + /** + * @return the hasTangents + */ + public boolean isHasTangents() { + return hasTangents; + } + + /** + * @param hasTangents the hasTangents to set + */ + public void setHasTangents(boolean hasTangents) { + this.hasTangents = hasTangents; + } /** * Bakes matrix transform directly into vertex coordinates. @@ -687,7 +701,7 @@ public void computeTangents() } } - this.hasTangents = true; + this.setHasTangents(true); } /** diff --git a/src/thothbot/parallax/core/shared/core/Object3D.java b/src/thothbot/parallax/core/shared/core/Object3D.java index 29a5b3cb..fc745ef1 100644 --- a/src/thothbot/parallax/core/shared/core/Object3D.java +++ b/src/thothbot/parallax/core/shared/core/Object3D.java @@ -71,7 +71,7 @@ public static interface Traverse { protected Vector3 scale; - public double renderDepth; + private double renderDepth; protected boolean rotationAutoUpdate; @@ -318,6 +318,20 @@ public Vector3 getScale() { public void setScale(Vector3 scale) { this.scale = scale; } + + /** + * @return the renderDepth + */ + public double getRenderDepth() { + return renderDepth; + } + + /** + * @param renderDepth the renderDepth to set + */ + public void setRenderDepth(double renderDepth) { + this.renderDepth = renderDepth; + } /** * Up direction. @@ -865,7 +879,7 @@ public Object3D clone( Object3D object, boolean recursive ) { object.quaternion.copy( this.quaternion ); object.scale.copy( this.scale ); - object.renderDepth = this.renderDepth; + object.setRenderDepth(this.getRenderDepth()); object.rotationAutoUpdate = this.rotationAutoUpdate; @@ -901,4 +915,5 @@ public String toString() { return "{class=" + this.getClass().getSimpleName() + ", id: " + this.getId() + "}"; } + } diff --git a/src/thothbot/parallax/core/shared/core/Raycaster.java b/src/thothbot/parallax/core/shared/core/Raycaster.java index 811e37d0..4b2cbd7c 100644 --- a/src/thothbot/parallax/core/shared/core/Raycaster.java +++ b/src/thothbot/parallax/core/shared/core/Raycaster.java @@ -36,11 +36,11 @@ public class Raycaster /** * The precision factor of the raycaster when intersecting {@link Mesh} objects. */ - public static final double precision = 0.0001; + public static final double PRECISION = 0.0001; /** * The precision factor of the raycaster when intersecting {@link Line} objects. */ - public static final double linePrecision = 1; + public static final double LINE_PRECISION = 1; public static class Intersect implements Comparable { diff --git a/src/thothbot/parallax/core/shared/objects/Line.java b/src/thothbot/parallax/core/shared/objects/Line.java index 2b6fe698..c01fe291 100644 --- a/src/thothbot/parallax/core/shared/objects/Line.java +++ b/src/thothbot/parallax/core/shared/objects/Line.java @@ -123,7 +123,7 @@ public void raycast( Raycaster raycaster, List intersects) Ray ray = new Ray(); Sphere sphere = new Sphere(); - double precision = Raycaster.linePrecision; + double precision = Raycaster.LINE_PRECISION; double precisionSq = precision * precision; Geometry geometry = (Geometry) this.getGeometry(); diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index ddab550e..129696b6 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -165,7 +165,7 @@ public void raycast( Raycaster raycaster, List intersects) } - double precision = Raycaster.precision; + double precision = Raycaster.PRECISION; if ( geometry instanceof BufferGeometry ) { @@ -524,7 +524,7 @@ public void initBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup) } - if ( geometry.hasTangents ) { + if ( geometry.isHasTangents() ) { geometryGroup.__tangentArray = Float32Array.create( nvertices * 4 ); @@ -1010,7 +1010,7 @@ public void setBuffers(WebGLRenderingContext gl, GeometryGroup geometryGroup, Bu } } - if ( dirtyTangents && geometry.hasTangents) + if ( dirtyTangents && geometry.isHasTangents()) { for ( int f = 0, fl = chunk_faces3.size(); f < fl; f ++ ) { From 2987f4c06c5e43e32fd01e1b436f76bf2657f4b5 Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 16 Feb 2015 00:53:54 +0300 Subject: [PATCH 40/75] Code refactoring --- .../core/client/renderers/WebGLRenderer.java | 87 +++++++++++-------- .../core/shared/cameras/HasNearFar.java | 43 +++++++++ .../shared/cameras/OrthographicCamera.java | 2 +- .../shared/cameras/PerspectiveCamera.java | 2 +- .../shared/materials/LineDashedMaterial.java | 3 + .../core/shared/materials/Material.java | 31 ++----- .../shared/materials/MeshDepthMaterial.java | 7 +- .../postprocessing/Postprocessing.java | 8 +- .../plugins/postprocessing/ShaderPass.java | 4 + 9 files changed, 121 insertions(+), 66 deletions(-) create mode 100644 src/thothbot/parallax/core/shared/cameras/HasNearFar.java diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index 8d00a25b..ecf61ee9 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -72,6 +72,9 @@ import thothbot.parallax.core.client.textures.Texture; import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.cameras.HasNearFar; +import thothbot.parallax.core.shared.cameras.OrthographicCamera; +import thothbot.parallax.core.shared.cameras.PerspectiveCamera; import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.BufferAttribute; import thothbot.parallax.core.shared.core.BufferGeometry; @@ -94,6 +97,7 @@ import thothbot.parallax.core.shared.materials.HasWireframe; import thothbot.parallax.core.shared.materials.LineBasicMaterial; import thothbot.parallax.core.shared.materials.Material; +import thothbot.parallax.core.shared.materials.MeshBasicMaterial; import thothbot.parallax.core.shared.materials.MeshFaceMaterial; import thothbot.parallax.core.shared.materials.MeshLambertMaterial; import thothbot.parallax.core.shared.materials.MeshPhongMaterial; @@ -2445,7 +2449,7 @@ private Shader setProgram( Camera camera, List lights, AbstractFog fog, M WebGLProgram program = shader.getProgram(); Map m_uniforms = shader.getUniforms(); - if ( program != _currentProgram ) + if ( !program.equals(_currentProgram) ) { getGL().useProgram( program ); this._currentProgram = program; @@ -2453,22 +2457,55 @@ private Shader setProgram( Camera camera, List lights, AbstractFog fog, M refreshProgram = true; refreshMaterial = true; refreshLights = true; - - Log.warn("program != _currentProgram"); } if ( material.getId() != this._currentMaterialId ) { + if(_currentMaterialId == -1) refreshLights = true; + this._currentMaterialId = material.getId(); refreshMaterial = true; } - if ( refreshMaterial || camera != this._currentCamera ) + if ( refreshProgram || !camera.equals( this._currentCamera) ) { getGL().uniformMatrix4fv( m_uniforms.get("projectionMatrix").getLocation(), false, camera.getProjectionMatrix().getArray() ); - if ( camera != this._currentCamera ) + if ( _logarithmicDepthBuffer ) { + + gl.uniform1f( m_uniforms.get("logDepthBufFC").getLocation(), 2.0 / ( Math.log( ((HasNearFar)camera).getFar() + 1.0 ) / 0.6931471805599453 /*Math.LN2*/ ) ); + + } + + if ( !camera.equals( this._currentCamera) ) this._currentCamera = camera; + + // load material specific uniforms + // (shader material also gets them for the sake of genericity) + if ( material.getClass() == ShaderMaterial.class || + material.getClass() == MeshPhongMaterial.class || + material instanceof HasEnvMap && ((HasEnvMap)material).getEnvMap() != null + ) { + + if ( m_uniforms.get("cameraPosition").getLocation() != null ) + { + _vector3.setFromMatrixPosition( camera.getMatrixWorld() ); + getGL().uniform3f( m_uniforms.get("cameraPosition").getLocation(), _vector3.getX(), _vector3.getY(), _vector3.getZ() ); + } + } + + if ( material.getClass() == MeshPhongMaterial.class || + material.getClass() == MeshLambertMaterial.class || + material.getClass() == MeshBasicMaterial.class || + material.getClass() == ShaderMaterial.class || + material instanceof HasSkinning && ((HasSkinning)material).isSkinning() + ) { + + if ( m_uniforms.get("viewMatrix").getLocation() != null ) + { + getGL().uniformMatrix4fv( m_uniforms.get("viewMatrix").getLocation(), false, camera.getMatrixWorldInverse().getArray() ); + } + } } // skinning uniforms must be set even if material didn't change @@ -2508,11 +2545,17 @@ private Shader setProgram( Camera camera, List lights, AbstractFog fog, M if (this._lightsNeedUpdate ) { + refreshLights = true; this._lights.setupLights( lights, this.gammaInput ); this._lightsNeedUpdate = false; } - this._lights.refreshUniformsLights( m_uniforms ); + if ( refreshLights ) { + this._lights.refreshUniformsLights( m_uniforms ); +// markUniformsLightsNeedsUpdate( m_uniforms, true ); + } else { +// markUniformsLightsNeedsUpdate( m_uniforms, false ); + } } material.refreshUniforms(camera, this.gammaInput); @@ -2523,30 +2566,6 @@ private Shader setProgram( Camera camera, List lights, AbstractFog fog, M // load common uniforms loadUniformsGeneric( m_uniforms ); - // load material specific uniforms - // (shader material also gets them for the sake of genericity) - if ( material.getClass() == ShaderMaterial.class || - material.getClass() == MeshPhongMaterial.class || - material instanceof HasEnvMap - ) { - - if ( m_uniforms.get("cameraPosition").getLocation() != null ) - { - Vector3 position = new Vector3(); - position.setFromMatrixPosition( camera.getMatrixWorld() ); - getGL().uniform3f( m_uniforms.get("cameraPosition").getLocation(), position.getX(), position.getY(), position.getZ() ); - } - } - - if ( material.getClass() == MeshPhongMaterial.class || - material.getClass() == MeshLambertMaterial.class || - material.getClass() == ShaderMaterial.class || - material instanceof HasSkinning && ((HasSkinning)material).isSkinning() - ) { - - if ( m_uniforms.get("viewMatrix").getLocation() != null ) - getGL().uniformMatrix4fv( m_uniforms.get("viewMatrix").getLocation(), false, camera.getMatrixWorldInverse().getArray() ); - } } loadUniformsMatrices( m_uniforms, object ); @@ -2604,6 +2623,8 @@ private void loadUniformsMatrices ( Map uniforms, GeometryObjec @SuppressWarnings("unchecked") private void loadUniformsGeneric( Map materialUniforms ) { + WebGLRenderingContext gl = getGL(); + for ( Uniform uniform : materialUniforms.values() ) { // for ( String key: materialUniforms.keySet() ) @@ -2618,11 +2639,7 @@ private void loadUniformsGeneric( Map materialUniforms ) // Up textures also for undefined values if ( type != Uniform.TYPE.T && value == null ) continue; - - //Log.debug("loadUniformsGeneric() " + uniform); - - WebGLRenderingContext gl = getGL(); - + if(type == TYPE.I) // single integer { gl.uniform1i( location, (value instanceof Boolean) ? ((Boolean)value) ? 1 : 0 : (Integer) value ); diff --git a/src/thothbot/parallax/core/shared/cameras/HasNearFar.java b/src/thothbot/parallax/core/shared/cameras/HasNearFar.java new file mode 100644 index 00000000..a3ba19dc --- /dev/null +++ b/src/thothbot/parallax/core/shared/cameras/HasNearFar.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.cameras; + +public interface HasNearFar { + + + /** + * Gets Camera frustum near plane. + */ + public double getNear(); + + /** + * Sets Camera frustum near plane. + */ + public void setNear(double near); + + /** + * Gets Camera frustum far plane. + */ + public double getFar(); + + /** + * Sets Camera frustum far plane. + */ + public void setFar(double far); +} diff --git a/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java b/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java index 59f669f4..58eb2ff1 100644 --- a/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java +++ b/src/thothbot/parallax/core/shared/cameras/OrthographicCamera.java @@ -37,7 +37,7 @@ * @author thothbot * */ -public class OrthographicCamera extends Camera +public class OrthographicCamera extends Camera implements HasNearFar { protected double zoom = 1.0; diff --git a/src/thothbot/parallax/core/shared/cameras/PerspectiveCamera.java b/src/thothbot/parallax/core/shared/cameras/PerspectiveCamera.java index ff8b18b8..74c34307 100644 --- a/src/thothbot/parallax/core/shared/cameras/PerspectiveCamera.java +++ b/src/thothbot/parallax/core/shared/cameras/PerspectiveCamera.java @@ -31,7 +31,7 @@ * @author thothbot * */ -public class PerspectiveCamera extends Camera +public class PerspectiveCamera extends Camera implements HasNearFar { public double zoom = 1.0; diff --git a/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java b/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java index 63b80d47..6ba865b0 100644 --- a/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java @@ -169,6 +169,9 @@ public void refreshUniforms(Camera camera, boolean isGammaInput) super.refreshUniforms(camera, isGammaInput); Map uniforms = getShader().getUniforms(); + uniforms.get("diffuse").setValue( getColor() ); + uniforms.get("opacity").setValue( getOpacity() ); + uniforms.get("dashSize").setValue( getDashSize() ); uniforms.get("totalSize").setValue( getDashSize() + getGapSize() ); uniforms.get("scale").setValue( getScale() ); diff --git a/src/thothbot/parallax/core/shared/materials/Material.java b/src/thothbot/parallax/core/shared/materials/Material.java index ba85e711..2eb08ede 100644 --- a/src/thothbot/parallax/core/shared/materials/Material.java +++ b/src/thothbot/parallax/core/shared/materials/Material.java @@ -905,8 +905,12 @@ public void deallocate( WebGLRenderer renderer ) WebGLProgram program = getShader().getProgram(); if ( program == null ) return; - getShader().setPrecision(null); - +// getShader().setPrecision(null); + + // only deallocate GL program if this was the last use of shared program + // assumed there is only single copy of any program in the _programs list + // (that's how it's constructed) + boolean deleteProgram = false; for ( String key: renderer._programs.keySet()) @@ -915,37 +919,18 @@ public void deallocate( WebGLRenderer renderer ) if ( shader == getShader() ) { - renderer.getInfo().getMemory().programs --; renderer._programs.remove(key); deleteProgram = true; break; } } - if ( deleteProgram == true ) { - - // avoid using array.splice, this is costlier than creating new array from scratch - -// var newPrograms = []; -// -// for ( int i = 0, il = renderer._programs.length; i < il; i ++ ) { -// -// programInfo = _programs[ i ]; -// -// if ( programInfo.program != program ) { -// -// newPrograms.push( programInfo ); -// -// } -// -// } - -// renderer._programs = newPrograms; + if ( deleteProgram == true ) + { renderer.getGL().deleteProgram( program ); renderer.getInfo().getMemory().programs --; - } } diff --git a/src/thothbot/parallax/core/shared/materials/MeshDepthMaterial.java b/src/thothbot/parallax/core/shared/materials/MeshDepthMaterial.java index 3930f211..eb5fbd75 100644 --- a/src/thothbot/parallax/core/shared/materials/MeshDepthMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/MeshDepthMaterial.java @@ -24,6 +24,7 @@ import thothbot.parallax.core.client.shaders.Shader; import thothbot.parallax.core.client.shaders.Uniform; import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.cameras.HasNearFar; import thothbot.parallax.core.shared.cameras.OrthographicCamera; /** @@ -93,10 +94,10 @@ public void refreshUniforms(Camera camera, boolean isGammaInput) super.refreshUniforms(camera, isGammaInput); Map uniforms = getShader().getUniforms(); - if(camera.getClass() == OrthographicCamera.class) + if(camera instanceof HasNearFar) { - uniforms.get("mNear").setValue( ((OrthographicCamera) camera).getNear() ); - uniforms.get("mFar").setValue( ((OrthographicCamera) camera).getFar() ); + uniforms.get("mNear").setValue( ((HasNearFar) camera).getNear() ); + uniforms.get("mFar").setValue( ((HasNearFar) camera).getFar() ); } uniforms.get("opacity").setValue( getOpacity() ); diff --git a/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java b/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java index 9fe80667..cd46023d 100644 --- a/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java +++ b/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java @@ -140,12 +140,14 @@ public void render( Camera camera, List lights, int currentWidth, int cur double delta = 0; WebGLRenderingContext gl = getRenderer().getGL(); - + for ( Pass pass : this.passes ) { - Log.info("Postprocessing.render(): pass " + pass.getClass().getSimpleName() ); - if ( !pass.isEnabled() ) continue; + + Log.info(" ----> Postprocessing.render(): pass " + pass.getClass().getSimpleName() + + (pass.getClass().equals(ShaderPass.class) ? + "(" + ((ShaderPass)pass).getMaterial().getShader().getClass().getSimpleName() + ")" : "") ); pass.render( this, delta, maskActive ); diff --git a/src/thothbot/parallax/plugins/postprocessing/ShaderPass.java b/src/thothbot/parallax/plugins/postprocessing/ShaderPass.java index dadbce29..fee411da 100644 --- a/src/thothbot/parallax/plugins/postprocessing/ShaderPass.java +++ b/src/thothbot/parallax/plugins/postprocessing/ShaderPass.java @@ -57,6 +57,10 @@ public Map getUniforms() { return this.material.getShader().getUniforms(); } + public ShaderMaterial getMaterial() { + return this.material; + } + @Override public void render( Postprocessing postprocessing, double delta, boolean maskActive) { From 5dad77e6ae0ea71e78bac64720d1a98557f941f5 Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 17 Feb 2015 13:14:25 +0300 Subject: [PATCH 41/75] Updated release in comments --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7daa68b8..be0dcaf0 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The aim of the project is to use GWT which helps maintaining complex pieces of c Parallax supports WebGL-canvas renderer only. -### Download - new Parallax v1.4 ### +### Download - new Parallax v1.5 ### [Download JAR](http://github.com/thothbot/parallax/wiki/Download) | [Change log](http://github.com/thothbot/parallax/wiki/Change-log) From b66057b97f511a2f4725104f3d081a0cd2b9c804 Mon Sep 17 00:00:00 2001 From: thothbot Date: Tue, 17 Feb 2015 19:13:27 +0300 Subject: [PATCH 42/75] Updated URL for change log --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be0dcaf0..46817fac 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Parallax supports WebGL-canvas renderer only. ### Download - new Parallax v1.5 ### -[Download JAR](http://github.com/thothbot/parallax/wiki/Download) | [Change log](http://github.com/thothbot/parallax/wiki/Change-log) +[Download JAR](http://github.com/thothbot/parallax/wiki/Download) | [Change log](https://github.com/thothbot/parallax/releases) ### Examples ### From 99f25de4f9403e808a66d522d2caabb80242a2aa Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 23 Feb 2015 02:06:51 +0300 Subject: [PATCH 43/75] Fixed issue #21, Color.getHexString() --- src/thothbot/parallax/core/shared/math/Color.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thothbot/parallax/core/shared/math/Color.java b/src/thothbot/parallax/core/shared/math/Color.java index 5913593d..69aebe74 100644 --- a/src/thothbot/parallax/core/shared/math/Color.java +++ b/src/thothbot/parallax/core/shared/math/Color.java @@ -317,7 +317,7 @@ public int getHex() public String getHexString() { - return ( "000000" + Integer.toString(this.getHex(), 16).substring(-6)); + return Integer.toHexString(this.getHex()).toUpperCase(); } public Color.HSL getHSL() From 9888f9d5818f4acd9f0cc026bd5f3958b500e9db Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 23 Feb 2015 02:44:37 +0300 Subject: [PATCH 44/75] Fixed issue #18: using LineDashedMaterial with Line object --- .../shared/materials/LineBasicMaterial.java | 2 +- .../shared/materials/LineDashedMaterial.java | 78 +------------------ 2 files changed, 5 insertions(+), 75 deletions(-) diff --git a/src/thothbot/parallax/core/shared/materials/LineBasicMaterial.java b/src/thothbot/parallax/core/shared/materials/LineBasicMaterial.java index 17ad2a35..4f66a694 100644 --- a/src/thothbot/parallax/core/shared/materials/LineBasicMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/LineBasicMaterial.java @@ -32,7 +32,7 @@ * @author thothbot * */ -public final class LineBasicMaterial extends Material +public class LineBasicMaterial extends Material implements HasFog, HasColor, HasVertexColors { diff --git a/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java b/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java index 6ba865b0..7957a650 100644 --- a/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/LineDashedMaterial.java @@ -24,37 +24,20 @@ import thothbot.parallax.core.client.shaders.Shader; import thothbot.parallax.core.client.shaders.Uniform; import thothbot.parallax.core.shared.cameras.Camera; -import thothbot.parallax.core.shared.math.Color; /** * A material for drawing wireframe-style geometries with dashed lines. * */ -public class LineDashedMaterial extends Material implements - HasFog, HasColor, HasVertexColors +public class LineDashedMaterial extends LineBasicMaterial { - - private boolean isFog; - - private Color color; - - private Material.COLORS vertexColors; - - private double linewidth; - private double scale; private double dashSize; private double gapSize; public LineDashedMaterial() { - setFog(true); - - setColor(new Color(0xffffff)); - - setLinewidth(1.0); - - setVertexColors(Material.COLORS.NO); + super(); setScale(1.0); setDashSize(3.0); @@ -62,7 +45,7 @@ public LineDashedMaterial() } @Override - protected Shader getAssociatedShader() + public Shader getAssociatedShader() { return new DashedShader(); } @@ -99,66 +82,16 @@ public void setGapSize(double gapSize) { this.gapSize = gapSize; } - /** - * The size of the gap. Default is 1. - * @return - */ - public double getLinewidth() { - return this.linewidth; - } - - public void setLinewidth(double linewidth) { - this.linewidth = linewidth; - } - - @Override - public boolean isFog() { - return this.isFog; - } - - @Override - public void setFog(boolean fog) { - this.isFog = fog; - } - - @Override - public Color getColor() { - return color; - } - - @Override - public void setColor(Color color) { - this.color = color; - } - - @Override - public Material.COLORS isVertexColors() { - return this.vertexColors; - } - - @Override - public void setVertexColors(Material.COLORS vertexColors) { - this.vertexColors = vertexColors; - } - public LineDashedMaterial clone() { LineDashedMaterial material = new LineDashedMaterial(); super.clone(material); - material.color.copy( this.color ); - - material.linewidth = this.linewidth; - material.scale = this.scale; material.dashSize = this.dashSize; material.gapSize = this.gapSize; - material.vertexColors = this.vertexColors; - - material.isFog = this.isFog; - return material; } @@ -168,10 +101,7 @@ public void refreshUniforms(Camera camera, boolean isGammaInput) { super.refreshUniforms(camera, isGammaInput); Map uniforms = getShader().getUniforms(); - - uniforms.get("diffuse").setValue( getColor() ); - uniforms.get("opacity").setValue( getOpacity() ); - + uniforms.get("dashSize").setValue( getDashSize() ); uniforms.get("totalSize").setValue( getDashSize() + getGapSize() ); uniforms.get("scale").setValue( getScale() ); From 9963823092d0cac7e742259cd1f867d91e8da1c2 Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 23 Feb 2015 03:03:09 +0300 Subject: [PATCH 45/75] Added leading zeros for getHexString, issue #21 --- src/thothbot/parallax/core/shared/math/Color.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/thothbot/parallax/core/shared/math/Color.java b/src/thothbot/parallax/core/shared/math/Color.java index 69aebe74..8da7fc6e 100644 --- a/src/thothbot/parallax/core/shared/math/Color.java +++ b/src/thothbot/parallax/core/shared/math/Color.java @@ -317,7 +317,10 @@ public int getHex() public String getHexString() { - return Integer.toHexString(this.getHex()).toUpperCase(); + String hexString = Integer.toHexString(this.getHex()).toUpperCase(); + while(hexString.length() < 6) + hexString = "0" + hexString; + return hexString; } public Color.HSL getHSL() From 7dc3785a37527de201c08cbdb241d2d34544bbbc Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 23 Feb 2015 14:09:35 +0300 Subject: [PATCH 46/75] Fixed issue #25 in ShadowCamera helper --- .../parallax/core/client/renderers/ShadowMap.java | 2 +- .../parallax/core/shared/lights/ShadowLight.java | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/ShadowMap.java b/src/thothbot/parallax/core/client/renderers/ShadowMap.java index 07291f63..a567c23d 100644 --- a/src/thothbot/parallax/core/client/renderers/ShadowMap.java +++ b/src/thothbot/parallax/core/client/renderers/ShadowMap.java @@ -285,7 +285,7 @@ else if ( light instanceof DirectionalLight ) if ( light.isShadowCameraVisible() && light.getCameraHelper() == null ) { light.setCameraHelper( new CameraHelper( light.getShadowCamera() )); - light.getShadowCamera().add( light.getCameraHelper() ); + getScene().add( light.getCameraHelper() ); } if ( light instanceof VirtualLight && ((VirtualLight)light).getOriginalCamera() == camera ) diff --git a/src/thothbot/parallax/core/shared/lights/ShadowLight.java b/src/thothbot/parallax/core/shared/lights/ShadowLight.java index 6a9a1b9c..98ef4086 100644 --- a/src/thothbot/parallax/core/shared/lights/ShadowLight.java +++ b/src/thothbot/parallax/core/shared/lights/ShadowLight.java @@ -51,22 +51,15 @@ public abstract class ShadowLight extends Light private RenderTargetTexture shadowMap; private Vector2 shadowMapSize; private Matrix4 shadowMatrix; - - - + private CameraHelper cameraHelper; - - public ShadowLight(int hex) { super(hex); this.position = new Vector3(0, 1.0, 0); this.target = new Object3D(); - - -// this.shadowMatrix = new Matrix4(); } /** From 43e2a55f3cba30abc2b2a6e1abb26f59968d8f1b Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 23 Feb 2015 15:20:14 +0300 Subject: [PATCH 47/75] Some optimization --- .../parallax/core/client/renderers/WebGLRenderer.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index ecf61ee9..cf9c3dfc 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -2329,8 +2329,11 @@ private void initMaterial ( Material material, List lights, AbstractFog f parameters.supportsVertexTextures = this._supportsVertexTextures; - parameters.useFog = (fog != null); - parameters.useFog2 = (fog != null && fog.getClass() == FogExp2.class); + if(fog != null) + { + parameters.useFog = true; + parameters.useFog2 = (fog instanceof FogExp2); + } parameters.logarithmicDepthBuffer = this._logarithmicDepthBuffer; @@ -2784,7 +2787,7 @@ else if(type == TYPE.TV) //List of Texture (2d) setTexture( texture, textureUnit ); } - } + } } } From c948813b86658809a1d9f9f7f05991dbc99bf5eb Mon Sep 17 00:00:00 2001 From: ftosi Date: Mon, 23 Feb 2015 14:51:19 +0100 Subject: [PATCH 48/75] Added null check on XHRLoader.loaderProgressHandler --- src/thothbot/parallax/loader/shared/XHRLoader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/thothbot/parallax/loader/shared/XHRLoader.java b/src/thothbot/parallax/loader/shared/XHRLoader.java index bc86636e..1def8652 100644 --- a/src/thothbot/parallax/loader/shared/XHRLoader.java +++ b/src/thothbot/parallax/loader/shared/XHRLoader.java @@ -69,7 +69,9 @@ protected void load() request.send( null ); loadHandlers.add(modelLoadHandler); - XHRLoader.loaderProgressHandler.onProgressUpdate(loadHandlers.size()); + + if(XHRLoader.loaderProgressHandler != null) + XHRLoader.loaderProgressHandler.onProgressUpdate(loadHandlers.size()); request.setOnReadyStateChange(new ReadyStateChangeHandler() { From 981f82462791a6d281ed2b51d8e6c8279388b332 Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 23 Feb 2015 22:16:56 +0300 Subject: [PATCH 49/75] Fixed issue #5 --- .../core/shared/geometries/PlaneBufferGeometry.java | 8 ++++---- .../parallax/core/shared/geometries/PlaneGeometry.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/thothbot/parallax/core/shared/geometries/PlaneBufferGeometry.java b/src/thothbot/parallax/core/shared/geometries/PlaneBufferGeometry.java index 9d9c6536..8367630d 100644 --- a/src/thothbot/parallax/core/shared/geometries/PlaneBufferGeometry.java +++ b/src/thothbot/parallax/core/shared/geometries/PlaneBufferGeometry.java @@ -25,11 +25,11 @@ public class PlaneBufferGeometry extends BufferGeometry { - public PlaneBufferGeometry(int width, int height) { + public PlaneBufferGeometry(double width, double height) { this(width, height, 1, 1); } - public PlaneBufferGeometry(int width, int height, int widthSegments, int heightSegments) { + public PlaneBufferGeometry(double width, double height, int widthSegments, int heightSegments) { double width_half = width / 2.0; double height_half = height / 2.0; @@ -40,8 +40,8 @@ public PlaneBufferGeometry(int width, int height, int widthSegments, int heightS int gridX1 = gridX + 1; int gridY1 = gridY + 1; - int segment_width = width / gridX; - int segment_height = height / gridY; + int segment_width = (int) (width / gridX); + int segment_height = (int) (height / gridY); Float32Array vertices = Float32Array.create( gridX1 * gridY1 * 3 ); Float32Array normals = Float32Array.create( gridX1 * gridY1 * 3 ); diff --git a/src/thothbot/parallax/core/shared/geometries/PlaneGeometry.java b/src/thothbot/parallax/core/shared/geometries/PlaneGeometry.java index 520ac120..0851c66c 100644 --- a/src/thothbot/parallax/core/shared/geometries/PlaneGeometry.java +++ b/src/thothbot/parallax/core/shared/geometries/PlaneGeometry.java @@ -30,12 +30,12 @@ */ public final class PlaneGeometry extends Geometry { - public PlaneGeometry(int width, int height) + public PlaneGeometry(double width, double height) { this(width, height, 1, 1); } - public PlaneGeometry(int width, int height, int widthSegments, int heightSegments) + public PlaneGeometry(double width, double height, int widthSegments, int heightSegments) { super(); From 1b6fdaf0c20607c51e1583aeb831b36e1f2f9908 Mon Sep 17 00:00:00 2001 From: thothbot Date: Wed, 25 Feb 2015 13:02:25 +0300 Subject: [PATCH 50/75] Orginizaed imports and some refactoring --- .../core/client/renderers/WebGLRenderer.java | 28 +++++++++++-------- .../shared/cameras/OrthographicCamera.java | 1 - .../shared/materials/MeshDepthMaterial.java | 1 - .../plugins/sprite/SpriteMaterial.java | 1 - .../plugins/sprite/shaders/SpriteShader.java | 1 - 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index cf9c3dfc..cab3167e 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -73,8 +73,6 @@ import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.HasNearFar; -import thothbot.parallax.core.shared.cameras.OrthographicCamera; -import thothbot.parallax.core.shared.cameras.PerspectiveCamera; import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.BufferAttribute; import thothbot.parallax.core.shared.core.BufferGeometry; @@ -587,7 +585,7 @@ public WebGLRenderingContext getGL() return this.gl; } - private void setDefaultGLState () + private void setDefaultGLState() { getGL().clearColor( 0.0, 0.0, 0.0, 1.0 ); getGL().clearDepth( 1 ); @@ -1920,9 +1918,10 @@ public int compare(WebGLObject a, WebGLObject b) { { Material material = scene.getOverrideMaterial(); - this.setBlending( material.getBlending(), material.getBlendEquation(), material.getBlendSrc(), material.getBlendDst() ); - this.setDepthTest( material.isDepthTest() ); - this.setDepthWrite( material.isDepthWrite() ); + setBlending( material.getBlending(), material.getBlendEquation(), material.getBlendSrc(), material.getBlendDst() ); + setDepthTest( material.isDepthTest() ); + setDepthWrite( material.isDepthWrite() ); + setPolygonOffset( material.isPolygonOffset(), material.getPolygonOffsetFactor(), material.getPolygonOffsetUnits() ); renderObjects( opaqueObjects, camera, lights, fog, true, material ); @@ -2112,7 +2111,8 @@ private void renderObjects (List renderList, Camera camera, List
  • Date: Thu, 26 Feb 2015 01:16:28 +0300 Subject: [PATCH 51/75] Added GridHelper, issue #20 --- .../core/shared/helpers/GridHelper.java | 81 +++++++++++++++++++ .../parallax/core/shared/objects/Line.java | 7 +- 2 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/thothbot/parallax/core/shared/helpers/GridHelper.java diff --git a/src/thothbot/parallax/core/shared/helpers/GridHelper.java b/src/thothbot/parallax/core/shared/helpers/GridHelper.java new file mode 100644 index 00000000..41184d08 --- /dev/null +++ b/src/thothbot/parallax/core/shared/helpers/GridHelper.java @@ -0,0 +1,81 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.helpers; + +import thothbot.parallax.core.shared.core.Geometry; +import thothbot.parallax.core.shared.materials.LineBasicMaterial; +import thothbot.parallax.core.shared.materials.Material; +import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.objects.Line; + +// port from three.js r70 GridHelper.js +/** + * + * @author bartolomiew + * + */ +public class GridHelper extends Line { + + private Color color1; + private Color color2; + + public GridHelper(double size, double step) { + super(new Geometry(), new LineBasicMaterial(), Line.MODE.PIECES); + Geometry geometry = (Geometry) getGeometry(); + + LineBasicMaterial material = (LineBasicMaterial) getMaterial(); + material.setVertexColors(Material.COLORS.VERTEX); + + color1 = new Color(0x444444); + color2 = new Color(0x888888); + + for (double i = -size; i <= size; i += step) { + + geometry.getVertices().add(new Vector3(-size, 0, i)); + geometry.getVertices().add(new Vector3(size, 0, i)); + geometry.getVertices().add(new Vector3(i, 0, -size)); + geometry.getVertices().add(new Vector3(i, 0, size)); + + Color color = i == 0 ? this.color1 : this.color2; + + geometry.getColors().add(color); + geometry.getColors().add(color); + geometry.getColors().add(color); + geometry.getColors().add(color); + + } + } + + public void setColors(int colorCenterLine, int colorGrid) + { + setColors(new Color(colorCenterLine), new Color(colorGrid)); + } + + public void setColors(Color colorCenterLine, Color colorGrid) + { + + color1.copy( colorCenterLine ); + color2.copy( colorGrid ); + + geometry.setColorsNeedUpdate(true); + + } + +} \ No newline at end of file diff --git a/src/thothbot/parallax/core/shared/objects/Line.java b/src/thothbot/parallax/core/shared/objects/Line.java index c01fe291..37db2661 100644 --- a/src/thothbot/parallax/core/shared/objects/Line.java +++ b/src/thothbot/parallax/core/shared/objects/Line.java @@ -29,6 +29,7 @@ import thothbot.parallax.core.client.renderers.WebGLRenderer; import thothbot.parallax.core.client.renderers.WebGlRendererInfo; import thothbot.parallax.core.client.shaders.Attribute; +import thothbot.parallax.core.shared.core.AbstractGeometry; import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.core.GeometryObject; import thothbot.parallax.core.shared.core.Raycaster; @@ -79,12 +80,12 @@ public Line() { this(new Geometry()); } - public Line(Geometry geometry) + public Line(AbstractGeometry geometry) { this(geometry, Line.defaultMaterial, Line.MODE.STRIPS); } - public Line(Geometry geometry, LineBasicMaterial material) + public Line(AbstractGeometry geometry, LineBasicMaterial material) { this(geometry, material, Line.MODE.STRIPS); } @@ -96,7 +97,7 @@ public Line(Geometry geometry, LineBasicMaterial material) * @param material Material for the line. Default is {@link LineBasicMaterial}. * @param mode Connection type between vertices. Default is {@link Line.MODE}.STRIPS. */ - public Line(Geometry geometry, LineBasicMaterial material, Line.MODE mode) + public Line(AbstractGeometry geometry, LineBasicMaterial material, Line.MODE mode) { super(geometry, material); From c0cfaaf32d01f3fd731907e717058f7f95349055 Mon Sep 17 00:00:00 2001 From: thothbot Date: Thu, 26 Feb 2015 01:25:48 +0300 Subject: [PATCH 52/75] Added PointLightHelper --- .../core/shared/helpers/PointLightHelper.java | 54 +++++++++++++++++++ .../parallax/core/shared/math/Color.java | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/thothbot/parallax/core/shared/helpers/PointLightHelper.java diff --git a/src/thothbot/parallax/core/shared/helpers/PointLightHelper.java b/src/thothbot/parallax/core/shared/helpers/PointLightHelper.java new file mode 100644 index 00000000..7f0ea296 --- /dev/null +++ b/src/thothbot/parallax/core/shared/helpers/PointLightHelper.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.helpers; + +import thothbot.parallax.core.shared.geometries.SphereGeometry; +import thothbot.parallax.core.shared.lights.PointLight; +import thothbot.parallax.core.shared.materials.MeshBasicMaterial; +import thothbot.parallax.core.shared.objects.Mesh; + +public class PointLightHelper extends Mesh { + + PointLight light; + + public PointLightHelper(PointLight light, double sphereSize) + { + super(new SphereGeometry( sphereSize, 4, 2 ), new MeshBasicMaterial()); + + this.light = light; + this.light.updateMatrixWorld(false); + + MeshBasicMaterial material = (MeshBasicMaterial) getMaterial(); + material.setWireframe(true); + material.setFog(false); + material.getColor().copy( this.light.getColor() ).multiply( this.light.getIntensity() ); + + setMatrix( this.light.getMatrixWorld() ); + setMatrixAutoUpdate(false); + + + } + + public void update () { + + ((MeshBasicMaterial)getMaterial()).getColor() + .copy( this.light.getColor() ) + .multiply( this.light.getIntensity() ); + } +} diff --git a/src/thothbot/parallax/core/shared/math/Color.java b/src/thothbot/parallax/core/shared/math/Color.java index 8da7fc6e..2b6dc0d8 100644 --- a/src/thothbot/parallax/core/shared/math/Color.java +++ b/src/thothbot/parallax/core/shared/math/Color.java @@ -417,7 +417,7 @@ public Color multiply( Color color ) return this; } - public Color multiply( int s ) + public Color multiply( double s ) { this.r *= s; From d663cfac9263d27fff08c3b26c4a42033222a6a7 Mon Sep 17 00:00:00 2001 From: thothbot Date: Thu, 26 Feb 2015 01:30:57 +0300 Subject: [PATCH 53/75] Added WireframeHelper --- .../core/shared/helpers/WireframeHelper.java | 226 ++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 src/thothbot/parallax/core/shared/helpers/WireframeHelper.java diff --git a/src/thothbot/parallax/core/shared/helpers/WireframeHelper.java b/src/thothbot/parallax/core/shared/helpers/WireframeHelper.java new file mode 100644 index 00000000..cb84f7b0 --- /dev/null +++ b/src/thothbot/parallax/core/shared/helpers/WireframeHelper.java @@ -0,0 +1,226 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.helpers; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import thothbot.parallax.core.client.gl2.arrays.Float32Array; +import thothbot.parallax.core.client.gl2.arrays.Uint16Array; +import thothbot.parallax.core.client.gl2.arrays.Uint32Array; +import thothbot.parallax.core.shared.core.BufferAttribute; +import thothbot.parallax.core.shared.core.BufferGeometry; +import thothbot.parallax.core.shared.core.BufferGeometry.DrawCall; +import thothbot.parallax.core.shared.core.Face3; +import thothbot.parallax.core.shared.core.FastMap; +import thothbot.parallax.core.shared.core.Geometry; +import thothbot.parallax.core.shared.core.GeometryObject; +import thothbot.parallax.core.shared.materials.LineBasicMaterial; +import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.objects.Line; + +import com.google.gwt.core.client.GWT; + +public class WireframeHelper extends Line { + + public WireframeHelper(GeometryObject object) + { + this(object, new Color(0xffffff)); + } + + public WireframeHelper(GeometryObject object, Color color) + { + super(new BufferGeometry(), new LineBasicMaterial(), Line.MODE.PIECES); + + LineBasicMaterial material = (LineBasicMaterial) getMaterial(); + material.setColor( color ); + + BufferGeometry geometry = (BufferGeometry) getGeometry(); + + int[] edge = new int[]{ 0, 0 }; + Map hash = GWT.isScript() ? + new FastMap() : new HashMap(); + + if(object.getGeometry() instanceof Geometry) + { + List vertices = ((Geometry)object.getGeometry()).getVertices(); + List faces = ((Geometry)object.getGeometry()).getFaces(); + int numEdges = 0; + + // allocate maximal size + Uint32Array edges = Uint32Array.create( 6 * faces.size() ); + + for ( int i = 0, l = faces.size(); i < l; i ++ ) { + + Face3 face = faces.get( i ); + + for ( int j = 0; j < 3; j ++ ) { + + edge[ 0 ] = face.getFlat()[j]; + edge[ 1 ] = face.getFlat()[( j + 1 ) % 3 ]; + Arrays.sort(edge); + + String key = "" + edge[0] + edge[1]; + + if ( !hash.containsKey(key) ) + { + edges.set( 2 * numEdges, edge[ 0 ]); + edges.set( 2 * numEdges + 1, edge[ 1 ]); + hash.put(key, true); + numEdges ++; + } + + } + + } + + Float32Array coords = Float32Array.create( numEdges * 2 * 3 ); + + for ( int i = 0, l = numEdges; i < l; i ++ ) { + + for ( int j = 0; j < 2; j ++ ) { + + Vector3 vertex = vertices.get( edges.get( 2 * i + j ) ); + + int index = 6 * i + 3 * j; + coords.set( index + 0 , vertex.getX()); + coords.set( index + 1 , vertex.getY()); + coords.set( index + 2 , vertex.getZ()); + + } + + } + + geometry.addAttribute( "position", new BufferAttribute( coords, 3 ) ); + + + + } + else if ( object.getGeometry() instanceof BufferGeometry ) + { + + // Indexed BufferGeometry + if ( ((BufferGeometry)object.getGeometry()).getAttribute("index") != null ) { + + Float32Array vertices = (Float32Array) ((BufferGeometry)object.getGeometry()).getAttribute("position").getArray(); + Uint16Array indices = (Uint16Array) ((BufferGeometry)object.getGeometry()).getAttribute("index").getArray(); + List drawcalls = ((BufferGeometry)object.getGeometry()).getDrawcalls(); + int numEdges = 0; + + if ( drawcalls.size() == 0 ) + { + drawcalls = Arrays.asList( new DrawCall(0, indices.getLength(), 9) ); + } + + // allocate maximal size + Uint32Array edges = Uint32Array.create( 2 * indices.getLength() ); + + for ( int o = 0, ol = drawcalls.size(); o < ol; ++ o ) { + + int start = drawcalls.get( o ).start; + int count = drawcalls.get( o ).count; + int index = drawcalls.get( o ).index; + + for ( int i = start, il = start + count; i < il; i += 3 ) { + + for ( int j = 0; j < 3; j ++ ) { + + edge[ 0 ] = index + indices.get( i + j ); + edge[ 1 ] = index + indices.get( i + ( j + 1 ) % 3 ); + Arrays.sort(edge); + + String key = "" + edge[0] + edge[1]; + + if ( !hash.containsKey(key) ) + { + edges.set( 2 * numEdges, edge[ 0 ]); + edges.set( 2 * numEdges + 1, edge[ 1 ]); + hash.put(key, true); + numEdges ++; + } + + } + + } + + } + + Float32Array coords = Float32Array.create( numEdges * 2 * 3 ); + + for ( int i = 0, l = numEdges; i < l; i ++ ) { + + for ( int j = 0; j < 2; j ++ ) { + + int index = 6 * i + 3 * j; + int index2 = 3 * edges.get( 2 * i + j); + coords.set( index + 0 , vertices.get( index2 ) ); + coords.set( index + 1 , vertices.get( index2 + 1 ) ); + coords.set( index + 2 , vertices.get( index2 + 2 ) ); + + } + + } + + geometry.addAttribute( "position", new BufferAttribute( coords, 3 ) ); + + } + // non-indexed BufferGeometry + else + { + + Float32Array vertices = (Float32Array) ((BufferGeometry)object.getGeometry()).getAttribute("position").getArray(); + int numEdges = vertices.getLength() / 3; + int numTris = numEdges / 3; + + Float32Array coords = Float32Array.create( numEdges * 2 * 3 ); + + for ( int i = 0, l = numTris; i < l; i ++ ) { + + for ( int j = 0; j < 3; j ++ ) { + + int index = 18 * i + 6 * j; + + int index1 = 9 * i + 3 * j; + coords.set( index + 0 , vertices.get( index1 ) ); + coords.set( index + 1 , vertices.get( index1 + 1 ) ); + coords.set( index + 2 , vertices.get( index1 + 2 ) ); + + int index2 = 9 * i + 3 * ( ( j + 1 ) % 3 ); + coords.set( index + 3 , vertices.get( index2 ) ); + coords.set( index + 4 , vertices.get( index2 + 1 ) ); + coords.set( index + 5 , vertices.get( index2 + 2 ) ); + + } + + } + + geometry.addAttribute( "position", new BufferAttribute( coords, 3 ) ); + + } + + } + + this.setMatrix( object.getMatrixWorld() ); + this.setMatrixAutoUpdate( false ); + } + +} From d46b2d67cb622d3efbbece99cd2ccebdd1c7dcdd Mon Sep 17 00:00:00 2001 From: thothbot Date: Thu, 26 Feb 2015 01:41:57 +0300 Subject: [PATCH 54/75] Added BoxHelper --- .../core/shared/helpers/BoxHelper.java | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/thothbot/parallax/core/shared/helpers/BoxHelper.java diff --git a/src/thothbot/parallax/core/shared/helpers/BoxHelper.java b/src/thothbot/parallax/core/shared/helpers/BoxHelper.java new file mode 100644 index 00000000..c056fd85 --- /dev/null +++ b/src/thothbot/parallax/core/shared/helpers/BoxHelper.java @@ -0,0 +1,129 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.helpers; + +import thothbot.parallax.core.client.gl2.arrays.Float32Array; +import thothbot.parallax.core.shared.core.AbstractGeometry; +import thothbot.parallax.core.shared.core.BufferAttribute; +import thothbot.parallax.core.shared.core.BufferGeometry; +import thothbot.parallax.core.shared.materials.LineBasicMaterial; +import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.objects.Line; +import thothbot.parallax.core.shared.objects.Mesh; + +public class BoxHelper extends Line +{ + public BoxHelper(Mesh object) + { + super(new BufferGeometry(), new LineBasicMaterial(), Line.MODE.PIECES); + + BufferGeometry geometry = (BufferGeometry) getGeometry(); + LineBasicMaterial material = (LineBasicMaterial) getMaterial(); + material.setColor(new Color(0xffff00)); + + + geometry.addAttribute( "position", new BufferAttribute( Float32Array.create( 72 ), 3 ) ); + + update( object ); + + } + + public void update( Mesh object ) + { + + AbstractGeometry geometry = object.getGeometry(); + + if ( geometry.getBoundingBox() == null ) { + + geometry.computeBoundingBox(); + + } + + Vector3 min = geometry.getBoundingBox().getMin(); + Vector3 max = geometry.getBoundingBox().getMax(); + + /* + 5____4 + 1/___0/| + | 6__|_7 + 2/___3/ + + 0: max.x, max.y, max.z + 1: min.x, max.y, max.z + 2: min.x, min.y, max.z + 3: max.x, min.y, max.z + 4: max.x, max.y, min.z + 5: min.x, max.y, min.z + 6: min.x, min.y, min.z + 7: max.x, min.y, min.z + */ + + Float32Array vertices = (Float32Array) ((BufferGeometry)this.geometry).getAttribute("position").getArray(); + + vertices.set( 0 , max.getX() ); vertices.set( 1 , max.getY() ); vertices.set( 2 , max.getZ() ); + vertices.set( 3 , min.getX() ); vertices.set( 4 , max.getY() ); vertices.set( 5 , max.getZ() ); + + vertices.set( 6 , min.getX() ); vertices.set( 7 , max.getY() ); vertices.set( 8 , max.getZ() ); + vertices.set( 9 , min.getX() ); vertices.set( 10 , min.getY() ); vertices.set( 11 , max.getZ() ); + + vertices.set( 12 , min.getX() ); vertices.set( 13 , min.getY() ); vertices.set( 14 , max.getZ() ); + vertices.set( 15 , max.getX() ); vertices.set( 16 , min.getY() ); vertices.set( 17 , max.getZ() ); + + vertices.set( 18 , max.getX() ); vertices.set( 19 , min.getY() ); vertices.set( 20 , max.getZ() ); + vertices.set( 21 , max.getX() ); vertices.set( 22 , max.getY() ); vertices.set( 23 , max.getZ() ); + + // + + vertices.set( 24 , max.getX() ); vertices.set( 25 , max.getY() ); vertices.set( 26 , min.getZ() ); + vertices.set( 27 , min.getX() ); vertices.set( 28 , max.getY() ); vertices.set( 29 , min.getZ() ); + + vertices.set( 30 , min.getX() ); vertices.set( 31 , max.getY() ); vertices.set( 32 , min.getZ() ); + vertices.set( 33 , min.getX() ); vertices.set( 34 , min.getY() ); vertices.set( 35 , min.getZ() ); + + vertices.set( 36 , min.getX() ); vertices.set( 37 , min.getY() ); vertices.set( 38 , min.getZ() ); + vertices.set( 39 , max.getX() ); vertices.set( 40 , min.getY() ); vertices.set( 41 , min.getZ() ); + + vertices.set( 42 , max.getX() ); vertices.set( 43 , min.getY() ); vertices.set( 44 , min.getZ() ); + vertices.set( 45 , max.getX() ); vertices.set( 46 , max.getY() ); vertices.set( 47 , min.getZ() ); + + // + + vertices.set( 48 , max.getX() ); vertices.set( 49 , max.getY() ); vertices.set( 50 , max.getZ() ); + vertices.set( 51 , max.getX() ); vertices.set( 52 , max.getY() ); vertices.set( 53 , min.getZ() ); + + vertices.set( 54 , min.getX() ); vertices.set( 55 , max.getY() ); vertices.set( 56 , max.getZ() ); + vertices.set( 57 , min.getX() ); vertices.set( 58 , max.getY() ); vertices.set( 59 , min.getZ() ); + + vertices.set( 60 , min.getX() ); vertices.set( 61 , min.getY() ); vertices.set( 62 , max.getZ() ); + vertices.set( 63 , min.getX() ); vertices.set( 64 , min.getY() ); vertices.set( 65 , min.getZ() ); + + vertices.set( 66 , max.getX() ); vertices.set( 67 , min.getY() ); vertices.set( 68 , max.getZ() ); + vertices.set( 69 , max.getX() ); vertices.set( 70 , min.getY() ); vertices.set( 71 , min.getZ() ); + + ((BufferGeometry)this.geometry).getAttribute("position").setNeedsUpdate(true); + + this.geometry.computeBoundingSphere(); + + setMatrix( object.getMatrixWorld() ); + this.setMatrixAutoUpdate(false); + + } + +} From 3ef70f8b7d9055eab1b6fd98c09c1acb40c49040 Mon Sep 17 00:00:00 2001 From: thothbot Date: Thu, 26 Feb 2015 01:55:37 +0300 Subject: [PATCH 55/75] Added FaceNormalsHelper --- .../shared/helpers/FaceNormalsHelper.java | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 src/thothbot/parallax/core/shared/helpers/FaceNormalsHelper.java diff --git a/src/thothbot/parallax/core/shared/helpers/FaceNormalsHelper.java b/src/thothbot/parallax/core/shared/helpers/FaceNormalsHelper.java new file mode 100644 index 00000000..73422cdf --- /dev/null +++ b/src/thothbot/parallax/core/shared/helpers/FaceNormalsHelper.java @@ -0,0 +1,119 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.helpers; + +import java.util.Arrays; +import java.util.List; + +import thothbot.parallax.core.shared.core.Face3; +import thothbot.parallax.core.shared.core.Geometry; +import thothbot.parallax.core.shared.materials.LineBasicMaterial; +import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.core.shared.math.Matrix3; +import thothbot.parallax.core.shared.math.Matrix4; +import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.objects.Line; +import thothbot.parallax.core.shared.objects.Mesh; + +public class FaceNormalsHelper extends Line +{ + + Mesh object; + double size; + Matrix3 normalMatrix; + + public FaceNormalsHelper(Mesh object) + { + this(object, 1.0); + } + + public FaceNormalsHelper(Mesh object, double size ) + { + this(object, size, 0xffff00); + } + + public FaceNormalsHelper(Mesh object, double size, int hex ) + { + this(object, size, hex, 1); + } + + public FaceNormalsHelper(Mesh object, double size, int hex, int linewidth ) + { + super(new Geometry(), new LineBasicMaterial(), Line.MODE.PIECES); + + this.object = object; + this.size = size; + + LineBasicMaterial material = (LineBasicMaterial) getMaterial(); + material.setColor(new Color(hex)); + material.setLinewidth(linewidth); + + Geometry geometry = (Geometry) getGeometry(); + + List faces = ((Geometry)this.object.getGeometry()).getFaces(); + + for ( int i = 0, l = faces.size(); i < l; i ++ ) { + + geometry.getVertices().addAll( Arrays.asList( new Vector3(), new Vector3() ) ); + + } + + setMatrixAutoUpdate(false); + + this.normalMatrix = new Matrix3(); + + this.update(); + + } + + public void update() + { + + List vertices = ((Geometry)this.getGeometry()).getVertices(); + + List objectVertices = ((Geometry)object.getGeometry()).getVertices(); + List objectFaces = ((Geometry)object.getGeometry()).getFaces(); + Matrix4 objectWorldMatrix = object.getMatrixWorld(); + + object.updateMatrixWorld( true ); + + this.normalMatrix.getNormalMatrix( objectWorldMatrix ); + + for ( int i = 0, i2 = 0, l = objectFaces.size(); i < l; i ++, i2 += 2 ) { + + Face3 face = objectFaces.get( i ); + + vertices.get( i2 ).copy( objectVertices.get( face.getA() ) ) + .add( objectVertices.get( face.getB() ) ) + .add( objectVertices.get( face.getC() ) ) + .divide( 3 ) + .apply( objectWorldMatrix ); + + vertices.get( i2 + 1 ).copy( face.getNormal() ) + .apply( this.normalMatrix ) + .normalize() + .multiply( this.size ) + .add( vertices.get( i2 ) ); + + } + + this.geometry.setVerticesNeedUpdate(true); + + } +} From 9d56d55815ad58bbd3ab3972e74b589b662794f8 Mon Sep 17 00:00:00 2001 From: thothbot Date: Thu, 26 Feb 2015 02:19:10 +0300 Subject: [PATCH 56/75] Added VertexNormalsHelper --- .../shared/helpers/VertexNormalsHelper.java | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/thothbot/parallax/core/shared/helpers/VertexNormalsHelper.java diff --git a/src/thothbot/parallax/core/shared/helpers/VertexNormalsHelper.java b/src/thothbot/parallax/core/shared/helpers/VertexNormalsHelper.java new file mode 100644 index 00000000..c169caf8 --- /dev/null +++ b/src/thothbot/parallax/core/shared/helpers/VertexNormalsHelper.java @@ -0,0 +1,139 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.helpers; + +import java.util.Arrays; +import java.util.List; + +import thothbot.parallax.core.shared.core.Face3; +import thothbot.parallax.core.shared.core.Geometry; +import thothbot.parallax.core.shared.materials.LineBasicMaterial; +import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.core.shared.math.Matrix3; +import thothbot.parallax.core.shared.math.Matrix4; +import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.objects.Line; +import thothbot.parallax.core.shared.objects.Mesh; + +public class VertexNormalsHelper extends Line +{ + Mesh object; + double size; + Matrix3 normalMatrix; + + public VertexNormalsHelper(Mesh object) + { + this(object, 1.0); + } + + public VertexNormalsHelper(Mesh object, double size ) + { + this(object, size, 0xff0000); + } + + public VertexNormalsHelper(Mesh object, double size, int hex ) + { + this(object, size, hex, 1); + } + + public VertexNormalsHelper(Mesh object, double size, int hex, int linewidth ) + { + super(new Geometry(), new LineBasicMaterial(), Line.MODE.PIECES); + + this.object = object; + this.size = size; + + LineBasicMaterial material = (LineBasicMaterial) getMaterial(); + material.setColor(new Color(hex)); + material.setLinewidth(linewidth); + + Geometry geometry = (Geometry) getGeometry(); + + List faces = ((Geometry)this.object.getGeometry()).getFaces(); + + for ( int i = 0, l = faces.size(); i < l; i ++ ) { + + Face3 face = faces.get( i ); + + for ( int j = 0, jl = face.getVertexNormals().size(); j < jl; j ++ ) + { + + geometry.getVertices().addAll( Arrays.asList( new Vector3(), new Vector3() ) ); + + } + + } + + setMatrixAutoUpdate(false); + + this.normalMatrix = new Matrix3(); + + this.update(); + + } + + Vector3 v1 = new Vector3(); + public void update() + { + + this.object.updateMatrixWorld( true ); + + this.normalMatrix.getNormalMatrix( this.object.getMatrixWorld() ); + + List vertices = ((Geometry)this.getGeometry()).getVertices(); + + List verts = ((Geometry)object.getGeometry()).getVertices(); + List faces = ((Geometry)object.getGeometry()).getFaces(); + Matrix4 worldMatrix = object.getMatrixWorld(); + + int idx = 0; + int vsize = vertices.size(); + + for ( int i = 0, l = faces.size(); i < l; i ++ ) { + + Face3 face = faces.get( i ); + + for ( int j = 0, jl = face.getVertexNormals().size(); j < jl; j ++ ) { + + int vertexId = face.getFlat()[ j ]; + Vector3 vertex = verts.get( vertexId ); + + Vector3 normal = face.getVertexNormals().get( j ); + + if(vsize > idx) + { + vertices.get( idx ).copy( vertex ).apply( worldMatrix ); + + v1.copy( normal ).apply( this.normalMatrix ).normalize().multiply( this.size ); + + v1.add( vertices.get( idx ) ); + idx = idx + 1; + + vertices.get( idx ).copy( v1 ); + idx = idx + 1; + } + + } + + } + + this.geometry.setVerticesNeedUpdate(true); + + } +} From 6b97e89c4ba1e0f9750c88c0b6241e479960dcd6 Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 27 Feb 2015 00:42:31 +0300 Subject: [PATCH 57/75] Added some experiment classes to raytracing randering --- .../client/renderers/RaytracingRenderer.java | 23 +++++++++++++ .../shared/geometries/TorusKnotGeometry.java | 5 +++ .../HasRaytracingPhysicalAttenuation.java | 27 +++++++++++++++ .../core/shared/lights/PointLight.java | 25 ++++++++++++-- .../shared/materials/HasRaytracingGlass.java | 34 +++++++++++++++++++ .../shared/materials/HasRaytracingMirror.java | 34 +++++++++++++++++++ .../shared/materials/MeshPhongMaterial.java | 30 +++++++++++++++- 7 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java create mode 100644 src/thothbot/parallax/core/shared/helpers/HasRaytracingPhysicalAttenuation.java create mode 100644 src/thothbot/parallax/core/shared/materials/HasRaytracingGlass.java create mode 100644 src/thothbot/parallax/core/shared/materials/HasRaytracingMirror.java diff --git a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java new file mode 100644 index 00000000..e9001d3f --- /dev/null +++ b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.client.renderers; + +public class RaytracingRenderer { + +} diff --git a/src/thothbot/parallax/core/shared/geometries/TorusKnotGeometry.java b/src/thothbot/parallax/core/shared/geometries/TorusKnotGeometry.java index d242476f..eeb66f9b 100644 --- a/src/thothbot/parallax/core/shared/geometries/TorusKnotGeometry.java +++ b/src/thothbot/parallax/core/shared/geometries/TorusKnotGeometry.java @@ -41,6 +41,11 @@ public TorusKnotGeometry() this(200, 40, 64, 8); } + public TorusKnotGeometry(int radius) + { + this(radius, 40, 64, 8); + } + public TorusKnotGeometry(int radius, int tube, int segmentsR, int segmentsT) { this(radius, tube, segmentsR, segmentsT, 2, 3, 1); diff --git a/src/thothbot/parallax/core/shared/helpers/HasRaytracingPhysicalAttenuation.java b/src/thothbot/parallax/core/shared/helpers/HasRaytracingPhysicalAttenuation.java new file mode 100644 index 00000000..30ac6669 --- /dev/null +++ b/src/thothbot/parallax/core/shared/helpers/HasRaytracingPhysicalAttenuation.java @@ -0,0 +1,27 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.helpers; + +public interface HasRaytracingPhysicalAttenuation +{ + + public boolean isPhysicalAttenuation(); + + public void setPhysicalAttenuation(boolean isPhysicalAttenuation); +} diff --git a/src/thothbot/parallax/core/shared/lights/PointLight.java b/src/thothbot/parallax/core/shared/lights/PointLight.java index 17f76830..4925886f 100644 --- a/src/thothbot/parallax/core/shared/lights/PointLight.java +++ b/src/thothbot/parallax/core/shared/lights/PointLight.java @@ -23,6 +23,7 @@ import thothbot.parallax.core.client.gl2.arrays.Float32Array; import thothbot.parallax.core.client.renderers.RendererLights; import thothbot.parallax.core.client.shaders.Uniform; +import thothbot.parallax.core.shared.helpers.HasRaytracingPhysicalAttenuation; import thothbot.parallax.core.shared.materials.MeshLambertMaterial; import thothbot.parallax.core.shared.materials.MeshPhongMaterial; import thothbot.parallax.core.shared.math.Vector3; @@ -41,7 +42,7 @@ * @author thothbot * */ -public class PointLight extends Light +public class PointLight extends Light implements HasRaytracingPhysicalAttenuation { public static class UniformPoint implements Light.UniformLight { @@ -71,14 +72,21 @@ public void refreshUniform(Map uniforms) private double intensity; private double distance; + private boolean isPhysicalAttenuation; + public PointLight(int hex) { this(hex, 1.0, 0.0); } - public PointLight(int color, double intensity, double distance ) + public PointLight(int hex, double intensity) + { + this(hex, intensity, 0.0); + } + + public PointLight(int hex, double intensity, double distance ) { - super(color); + super(hex); this.intensity = intensity; this.distance = distance; } @@ -98,6 +106,16 @@ public void setDistance(double distance) { public double getDistance() { return distance; } + + @Override + public boolean isPhysicalAttenuation() { + return isPhysicalAttenuation; + } + + @Override + public void setPhysicalAttenuation(boolean isPhysicalAttenuation) { + this.isPhysicalAttenuation = isPhysicalAttenuation; + } public PointLight clone() { @@ -137,4 +155,5 @@ public void setupRendererLights(RendererLights zlights, boolean isGammaInput) pointDistances.set( pointOffset / 3, distance ); } + } diff --git a/src/thothbot/parallax/core/shared/materials/HasRaytracingGlass.java b/src/thothbot/parallax/core/shared/materials/HasRaytracingGlass.java new file mode 100644 index 00000000..3ec52365 --- /dev/null +++ b/src/thothbot/parallax/core/shared/materials/HasRaytracingGlass.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.materials; + +import thothbot.parallax.core.shared.math.Color; + +/** + * + * @author thothbot + * + */ +public interface HasRaytracingGlass +{ + + public boolean isGlass(); + + public void setGlass(boolean isGlass); +} diff --git a/src/thothbot/parallax/core/shared/materials/HasRaytracingMirror.java b/src/thothbot/parallax/core/shared/materials/HasRaytracingMirror.java new file mode 100644 index 00000000..48ea6974 --- /dev/null +++ b/src/thothbot/parallax/core/shared/materials/HasRaytracingMirror.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.materials; + +import thothbot.parallax.core.shared.math.Color; + +/** + * + * @author thothbot + * + */ +public interface HasRaytracingMirror +{ + + public boolean isMirror(); + + public void setMirror(boolean isMirror); +} diff --git a/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java b/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java index fff28a8d..7a0b25b6 100644 --- a/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java +++ b/src/thothbot/parallax/core/shared/materials/MeshPhongMaterial.java @@ -36,7 +36,11 @@ */ public final class MeshPhongMaterial extends Material implements HasMaterialMap, HasBumpMap, HasNormalMap, HasWrap, HasWireframe, HasFog, HasVertexColors, - HasSkinning, HasAmbientEmissiveColor, HasShading + HasSkinning, HasAmbientEmissiveColor, HasShading, + + //Raytracing + HasRaytracingMirror, HasRaytracingGlass + { private Color color; @@ -84,6 +88,9 @@ public final class MeshPhongMaterial extends Material private int numSupportedMorphTargets; private int numSupportedMorphNormals; + private boolean isMirror; + private boolean isGlass; + public MeshPhongMaterial() { setWrapRGB(new Vector3( 1, 1, 1 )); @@ -413,6 +420,26 @@ public void setShading(Material.SHADING shading) { this.shading = shading; } + @Override + public boolean isGlass() { + return isGlass; + } + + @Override + public void setGlass(boolean isGlass) { + this.isGlass = isGlass; + } + + @Override + public boolean isMirror() { + return isMirror; + } + + @Override + public void setMirror(boolean isMirror) { + this.isMirror = isMirror; + } + public MeshPhongMaterial clone() { MeshPhongMaterial material = new MeshPhongMaterial(); @@ -490,4 +517,5 @@ public void refreshUniforms(Camera camera, boolean isGammaInput) if ( isWrapAround() ) ((Vector3) uniforms.get("wrapRGB").getValue()).copy( getWrapRGB() ); } + } From 7a71d7446b55c04e71a5377040c222933a190910 Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 27 Feb 2015 00:49:38 +0300 Subject: [PATCH 58/75] Added AbstractRenderer --- .../client/renderers/AbstractRenderer.java | 24 +++++++++++++++++++ .../client/renderers/RaytracingRenderer.java | 3 ++- .../core/client/renderers/WebGLRenderer.java | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/thothbot/parallax/core/client/renderers/AbstractRenderer.java diff --git a/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java b/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java new file mode 100644 index 00000000..aa4e3933 --- /dev/null +++ b/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.client.renderers; + +public abstract class AbstractRenderer +{ + +} diff --git a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java index e9001d3f..c6a6410b 100644 --- a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java @@ -18,6 +18,7 @@ package thothbot.parallax.core.client.renderers; -public class RaytracingRenderer { +public class RaytracingRenderer extends AbstractRenderer +{ } diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index cab3167e..b85d206e 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -127,7 +127,7 @@ /** * The WebGL renderer displays your beautifully crafted {@link Scene}s using WebGL, if your device supports it. */ -public class WebGLRenderer implements HasEventBus +public class WebGLRenderer extends AbstractRenderer implements HasEventBus { // The HTML5 Canvas's 'webgl' context obtained from the canvas where the renderer will draw. private WebGLRenderingContext gl; From 7addd222de15898445066964255ed453c83c3e19 Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 27 Feb 2015 01:51:45 +0300 Subject: [PATCH 59/75] Moved clearColor & alpha to abstractRenderer --- .../client/renderers/AbstractRenderer.java | 52 ++++++++++++++++ .../client/renderers/RaytracingRenderer.java | 8 +++ .../core/client/renderers/WebGLRenderer.java | 61 ++----------------- 3 files changed, 65 insertions(+), 56 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java b/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java index aa4e3933..99357d61 100644 --- a/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java @@ -18,7 +18,59 @@ package thothbot.parallax.core.client.renderers; +import thothbot.parallax.core.shared.math.Color; + public abstract class AbstractRenderer { + // Default Color and alpha + protected Color clearColor = new Color(0x000000); + protected double clearAlpha = 1.0; + + public void setClearColor( int hex ) + { + setClearColor(new Color(hex)); + } + + public void setClearColor( Color color ) + { + setClearColor(color, 1.0); + } + + /** + * Sets the the background color, using hex for the color.
    + * + * @param hex the clear color value. + */ + public void setClearColor( int hex, double alpha ) + { + setClearColor(new Color(hex), alpha); + } + + /** + * Sets the the background color, using {@link Color} for the color and alpha for the opacity. + * + * @param color the {@link Color} instance. + * @param alpha the opacity of the scene's background color, range 0.0 (invisible) to 1.0 (opaque). + */ + public abstract void setClearColor( Color color, double alpha ); + + /** + * Returns the background color. + * + * @return the {@link Color} instance. + */ + public Color getClearColor() + { + return this.clearColor; + } + /** + * Returns the opacity of the scene's background color, range 0.0 (invisible) to 1.0 (opaque) + * + * @return the value in range <0,1>. + */ + public double getClearAlpha() + { + return this.clearAlpha; + } } diff --git a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java index c6a6410b..5269dfbf 100644 --- a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java @@ -18,7 +18,15 @@ package thothbot.parallax.core.client.renderers; +import thothbot.parallax.core.shared.math.Color; + public class RaytracingRenderer extends AbstractRenderer { + @Override + public void setClearColor(Color color, double alpha) + { + this.clearColor.copy(color); + } + } diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index b85d206e..3dc18dd9 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -134,10 +134,6 @@ public class WebGLRenderer extends AbstractRenderer implements HasEventBus private WebGlRendererInfo info; - // Default Color and alpha - private Color _clearColor = new Color(0x000000); - private double _clearAlpha = 1.0; - private List lights = new ArrayList(); public Map> _webglObjects = GWT.isScript() ? @@ -549,8 +545,6 @@ public void setGammaOutput(boolean isGammaOutput) { this.gammaOutput = isGammaOutput; } - - /** * Defines whether the renderer should auto update the scene. * Default is true. @@ -603,7 +597,7 @@ private void setDefaultGLState() getGL().blendFunc( BlendingFactorSrc.SRC_ALPHA, BlendingFactorDest.ONE_MINUS_SRC_ALPHA ); getGL().viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight ); - getGL().clearColor( _clearColor.getR(), _clearColor.getG(), _clearColor.getB(), _clearAlpha ); + getGL().clearColor( clearColor.getR(), clearColor.getG(), clearColor.getB(), clearAlpha ); } /** @@ -673,59 +667,14 @@ public void enableScissorTest(boolean enable) else getGL().disable(EnableCap.SCISSOR_TEST); } - - public void setClearColor( int hex ) - { - setClearColor(new Color(hex)); - } - - public void setClearColor( Color color ) - { - setClearColor(color, 1.0); - } - - /** - * Sets the the background color, using hex for the color.
    - * - * @param hex the clear color value. - */ - public void setClearColor( int hex, double alpha ) - { - setClearColor(new Color(hex), alpha); - } - /** - * Sets the the background color, using {@link Color} for the color and alpha for the opacity. - * - * @param color the {@link Color} instance. - * @param alpha the opacity of the scene's background color, range 0.0 (invisible) to 1.0 (opaque). - */ + @Override public void setClearColor( Color color, double alpha ) { - this._clearColor.copy(color); - this._clearAlpha = alpha; - - getGL().clearColor( this._clearColor.getR(), this._clearColor.getG(), this._clearColor.getB(), this._clearAlpha ); - } + this.clearColor.copy(color); + this.clearAlpha = alpha; - /** - * Returns the background color. - * - * @return the {@link Color} instance. - */ - public Color getClearColor() - { - return this._clearColor; - } - - /** - * Returns the opacity of the scene's background color, range 0.0 (invisible) to 1.0 (opaque) - * - * @return the value in range <0,1>. - */ - public double getClearAlpha() - { - return this._clearAlpha; + getGL().clearColor( this.clearColor.getR(), this.clearColor.getG(), this.clearColor.getB(), this.clearAlpha ); } public void clear() From 6a9c174a35f3432ba9a2f8a61dcf62d640471985 Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 27 Feb 2015 01:55:59 +0300 Subject: [PATCH 60/75] Moved basic clearing to abstract renderer --- .../client/renderers/AbstractRenderer.java | 22 +++++++++++++++++++ .../client/renderers/RaytracingRenderer.java | 6 +++++ .../core/client/renderers/WebGLRenderer.java | 19 +--------------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java b/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java index 99357d61..6a4924b4 100644 --- a/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java @@ -25,6 +25,9 @@ public abstract class AbstractRenderer // Default Color and alpha protected Color clearColor = new Color(0x000000); protected double clearAlpha = 1.0; + + // Clearing + protected boolean autoClear = true; public void setClearColor( int hex ) { @@ -73,4 +76,23 @@ public double getClearAlpha() { return this.clearAlpha; } + + /** + * Gets {@link #setAutoClear(boolean)} flag. + */ + public boolean isAutoClear() { + return autoClear; + } + + /** + * Defines whether the renderer should automatically clear its output before rendering. + * Default is true. + * + * @param isAutoClear false or true + */ + public void setAutoClear(boolean isAutoClear) { + this.autoClear = isAutoClear; + } + + public abstract void clear(); } diff --git a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java index 5269dfbf..a0bfb0b6 100644 --- a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java @@ -29,4 +29,10 @@ public void setClearColor(Color color, double alpha) this.clearColor.copy(color); } + @Override + public void clear() { + // TODO Auto-generated method stub + + } + } diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index 3dc18dd9..455c950b 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -156,7 +156,6 @@ public final native double _devicePixelRatio() /*-{ public Shader.PRECISION _precision = Shader.PRECISION.HIGHP; // clearing - private boolean autoClear = true; private boolean autoClearColor = true; private boolean autoClearDepth = true; private boolean autoClearStencil = true; @@ -419,23 +418,6 @@ public Shader.PRECISION getPrecision() { return this._precision; } - /** - * Gets {@link #setAutoClear(boolean)} flag. - */ - public boolean isAutoClear() { - return autoClear; - } - - /** - * Defines whether the renderer should automatically clear its output before rendering. - * Default is true. - * - * @param isAutoClear false or true - */ - public void setAutoClear(boolean isAutoClear) { - this.autoClear = isAutoClear; - } - /** * Gets {@link #setAutoClearColor(boolean)} flag. */ @@ -677,6 +659,7 @@ public void setClearColor( Color color, double alpha ) getGL().clearColor( this.clearColor.getR(), this.clearColor.getG(), this.clearColor.getB(), this.clearAlpha ); } + @Override public void clear() { clear(true, true, true); From 16460724882a7e83005f67f36319bf138bb3866f Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 27 Feb 2015 03:11:55 +0300 Subject: [PATCH 61/75] Implemented some private method in raycasting renderer --- .../client/renderers/RaytracingRenderer.java | 382 ++++++++++++++++++ .../core/shared/lights/AreaLight.java | 19 +- .../core/shared/lights/HasIntensity.java | 32 ++ .../core/shared/lights/HemisphereLight.java | 4 +- .../core/shared/lights/PointLight.java | 2 +- .../core/shared/lights/ShadowLight.java | 2 +- 6 files changed, 435 insertions(+), 6 deletions(-) create mode 100644 src/thothbot/parallax/core/shared/lights/HasIntensity.java diff --git a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java index a0bfb0b6..8df1e369 100644 --- a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java @@ -18,10 +18,60 @@ package thothbot.parallax.core.client.renderers; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.google.gwt.core.client.GWT; + +import thothbot.parallax.core.shared.core.Face3; +import thothbot.parallax.core.shared.core.FastMap; +import thothbot.parallax.core.shared.core.Geometry; +import thothbot.parallax.core.shared.core.GeometryObject; +import thothbot.parallax.core.shared.core.Object3D; +import thothbot.parallax.core.shared.core.Raycaster; +import thothbot.parallax.core.shared.core.Raycaster.Intersect; +import thothbot.parallax.core.shared.helpers.HasRaytracingPhysicalAttenuation; +import thothbot.parallax.core.shared.lights.HasIntensity; +import thothbot.parallax.core.shared.lights.Light; +import thothbot.parallax.core.shared.materials.HasColor; +import thothbot.parallax.core.shared.materials.HasRaytracingGlass; +import thothbot.parallax.core.shared.materials.HasRaytracingMirror; +import thothbot.parallax.core.shared.materials.HasShading; +import thothbot.parallax.core.shared.materials.HasVertexColors; +import thothbot.parallax.core.shared.materials.Material; +import thothbot.parallax.core.shared.materials.MeshBasicMaterial; +import thothbot.parallax.core.shared.materials.MeshLambertMaterial; +import thothbot.parallax.core.shared.materials.MeshPhongMaterial; import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.core.shared.math.Matrix3; +import thothbot.parallax.core.shared.math.Matrix4; +import thothbot.parallax.core.shared.math.Ray; +import thothbot.parallax.core.shared.math.Vector3; public class RaytracingRenderer extends AbstractRenderer { + + private static final int maxRecursionDepth = 3; + + private static class RaycastingGeometryObject extends Object3D + { + public Matrix3 normalMatrix; + public Matrix4 inverseMatrix; + } + + Vector3 origin = new Vector3(); + Vector3 direction = new Vector3(); + + Raycaster raycaster = new Raycaster( origin, direction ); + Raycaster raycasterLight = new Raycaster(); + + List objects; + List lights = new ArrayList(); + + Map cache = GWT.isScript() ? + new FastMap() : new HashMap(); @Override public void setClearColor(Color color, double alpha) @@ -35,4 +85,336 @@ public void clear() { } + Color diffuseColor = new Color(); + Color specularColor = new Color(); + Color lightColor = new Color(); + Color schlick = new Color(); + + Color lightContribution = new Color(); + + Vector3 eyeVector = new Vector3(); + Vector3 lightVector = new Vector3(); + Vector3 normalVector = new Vector3(); + Vector3 halfVector = new Vector3(); + + Vector3 localPoint = new Vector3(); + Vector3 reflectionVector = new Vector3(); + + Vector3 tmpVec = new Vector3(); + + Color[] tmpColor = null; + + private void spawnRay(Vector3 rayOrigin, Vector3 rayDirection, Color outputColor, int recursionDepth) + { + // Init the tmp array + if(tmpColor.length < maxRecursionDepth) + { + tmpColor = new Color[maxRecursionDepth]; + for ( int i = 0; i < maxRecursionDepth; i ++ ) + tmpColor[ i ] = new Color(); + } + + Ray ray = raycaster.getRay(); + + ray.setOrigin( rayOrigin ); + ray.setDirection(rayDirection);; + + // + + Ray rayLight = raycasterLight.getRay(); + + // + + outputColor.setRGB( 0, 0, 0 ); + + // + + List intersections = raycaster.intersectObjects( objects, true ); + + // ray didn't find anything + // (here should come setting of background color?) + + if ( intersections.size() == 0 ) { + + return; + + } + + // ray hit + + Intersect intersection = intersections.get( 0 ); + + Vector3 point = intersection.point; + GeometryObject object = intersection.object; + Material material = object.getMaterial(); + Face3 face = intersection.face; + + List vertices = ((Geometry)object.getGeometry()).getVertices(); + + // + + RaycastingGeometryObject _object = cache.get( object.getId() + "" ); + + localPoint.copy( point ).apply( _object.inverseMatrix ); + eyeVector.sub( raycaster.getRay().getOrigin(), point ).normalize(); + + // resolve pixel diffuse color + + if ( material instanceof MeshLambertMaterial || + material instanceof MeshPhongMaterial || + material instanceof MeshBasicMaterial ) + { + diffuseColor.copyGammaToLinear( ((HasColor)material).getColor() ); + } + else + { + diffuseColor.setRGB( 1, 1, 1 ); + } + + if ( material instanceof HasVertexColors + && ((HasVertexColors)material).isVertexColors() == Material.COLORS.FACE ) + { + diffuseColor.multiply( face.getColor() ); + } + + // compute light shading + + rayLight.getOrigin().copy( point ); + + if ( material instanceof MeshBasicMaterial ) + { + for ( int i = 0, l = lights.size(); i < l; i ++ ) + { + + Light light = lights.get( i ); + + lightVector.setFromMatrixPosition( light.getMatrixWorld() ); + lightVector.sub( point ); + + rayLight.getDirection().copy( lightVector ).normalize(); + + List intersections2 = raycasterLight.intersectObjects( objects, true ); + + // point in shadow + + if ( intersections2.size() > 0 ) continue; + + // point visible + + outputColor.add( diffuseColor ); + + } + + } else if ( material instanceof MeshLambertMaterial || + material instanceof MeshPhongMaterial ) { + + boolean normalComputed = false; + + for ( int i = 0, l = lights.size(); i < l; i ++ ) { + + Light light = lights.get( i ); + + lightColor.copyGammaToLinear( light.getColor() ); + + lightVector.setFromMatrixPosition( light.getMatrixWorld() ); + lightVector.sub( point ); + + rayLight.getDirection().copy( lightVector ).normalize(); + + List intersections3 = raycasterLight.intersectObjects( objects, true ); + + // point in shadow + + if ( intersections3.size() > 0 ) continue; + + // point lit + + if ( normalComputed == false ) { + + // the same normal can be reused for all lights + // (should be possible to cache even more) + + computePixelNormal( normalVector, localPoint, ((HasShading)material).getShading(), face, vertices ); + normalVector.apply( _object.normalMatrix ).normalize(); + + normalComputed = true; + + } + + // compute attenuation + + double attenuation = 1.0; + + if (light instanceof HasRaytracingPhysicalAttenuation + && ((HasRaytracingPhysicalAttenuation)light).isPhysicalAttenuation() == true ) { + + attenuation = lightVector.length(); + attenuation = 1.0 / ( attenuation * attenuation ); + + } + + lightVector.normalize(); + + // compute diffuse + + double dot = Math.max( normalVector.dot( lightVector ), 0 ); + double diffuseIntensity = dot * ((HasIntensity)light).getIntensity(); + + lightContribution.copy( diffuseColor ); + lightContribution.multiply( lightColor ); + lightContribution.multiply( diffuseIntensity * attenuation ); + + outputColor.add( lightContribution ); + + // compute specular + + if ( material instanceof MeshPhongMaterial ) + { + + halfVector.add( lightVector, eyeVector ).normalize(); + + double dotNormalHalf = Math.max( normalVector.dot( halfVector ), 0.0 ); + double specularIntensity = Math.max( Math.pow( dotNormalHalf, ((MeshPhongMaterial) material).getShininess() ), 0.0 ) * diffuseIntensity; + + double specularNormalization = ( ((MeshPhongMaterial) material).getShininess() + 2.0 ) / 8.0; + + specularColor.copyGammaToLinear( ((MeshPhongMaterial) material).getSpecular() ); + + double alpha = Math.pow( Math.max( 1.0 - lightVector.dot( halfVector ), 0.0 ), 5.0 ); + + schlick.setR( specularColor.getR() + ( 1.0 - specularColor.getR() ) * alpha ); + schlick.setG( specularColor.getG() + ( 1.0 - specularColor.getG() ) * alpha ); + schlick.setB( specularColor.getB() + ( 1.0 - specularColor.getB() ) * alpha ); + + lightContribution.copy( schlick ); + + lightContribution.multiply( lightColor ); + lightContribution.multiply( specularNormalization * specularIntensity * attenuation ); + outputColor.add( lightContribution ); + + } + + } + + } + + // reflection / refraction + + double reflectivity = ((MeshPhongMaterial)material).getReflectivity(); + + if ( ( ((HasRaytracingMirror)material).isMirror() || ((HasRaytracingGlass)material).isGlass() ) + && reflectivity > 0 + && recursionDepth < maxRecursionDepth ) + { + + if ( ((HasRaytracingMirror)material).isMirror() ) + { + + reflectionVector.copy( rayDirection ); + reflectionVector.reflect( normalVector ); + + } + else if ( ((HasRaytracingGlass)material).isGlass() ) + { + + double eta = ((MeshPhongMaterial)material).getRefractionRatio(); + + double dotNI = rayDirection.dot( normalVector ); + double k = 1.0 - eta * eta * ( 1.0 - dotNI * dotNI ); + + if ( k < 0.0 ) { + + reflectionVector.set( 0, 0, 0 ); + + } else { + + reflectionVector.copy( rayDirection ); + reflectionVector.multiply( eta ); + + double alpha = eta * dotNI + Math.sqrt( k ); + tmpVec.copy( normalVector ); + tmpVec.multiply( alpha ); + reflectionVector.sub( tmpVec ); + + } + + } + + double theta = Math.max( eyeVector.dot( normalVector ), 0.0 ); + double rf0 = reflectivity; + double fresnel = rf0 + ( 1.0 - rf0 ) * Math.pow( ( 1.0 - theta ), 5.0 ); + + double weight = fresnel; + + Color zColor = tmpColor[ recursionDepth ]; + + spawnRay( point, reflectionVector, zColor, recursionDepth + 1 ); + + if ( ((MeshPhongMaterial)material).getSpecular() != null ) { + + zColor.multiply( ((MeshPhongMaterial)material).getSpecular() ); + + } + + zColor.multiply( weight ); + outputColor.multiply( 1 - weight ); + outputColor.add( zColor ); + + } + } + + Vector3 tmpVec1 = new Vector3(); + Vector3 tmpVec2 = new Vector3(); + Vector3 tmpVec3 = new Vector3(); + + private void computePixelNormal(Vector3 outputVector, Vector3 point, Material.SHADING shading, Face3 face, List vertices ) + { + + Vector3 faceNormal = face.getNormal(); + List vertexNormals = face.getVertexNormals(); + + if ( shading == Material.SHADING.FLAT ) + { + outputVector.copy( faceNormal ); + + } + else if ( shading == Material.SHADING.SMOOTH ) + { + // compute barycentric coordinates + + Vector3 vA = vertices.get( face.getA() ); + Vector3 vB = vertices.get( face.getB() ); + Vector3 vC = vertices.get( face.getC() ); + + tmpVec3.cross( tmpVec1.sub( vB, vA ), tmpVec2.sub( vC, vA ) ); + double areaABC = faceNormal.dot( tmpVec3 ); + + tmpVec3.cross( tmpVec1.sub( vB, point ), tmpVec2.sub( vC, point ) ); + double areaPBC = faceNormal.dot( tmpVec3 ); + double a = areaPBC / areaABC; + + tmpVec3.cross( tmpVec1.sub( vC, point ), tmpVec2.sub( vA, point ) ); + double areaPCA = faceNormal.dot( tmpVec3 ); + double b = areaPCA / areaABC; + + double c = 1.0 - a - b; + + // compute interpolated vertex normal + + tmpVec1.copy( vertexNormals.get( 0 ) ); + tmpVec1.multiply( a ); + + tmpVec2.copy( vertexNormals.get( 1 ) ); + tmpVec2.multiply( b ); + + tmpVec3.copy( vertexNormals.get( 2 ) ); + tmpVec3.multiply( c ); + + outputVector.add( tmpVec1, tmpVec2 ); + outputVector.add( tmpVec3 ); + + } + + } + } diff --git a/src/thothbot/parallax/core/shared/lights/AreaLight.java b/src/thothbot/parallax/core/shared/lights/AreaLight.java index 1d4d24e7..5688198f 100644 --- a/src/thothbot/parallax/core/shared/lights/AreaLight.java +++ b/src/thothbot/parallax/core/shared/lights/AreaLight.java @@ -21,12 +21,13 @@ import thothbot.parallax.core.client.renderers.RendererLights; import thothbot.parallax.core.shared.math.Vector3; -public class AreaLight extends Light { +public class AreaLight extends Light implements HasIntensity +{ public Vector3 normal; public Vector3 right; - public double intensity; + private double intensity; public double width = 1.0; public double height = 1.0; @@ -54,4 +55,18 @@ public void setupRendererLights(RendererLights zlights, boolean isGammaInput) { // TODO Auto-generated method stub } + + /** + * Gets Light's intensity. + */ + public double getIntensity() { + return this.intensity; + } + + /** + * Sets Light's intensity. + */ + public void setIntensity(double intensity) { + this.intensity = intensity; + } } diff --git a/src/thothbot/parallax/core/shared/lights/HasIntensity.java b/src/thothbot/parallax/core/shared/lights/HasIntensity.java new file mode 100644 index 00000000..edf5ffa9 --- /dev/null +++ b/src/thothbot/parallax/core/shared/lights/HasIntensity.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012 Alex Usachev, thothbot@gmail.com + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +package thothbot.parallax.core.shared.lights; + +public interface HasIntensity { + + /** + * Gets Light's intensity. + */ + public double getIntensity(); + + /** + * Sets Light's intensity. + */ + public void setIntensity(double intensity); +} diff --git a/src/thothbot/parallax/core/shared/lights/HemisphereLight.java b/src/thothbot/parallax/core/shared/lights/HemisphereLight.java index ca3c7615..623ca91d 100644 --- a/src/thothbot/parallax/core/shared/lights/HemisphereLight.java +++ b/src/thothbot/parallax/core/shared/lights/HemisphereLight.java @@ -26,9 +26,9 @@ import thothbot.parallax.core.shared.math.Color; import thothbot.parallax.core.shared.math.Vector3; -public final class HemisphereLight extends Light +public final class HemisphereLight extends Light implements HasIntensity { - public static class UniformHemisphere implements Light.UniformLight + public static class UniformHemisphere implements Light.UniformLight { public Float32Array skyColors; public Float32Array groundColors; diff --git a/src/thothbot/parallax/core/shared/lights/PointLight.java b/src/thothbot/parallax/core/shared/lights/PointLight.java index 4925886f..c58c0fed 100644 --- a/src/thothbot/parallax/core/shared/lights/PointLight.java +++ b/src/thothbot/parallax/core/shared/lights/PointLight.java @@ -42,7 +42,7 @@ * @author thothbot * */ -public class PointLight extends Light implements HasRaytracingPhysicalAttenuation +public class PointLight extends Light implements HasRaytracingPhysicalAttenuation, HasIntensity { public static class UniformPoint implements Light.UniformLight { diff --git a/src/thothbot/parallax/core/shared/lights/ShadowLight.java b/src/thothbot/parallax/core/shared/lights/ShadowLight.java index 98ef4086..357fa271 100644 --- a/src/thothbot/parallax/core/shared/lights/ShadowLight.java +++ b/src/thothbot/parallax/core/shared/lights/ShadowLight.java @@ -25,7 +25,7 @@ import thothbot.parallax.core.shared.math.Matrix4; import thothbot.parallax.core.shared.math.Vector2; import thothbot.parallax.core.shared.math.Vector3; -public abstract class ShadowLight extends Light +public abstract class ShadowLight extends Light implements HasIntensity { protected Object3D target; From 09789b6dbad5da9d1447af1e053b65389d12d389 Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 27 Feb 2015 03:37:17 +0300 Subject: [PATCH 62/75] Added rendering method to raycasting renderer --- .../client/renderers/AbstractRenderer.java | 25 ++++++ .../client/renderers/RaytracingRenderer.java | 77 +++++++++++++++++++ .../core/client/renderers/WebGLRenderer.java | 21 +---- 3 files changed, 106 insertions(+), 17 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java b/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java index 6a4924b4..2f28abe9 100644 --- a/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java @@ -18,10 +18,15 @@ package thothbot.parallax.core.client.renderers; +import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.core.shared.scenes.Scene; public abstract class AbstractRenderer { + private int absoluteWidth = 0; + private int absoluteHeight = 0; + // Default Color and alpha protected Color clearColor = new Color(0x000000); protected double clearAlpha = 1.0; @@ -29,6 +34,24 @@ public abstract class AbstractRenderer // Clearing protected boolean autoClear = true; + public void setSize(int width, int height) + { + this.absoluteWidth = width; + this.absoluteHeight = height; + } + + public int getAbsoluteWidth() { + return this.absoluteWidth; + } + + public int getAbsoluteHeight() { + return this.absoluteHeight; + } + + public double getAbsoluteAspectRation() { + return getAbsoluteWidth() / (double)getAbsoluteHeight(); + } + public void setClearColor( int hex ) { setClearColor(new Color(hex)); @@ -95,4 +118,6 @@ public void setAutoClear(boolean isAutoClear) { } public abstract void clear(); + + public abstract void render( Scene scene, Camera camera ); } diff --git a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java index 8df1e369..14ecd622 100644 --- a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java @@ -25,11 +25,14 @@ import com.google.gwt.core.client.GWT; +import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.cameras.PerspectiveCamera; import thothbot.parallax.core.shared.core.Face3; import thothbot.parallax.core.shared.core.FastMap; import thothbot.parallax.core.shared.core.Geometry; import thothbot.parallax.core.shared.core.GeometryObject; import thothbot.parallax.core.shared.core.Object3D; +import thothbot.parallax.core.shared.core.Object3D.Traverse; import thothbot.parallax.core.shared.core.Raycaster; import thothbot.parallax.core.shared.core.Raycaster.Intersect; import thothbot.parallax.core.shared.helpers.HasRaytracingPhysicalAttenuation; @@ -45,10 +48,12 @@ import thothbot.parallax.core.shared.materials.MeshLambertMaterial; import thothbot.parallax.core.shared.materials.MeshPhongMaterial; import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.core.shared.math.Mathematics; import thothbot.parallax.core.shared.math.Matrix3; import thothbot.parallax.core.shared.math.Matrix4; import thothbot.parallax.core.shared.math.Ray; import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.scenes.Scene; public class RaytracingRenderer extends AbstractRenderer { @@ -59,14 +64,25 @@ private static class RaycastingGeometryObject extends Object3D { public Matrix3 normalMatrix; public Matrix4 inverseMatrix; + + public RaycastingGeometryObject() + { + this.normalMatrix = new Matrix3(); + this.inverseMatrix = new Matrix4(); + } } Vector3 origin = new Vector3(); Vector3 direction = new Vector3(); + + Vector3 cameraPosition = new Vector3(); Raycaster raycaster = new Raycaster( origin, direction ); Raycaster raycasterLight = new Raycaster(); + Matrix4 modelViewMatrix = new Matrix4(); + Matrix3 cameraNormalMatrix = new Matrix3(); + List objects; List lights = new ArrayList(); @@ -84,6 +100,67 @@ public void clear() { // TODO Auto-generated method stub } + + @Override + public void render( Scene scene, final Camera camera ) { + + if ( isAutoClear() == true ) this.clear(); + +// cancelAnimationFrame( animationFrameId ); + + // update scene graph + + if ( scene.isAutoUpdate() == true ) scene.updateMatrixWorld(false); + + // update camera matrices + + if ( camera.getParent() == null ) camera.updateMatrixWorld(false); + + camera.getMatrixWorldInverse().getInverse( camera.getMatrixWorld() ); + cameraPosition.setFromMatrixPosition( camera.getMatrixWorld() ); + + // + + cameraNormalMatrix.getNormalMatrix( camera.getMatrixWorld() ); + origin.copy( cameraPosition ); + + double perspective = 0.5 / Math.tan( Mathematics.degToRad( ((PerspectiveCamera)camera).getFov() * 0.5 ) ) * getAbsoluteHeight(); + + List objects = scene.getChildren(); + + // collect lights and set up object matrices + + lights = new ArrayList(); + + scene.traverse(new Traverse() { + + @Override + public void callback(Object3D object) { + if ( object instanceof Light ) { + + lights.add( (Light) object ); + + } + + if ( !cache.containsKey( object.getId() + "" ) ) + { + cache.put( object.getId() + "", new RaycastingGeometryObject()); + } + + modelViewMatrix.multiply( camera.getMatrixWorldInverse(), object.getMatrixWorld() ); + + RaycastingGeometryObject _object = cache.get( object.getId() + "" ); + + _object.normalMatrix.getNormalMatrix( modelViewMatrix ); + _object.inverseMatrix.getInverse( object.getMatrixWorld() ); + + + } + }); + +// renderBlock( 0, 0 ); + + } Color diffuseColor = new Color(); Color specularColor = new Color(); diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index 455c950b..b29d4b47 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -215,8 +215,6 @@ public final native double _devicePixelRatio() /*-{ // _oldLineWidth = null, - private int absoluteWidth = 0; - private int absoluteHeight = 0; private int _viewportX = 0; private int _viewportY = 0; private int _viewportWidth = 0; @@ -592,11 +590,11 @@ private void setDefaultGLState() * @param width the {@link Canvas3d} width. * @param height the {@link Canvas3d} height. */ + @Override public void setSize(int width, int height) { - this.absoluteWidth = width; - this.absoluteHeight = height; - + super.setSize(width, height); + setViewport(0, 0, width, height); EVENT_BUS.fireEvent(new ViewportResizeEvent(this)); @@ -617,18 +615,6 @@ public void setViewport(int x, int y, int width, int height) getGL().viewport(this._viewportX, this._viewportY, this._viewportWidth, this._viewportHeight); } - public int getAbsoluteWidth() { - return this.absoluteWidth; - } - - public int getAbsoluteHeight() { - return this.absoluteHeight; - } - - public double getAbsoluteAspectRation() { - return getAbsoluteWidth() / (double)getAbsoluteHeight(); - } - /** * Sets the scissor area from (x, y) to (x + absoluteWidth, y + absoluteHeight). */ @@ -1712,6 +1698,7 @@ public void updateObject( GeometryObject object, Object3D scene ) } + @Override public void render( Scene scene, Camera camera ) { render(scene, camera, null); From 78500530ab75ab1ced5c9e1bc33751b59144fa8e Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 27 Feb 2015 04:16:54 +0300 Subject: [PATCH 63/75] Updated rendering method in raytracing renderer --- .../client/renderers/RaytracingRenderer.java | 99 ++++++++++++++++++- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java index 14ecd622..5b1155e4 100644 --- a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java @@ -23,6 +23,10 @@ import java.util.List; import java.util.Map; +import com.google.gwt.canvas.client.Canvas; +import com.google.gwt.canvas.dom.client.CanvasPixelArray; +import com.google.gwt.canvas.dom.client.Context2d; +import com.google.gwt.canvas.dom.client.ImageData; import com.google.gwt.core.client.GWT; import thothbot.parallax.core.shared.cameras.Camera; @@ -59,6 +63,7 @@ public class RaytracingRenderer extends AbstractRenderer { private static final int maxRecursionDepth = 3; + private static final int blockSize = 64; private static class RaycastingGeometryObject extends Object3D { @@ -71,6 +76,9 @@ public RaycastingGeometryObject() this.inverseMatrix = new Matrix4(); } } + + Canvas canvas; + Context2d context; Vector3 origin = new Vector3(); Vector3 direction = new Vector3(); @@ -80,6 +88,7 @@ public RaycastingGeometryObject() Raycaster raycaster = new Raycaster( origin, direction ); Raycaster raycasterLight = new Raycaster(); + double perspective; Matrix4 modelViewMatrix = new Matrix4(); Matrix3 cameraNormalMatrix = new Matrix3(); @@ -87,7 +96,23 @@ public RaycastingGeometryObject() List lights = new ArrayList(); Map cache = GWT.isScript() ? - new FastMap() : new HashMap(); + new FastMap() : new HashMap(); + + public RaytracingRenderer(int width, int height) { + canvas = Canvas.createIfSupported(); + context = canvas.getContext2d(); + context.setFillStyle( "white" ); + + setSize(width, height); + } + + @Override + public void setSize(int width, int height) { + super.setSize(width, height); + + canvas.setCoordinateSpaceWidth(width); + canvas.setCoordinateSpaceHeight(height); + } @Override public void setClearColor(Color color, double alpha) @@ -124,7 +149,7 @@ public void render( Scene scene, final Camera camera ) { cameraNormalMatrix.getNormalMatrix( camera.getMatrixWorld() ); origin.copy( cameraPosition ); - double perspective = 0.5 / Math.tan( Mathematics.degToRad( ((PerspectiveCamera)camera).getFov() * 0.5 ) ) * getAbsoluteHeight(); + perspective = 0.5 / Math.tan( Mathematics.degToRad( ((PerspectiveCamera)camera).getFov() * 0.5 ) ) * getAbsoluteHeight(); List objects = scene.getChildren(); @@ -158,7 +183,75 @@ public void callback(Object3D object) { } }); -// renderBlock( 0, 0 ); + renderBlock( 0, 0 ); + + } + + ImageData imagedata = null; + CanvasPixelArray data = null; + Color pixelColor = new Color(); + + private void renderBlock(int blockX, int blockY) { + + if(imagedata == null) + { + Canvas canvasBlock = Canvas.createIfSupported(); + + canvasBlock.setCoordinateSpaceWidth(blockSize); + canvasBlock.setCoordinateSpaceHeight(blockSize); + Context2d contextBlock = canvasBlock.getContext2d(); + + this.imagedata = contextBlock.getImageData( 0, 0, blockSize, blockSize ); + this.data = imagedata.getData(); + } + + // + + int index = 0; + + for ( int y = 0; y < blockSize; y ++ ) { + + for ( int x = 0; x < blockSize; x ++, index += 4 ) { + + // spawn primary ray at pixel position + + origin.copy( cameraPosition ); + + direction.set( x + blockX - getAbsoluteWidth()/2, - ( y + blockY - getAbsoluteHeight()/2 ), - perspective ); + direction.apply( cameraNormalMatrix ).normalize(); + + spawnRay( origin, direction, pixelColor, 0 ); + + // convert from linear to gamma + + data.set( index , (int)(Math.sqrt( pixelColor.getR() ) * 255) ); + data.set( index + 1 , (int)(Math.sqrt( pixelColor.getG() ) * 255) ); + data.set( index + 2 , (int)(Math.sqrt( pixelColor.getB() ) * 255) ); + + } + + } + + context.putImageData( imagedata, blockX, blockY ); + + blockX += blockSize; + + if ( blockX >= getAbsoluteWidth() ) { + + blockX = 0; + blockY += blockSize; + + if ( blockY >= getAbsoluteHeight() ) return; + + } + + context.fillRect( blockX, blockY, blockSize, blockSize ); + +// animationFrameId = requestAnimationFrame( function () { + + renderBlock( blockX, blockY ); + +// } ); } From d81b8bc41341b89a36ca2432fd20e888b8bf5c8a Mon Sep 17 00:00:00 2001 From: thothbot Date: Fri, 27 Feb 2015 04:25:17 +0300 Subject: [PATCH 64/75] Some optimization in renderers --- .../core/client/renderers/AbstractRenderer.java | 4 ++-- .../core/client/renderers/RaytracingRenderer.java | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java b/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java index 2f28abe9..3abdf242 100644 --- a/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/AbstractRenderer.java @@ -24,8 +24,8 @@ public abstract class AbstractRenderer { - private int absoluteWidth = 0; - private int absoluteHeight = 0; + protected int absoluteWidth = 0; + protected int absoluteHeight = 0; // Default Color and alpha protected Color clearColor = new Color(0x000000); diff --git a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java index 5b1155e4..73964fd2 100644 --- a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java @@ -65,12 +65,12 @@ public class RaytracingRenderer extends AbstractRenderer private static final int maxRecursionDepth = 3; private static final int blockSize = 64; - private static class RaycastingGeometryObject extends Object3D + private static class ObjectMatrixes { public Matrix3 normalMatrix; public Matrix4 inverseMatrix; - public RaycastingGeometryObject() + public ObjectMatrixes() { this.normalMatrix = new Matrix3(); this.inverseMatrix = new Matrix4(); @@ -95,8 +95,8 @@ public RaycastingGeometryObject() List objects; List lights = new ArrayList(); - Map cache = GWT.isScript() ? - new FastMap() : new HashMap(); + Map cache = GWT.isScript() ? + new FastMap() : new HashMap(); public RaytracingRenderer(int width, int height) { canvas = Canvas.createIfSupported(); @@ -169,12 +169,12 @@ public void callback(Object3D object) { if ( !cache.containsKey( object.getId() + "" ) ) { - cache.put( object.getId() + "", new RaycastingGeometryObject()); + cache.put( object.getId() + "", new ObjectMatrixes()); } modelViewMatrix.multiply( camera.getMatrixWorldInverse(), object.getMatrixWorld() ); - RaycastingGeometryObject _object = cache.get( object.getId() + "" ); + ObjectMatrixes _object = cache.get( object.getId() + "" ); _object.normalMatrix.getNormalMatrix( modelViewMatrix ); _object.inverseMatrix.getInverse( object.getMatrixWorld() ); @@ -323,7 +323,7 @@ private void spawnRay(Vector3 rayOrigin, Vector3 rayDirection, Color outputColor // - RaycastingGeometryObject _object = cache.get( object.getId() + "" ); + ObjectMatrixes _object = cache.get( object.getId() + "" ); localPoint.copy( point ).apply( _object.inverseMatrix ); eyeVector.sub( raycaster.getRay().getOrigin(), point ).normalize(); From 130b2ce3e67af33aa855f6d21756f8dd5b39931a Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 2 Mar 2015 01:00:40 +0300 Subject: [PATCH 65/75] Fixed few issues in raytracing rendering --- .../client/renderers/RaytracingRenderer.java | 103 +++++++++++------- .../parallax/core/shared/core/Raycaster.java | 24 +--- .../parallax/core/shared/math/Color.java | 2 +- 3 files changed, 68 insertions(+), 61 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java index 73964fd2..b127362d 100644 --- a/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/RaytracingRenderer.java @@ -23,12 +23,17 @@ import java.util.List; import java.util.Map; +import com.google.gwt.animation.client.AnimationScheduler; +import com.google.gwt.animation.client.AnimationScheduler.AnimationCallback; +import com.google.gwt.animation.client.AnimationScheduler.AnimationHandle; import com.google.gwt.canvas.client.Canvas; import com.google.gwt.canvas.dom.client.CanvasPixelArray; import com.google.gwt.canvas.dom.client.Context2d; import com.google.gwt.canvas.dom.client.ImageData; import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.RootPanel; +import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.cameras.Camera; import thothbot.parallax.core.shared.cameras.PerspectiveCamera; import thothbot.parallax.core.shared.core.Face3; @@ -89,21 +94,43 @@ public ObjectMatrixes() Raycaster raycasterLight = new Raycaster(); double perspective; - Matrix4 modelViewMatrix = new Matrix4(); + Matrix4 modelViewMatrix = new Matrix4(); Matrix3 cameraNormalMatrix = new Matrix3(); - List objects; + List objects; List lights = new ArrayList(); + AnimationHandle animationHandler; + Map cache = GWT.isScript() ? new FastMap() : new HashMap(); + + Canvas canvasBlock; + ImageData imagedata = null; + public RaytracingRenderer(int width, int height) { canvas = Canvas.createIfSupported(); + canvas.ensureDebugId("canvas2d"); + + setSize(width, height); + context = canvas.getContext2d(); - context.setFillStyle( "white" ); + context.setFillStyle( "#FFFFFF" ); + + + canvasBlock = Canvas.createIfSupported(); + canvasBlock.setCoordinateSpaceWidth(blockSize); + canvasBlock.setCoordinateSpaceHeight(blockSize); - setSize(width, height); + RootPanel.get().add(canvasBlock, -10000, 0); + + Context2d contextBlock = canvasBlock.getContext2d(); + imagedata = contextBlock.getImageData( 0, 0, blockSize, blockSize ); + } + + public Canvas getCanvas() { + return this.canvas; } @Override @@ -151,7 +178,7 @@ public void render( Scene scene, final Camera camera ) { perspective = 0.5 / Math.tan( Mathematics.degToRad( ((PerspectiveCamera)camera).getFov() * 0.5 ) ) * getAbsoluteHeight(); - List objects = scene.getChildren(); + objects = scene.getChildren(); // collect lights and set up object matrices @@ -183,28 +210,14 @@ public void callback(Object3D object) { } }); - renderBlock( 0, 0 ); - + renderBlock(0, 0); } - ImageData imagedata = null; - CanvasPixelArray data = null; - Color pixelColor = new Color(); - - private void renderBlock(int blockX, int blockY) { - - if(imagedata == null) - { - Canvas canvasBlock = Canvas.createIfSupported(); - - canvasBlock.setCoordinateSpaceWidth(blockSize); - canvasBlock.setCoordinateSpaceHeight(blockSize); - Context2d contextBlock = canvasBlock.getContext2d(); - - this.imagedata = contextBlock.getImageData( 0, 0, blockSize, blockSize ); - this.data = imagedata.getData(); - } - + private void renderBlock(int blockX, int blockY) + { + Log.debug("Raytracing -- Render block: " + blockX + ", " + blockY); + Color pixelColor = new Color(); + // int index = 0; @@ -220,14 +233,15 @@ private void renderBlock(int blockX, int blockY) { direction.set( x + blockX - getAbsoluteWidth()/2, - ( y + blockY - getAbsoluteHeight()/2 ), - perspective ); direction.apply( cameraNormalMatrix ).normalize(); - spawnRay( origin, direction, pixelColor, 0 ); + spawnRay( origin, direction, pixelColor, 0 ); // convert from linear to gamma - data.set( index , (int)(Math.sqrt( pixelColor.getR() ) * 255) ); - data.set( index + 1 , (int)(Math.sqrt( pixelColor.getG() ) * 255) ); - data.set( index + 2 , (int)(Math.sqrt( pixelColor.getB() ) * 255) ); + imagedata.getData().set( index , (int)(Math.sqrt( pixelColor.getR() ) * 255) ); + imagedata.getData().set( index + 1 , (int)(Math.sqrt( pixelColor.getG() ) * 255) ); + imagedata.getData().set( index + 2 , (int)(Math.sqrt( pixelColor.getB() ) * 255) ); + imagedata.getData().set( index + 3 , 255 ); // alpha } } @@ -247,11 +261,18 @@ private void renderBlock(int blockX, int blockY) { context.fillRect( blockX, blockY, blockSize, blockSize ); -// animationFrameId = requestAnimationFrame( function () { - - renderBlock( blockX, blockY ); - -// } ); + final int _blockX = blockX; + final int _blockY = blockY; + + animationHandler = AnimationScheduler.get().requestAnimationFrame(new AnimationCallback() { + + @Override + public void execute(double timestamp) { + + renderBlock( _blockX, _blockY ); + + } + }); } @@ -277,7 +298,7 @@ private void renderBlock(int blockX, int blockY) { private void spawnRay(Vector3 rayOrigin, Vector3 rayDirection, Color outputColor, int recursionDepth) { // Init the tmp array - if(tmpColor.length < maxRecursionDepth) + if(tmpColor == null) { tmpColor = new Color[maxRecursionDepth]; for ( int i = 0; i < maxRecursionDepth; i ++ ) @@ -286,8 +307,8 @@ private void spawnRay(Vector3 rayOrigin, Vector3 rayDirection, Color outputColor Ray ray = raycaster.getRay(); - ray.setOrigin( rayOrigin ); - ray.setDirection(rayDirection);; + ray.setOrigin( rayOrigin ); + ray.setDirection( rayDirection ); // @@ -346,7 +367,7 @@ private void spawnRay(Vector3 rayOrigin, Vector3 rayDirection, Color outputColor { diffuseColor.multiply( face.getColor() ); } - + // compute light shading rayLight.getOrigin().copy( point ); @@ -460,8 +481,8 @@ private void spawnRay(Vector3 rayOrigin, Vector3 rayDirection, Color outputColor lightContribution.multiply( lightColor ); lightContribution.multiply( specularNormalization * specularIntensity * attenuation ); - outputColor.add( lightContribution ); + outputColor.add( lightContribution ); } } @@ -527,10 +548,10 @@ else if ( ((HasRaytracingGlass)material).isGlass() ) } zColor.multiply( weight ); - outputColor.multiply( 1 - weight ); + outputColor.multiply( 1.0 - weight ); outputColor.add( zColor ); - } + } Vector3 tmpVec1 = new Vector3(); diff --git a/src/thothbot/parallax/core/shared/core/Raycaster.java b/src/thothbot/parallax/core/shared/core/Raycaster.java index 4b2cbd7c..f8e88282 100644 --- a/src/thothbot/parallax/core/shared/core/Raycaster.java +++ b/src/thothbot/parallax/core/shared/core/Raycaster.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; +import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.math.Ray; import thothbot.parallax.core.shared.math.Vector3; import thothbot.parallax.core.shared.objects.Line; @@ -151,23 +152,6 @@ public void set( Vector3 origin, Vector3 direction ) { } - public List intersectObjects ( List objects ) { - - List intersects = new ArrayList(); - - for ( int i = 0, l = objects.size(); i < l; i ++ ) { - - if(objects instanceof GeometryObject) - intersectObject( (GeometryObject)objects.get( i ), this, intersects, false ); - - } - - Collections.sort(intersects); - - return intersects; - - } - /** * Checks all intersection between the ray and the objects with or without the descendants. * Intersections are returned sorted by distance, closest first. Intersections are of the same form as @@ -176,13 +160,15 @@ public List intersectObjects ( List objects ) { * @param recursive If set, it also checks all descendants of the objects. Otherwise it only checks intersecton with the objects. * @return */ - public List intersectObjects ( List objects, boolean recursive ) { + public List intersectObjects ( List objects, boolean recursive ) { List intersects = new ArrayList(); for ( int i = 0, l = objects.size(); i < l; i ++ ) { - intersectObject( objects.get( i ), this, intersects, recursive ); + Object3D object = objects.get(i); + if(object instanceof GeometryObject) + intersectObject( (GeometryObject)object, this, intersects, recursive ); } diff --git a/src/thothbot/parallax/core/shared/math/Color.java b/src/thothbot/parallax/core/shared/math/Color.java index 2b6dc0d8..5c68fceb 100644 --- a/src/thothbot/parallax/core/shared/math/Color.java +++ b/src/thothbot/parallax/core/shared/math/Color.java @@ -466,7 +466,7 @@ public Color clone() */ public String toString() { - return getStyle(); + return "{r:" + this.r + ", g:" + this.g + ", b:" + this.b + "}"; } private double hue2rgb( double p, double q, double t ) From 3ae38f57b0c80665f1fcfed597804d586e8f3a34 Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 2 Mar 2015 03:04:41 +0300 Subject: [PATCH 66/75] Some optimization in performance --- .../parallax/core/shared/math/Box3.java | 5 +- .../parallax/core/shared/math/Ray.java | 80 ++++++----- .../parallax/core/shared/math/Sphere.java | 28 ++-- .../parallax/core/shared/math/Vector3.java | 13 +- .../parallax/core/shared/objects/Mesh.java | 132 +++++++++--------- 5 files changed, 135 insertions(+), 123 deletions(-) diff --git a/src/thothbot/parallax/core/shared/math/Box3.java b/src/thothbot/parallax/core/shared/math/Box3.java index a9e19024..01744429 100644 --- a/src/thothbot/parallax/core/shared/math/Box3.java +++ b/src/thothbot/parallax/core/shared/math/Box3.java @@ -78,10 +78,9 @@ public Box3 setFromPoints( Vector3[] points ) { this.makeEmpty(); - for ( int i = 0, il = points.length; i < il; i ++ ) { - + for ( int i = 0, il = points.length; i < il; i ++ ) + { this.expandByPoint( points[ i ] ); - } return this; diff --git a/src/thothbot/parallax/core/shared/math/Ray.java b/src/thothbot/parallax/core/shared/math/Ray.java index 957f7c47..35fa29bd 100644 --- a/src/thothbot/parallax/core/shared/math/Ray.java +++ b/src/thothbot/parallax/core/shared/math/Ray.java @@ -264,18 +264,21 @@ public boolean isIntersectionSphere( Sphere sphere ) public Vector3 intersectSphere( Sphere sphere ) { return intersectSphere(sphere, null); } - - public Vector3 intersectSphere( Sphere sphere, Vector3 optionalTarget ) { - - // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/ - - Vector3 v1 = new Vector3(); - v1.sub( sphere.getCenter(), this.getOrigin() ); + /** + * from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/ + * @param sphere + * @param optionalTarget + * @return + */ + static Vector3 _v1 = new Vector3(); + public Vector3 intersectSphere( Sphere sphere, Vector3 optionalTarget ) + { + _v1.sub( sphere.getCenter(), this.getOrigin() ); - double tca = v1.dot( this.direction ); + double tca = _v1.dot( this.direction ); - double d2 = v1.dot( v1 ) - tca * tca; + double d2 = _v1.dot( _v1 ) - tca * tca; double radius2 = sphere.getRadius() * sphere.getRadius(); @@ -370,17 +373,20 @@ public Vector3 intersectPlane( Plane plane, Vector3 optionalTarget ) return this.at( t, optionalTarget ); } - public boolean isIntersectionBox(Box3 box) { - - Vector3 v = new Vector3(); - - return this.intersectBox( box, v ) != null; + static Vector3 _v2 = new Vector3(); + public boolean isIntersectionBox(Box3 box) + { + return this.intersectBox( box, _v2 ) != null; } - public Vector3 intersectBox( Box3 box, Vector3 optionalTarget ) { - - // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/ - + /** + * http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/ + * @param box + * @param optionalTarget + * @return + */ + public Vector3 intersectBox( Box3 box, Vector3 optionalTarget ) + { double tmin,tmax,tymin,tymax,tzmin,tzmax; double invdirx = 1.0 / this.direction.x, @@ -442,30 +448,38 @@ public Vector3 intersectBox( Box3 box, Vector3 optionalTarget ) { return this.at( tmin >= 0 ? tmin : tmax, optionalTarget ); } - public Vector3 intersectTriangle(Vector3 a, Vector3 b, Vector3 c, boolean backfaceCulling) { + public Vector3 intersectTriangle(Vector3 a, Vector3 b, Vector3 c, boolean backfaceCulling) + { return intersectTriangle(a,b,c, backfaceCulling, new Vector3()); } + /** + * from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp + * @param a + * @param b + * @param c + * @param backfaceCulling + * @param optionalTarget + * @return + */ + static Vector3 _diff = new Vector3(); + static Vector3 _edge1 = new Vector3(); + static Vector3 _edge2 = new Vector3(); + static Vector3 _normal = new Vector3(); public Vector3 intersectTriangle(Vector3 a, Vector3 b, Vector3 c, boolean backfaceCulling, Vector3 optionalTarget) { // Compute the offset origin, edges, and normal. - Vector3 diff = new Vector3(); - Vector3 edge1 = new Vector3(); - Vector3 edge2 = new Vector3(); - Vector3 normal = new Vector3(); - - // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp - edge1.sub( b, a ); - edge2.sub( c, a ); - normal.cross( edge1, edge2 ); + _edge1.sub( b, a ); + _edge2.sub( c, a ); + _normal.cross( _edge1, _edge2 ); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction, // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2)) // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q)) // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N) - double DdN = this.direction.dot( normal ); + double DdN = this.direction.dot( _normal ); double sign; if ( DdN > 0 ) { @@ -484,8 +498,8 @@ public Vector3 intersectTriangle(Vector3 a, Vector3 b, Vector3 c, boolean backfa } - diff.sub( this.origin, a ); - double DdQxE2 = sign * this.direction.dot( edge2.cross( diff, edge2 ) ); + _diff.sub( this.origin, a ); + double DdQxE2 = sign * this.direction.dot( _edge2.cross( _diff, _edge2 ) ); // b1 < 0, no intersection if ( DdQxE2 < 0 ) { @@ -494,7 +508,7 @@ public Vector3 intersectTriangle(Vector3 a, Vector3 b, Vector3 c, boolean backfa } - double DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) ); + double DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) ); // b2 < 0, no intersection if ( DdE1xQ < 0 ) { @@ -511,7 +525,7 @@ public Vector3 intersectTriangle(Vector3 a, Vector3 b, Vector3 c, boolean backfa } // Line intersects triangle, check if ray does. - double QdN = - sign * diff.dot( normal ); + double QdN = - sign * _diff.dot( _normal ); // t < 0, no intersection if ( QdN < 0 ) { diff --git a/src/thothbot/parallax/core/shared/math/Sphere.java b/src/thothbot/parallax/core/shared/math/Sphere.java index 717851dc..bc8c6a8d 100644 --- a/src/thothbot/parallax/core/shared/math/Sphere.java +++ b/src/thothbot/parallax/core/shared/math/Sphere.java @@ -66,30 +66,28 @@ public Sphere set( Vector3 center, double radius ) return this; } - public Sphere setFromPoints(List points, Vector3 optionalCenter) { + public Sphere setFromPoints(List points, Vector3 optionalCenter) + { return setFromPoints(points.toArray(new Vector3[points.size()]), optionalCenter); } - - public Sphere setFromPoints(Vector3[] points, Vector3 optionalCenter) { - - Box3 box = new Box3(); - - if ( optionalCenter != null ) { + static Box3 _box = new Box3(); + public Sphere setFromPoints(Vector3[] points, Vector3 optionalCenter) + { + if ( optionalCenter != null ) + { center.copy( optionalCenter ); - - } else { - - box.setFromPoints( points ).center( center ); - + } + else + { + _box.setFromPoints( points ).center( center ); } double maxRadiusSq = 0; - for ( int i = 0, il = points.length; i < il; i ++ ) { - + for ( int i = 0, il = points.length; i < il; i ++ ) + { maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) ); - } this.radius = Math.sqrt( maxRadiusSq ); diff --git a/src/thothbot/parallax/core/shared/math/Vector3.java b/src/thothbot/parallax/core/shared/math/Vector3.java index 791e71fc..419420f6 100644 --- a/src/thothbot/parallax/core/shared/math/Vector3.java +++ b/src/thothbot/parallax/core/shared/math/Vector3.java @@ -646,13 +646,16 @@ public Vector3 projectOnPlane(Vector3 planeNormal) } + /** + * reflect incident vector off plane orthogonal to normal + * normal is assumed to have unit length + * @param normal + * @return + */ + static Vector3 _v1 = new Vector3(); public Vector3 reflect(Vector3 normal) { - // reflect incident vector off plane orthogonal to normal - // normal is assumed to have unit length - - Vector3 v1 = new Vector3(); - return this.sub( v1.copy( normal ).multiply( 2 * this.dot( normal ) ) ); + return this.sub( _v1.copy( normal ).multiply( 2 * this.dot( normal ) ) ); } public double angleTo( Vector3 v ) diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index 129696b6..2d899892 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -125,50 +125,49 @@ public void updateMorphTargets() { } } + - public void raycast( Raycaster raycaster, List intersects) { + Matrix4 _inverseMatrix = new Matrix4(); + Ray _ray = new Ray(); + Sphere _sphere = new Sphere(); - Matrix4 inverseMatrix = new Matrix4(); - Ray ray = new Ray(); - Sphere sphere = new Sphere(); + Vector3 _vA = new Vector3(); + Vector3 _vB = new Vector3(); + Vector3 _vC = new Vector3(); - Vector3 vA = new Vector3(); - Vector3 vB = new Vector3(); - Vector3 vC = new Vector3(); + public void raycast( Raycaster raycaster, List intersects) { // Checking boundingSphere distance to ray AbstractGeometry geometry = this.getGeometry(); - if ( geometry.getBoundingSphere() == null ) geometry.computeBoundingSphere(); + if ( geometry.getBoundingSphere() == null ) + geometry.computeBoundingSphere(); - sphere.copy( geometry.getBoundingSphere() ); - sphere.apply( this.matrixWorld ); - - if ( raycaster.getRay().isIntersectionSphere( sphere ) == false ) { + _sphere.copy( geometry.getBoundingSphere() ); + _sphere.apply( this.matrixWorld ); + if ( raycaster.getRay().isIntersectionSphere( _sphere ) == false ) + { return; - } // Check boundingBox before continuing - inverseMatrix.getInverse( this.matrixWorld ); - ray.copy( raycaster.getRay() ).apply( inverseMatrix ); - - if ( geometry.getBoundingBox() != null ) { - - if ( ray.isIntersectionBox( geometry.getBoundingBox() ) == false ) { + _inverseMatrix.getInverse( this.matrixWorld ); + _ray.copy( raycaster.getRay() ).apply( _inverseMatrix ); + if ( geometry.getBoundingBox() != null ) + { + if ( _ray.isIntersectionBox( geometry.getBoundingBox() ) == false ) + { return; - } - } double precision = Raycaster.PRECISION; - if ( geometry instanceof BufferGeometry ) { - + if ( geometry instanceof BufferGeometry ) + { Material material = this.getMaterial(); if ( material == null ) return; @@ -181,38 +180,37 @@ public void raycast( Raycaster raycaster, List intersects) Float32Array positions = (Float32Array)bGeometry.getAttribute("position").getArray(); List offsets = bGeometry.getDrawcalls(); - if ( offsets.size() == 0 ) { - + if ( offsets.size() == 0 ) + { offsets.add(new BufferGeometry.DrawCall(0, indices.getLength(), 0)); - } - for ( int oi = 0, ol = offsets.size(); oi < ol; ++oi ) { - + for ( int oi = 0, ol = offsets.size(); oi < ol; ++oi ) + { int start = offsets.get( oi ).start; int count = offsets.get( oi ).count; int index = offsets.get( oi ).index; - for ( int i = start, il = start + count; i < il; i += 3 ) { + for ( int i = start, il = start + count; i < il; i += 3 ) + { int a = index + (int)indices.get( i ); int b = index + (int)indices.get( i + 1 ); int c = index + (int)indices.get( i + 2 ); - vA.fromArray( positions, a * 3 ); - vB.fromArray( positions, b * 3 ); - vC.fromArray( positions, c * 3 ); + _vA.fromArray( positions, a * 3 ); + _vB.fromArray( positions, b * 3 ); + _vC.fromArray( positions, c * 3 ); Vector3 intersectionPoint; - if ( material.getSides() == Material.SIDE.BACK ) { - - intersectionPoint = ray.intersectTriangle( vC, vB, vA, true); - - } else { - - intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.getSides() != Material.SIDE.DOUBLE ); - + if ( material.getSides() == Material.SIDE.BACK ) + { + intersectionPoint = _ray.intersectTriangle( _vC, _vB, _vA, true); + } + else + { + intersectionPoint = _ray.intersectTriangle( _vA, _vB, _vC, material.getSides() != Material.SIDE.DOUBLE ); } if ( intersectionPoint == null ) continue; @@ -226,7 +224,7 @@ public void raycast( Raycaster raycaster, List intersects) Raycaster.Intersect intersect = new Raycaster.Intersect(); intersect.distance = distance; intersect.point = intersectionPoint; - intersect.face = new Face3( a, b, c, Triangle.normal( vA, vB, vC ) ); + intersect.face = new Face3( a, b, c, Triangle.normal( _vA, _vB, _vC ) ); intersect.object = this; intersects.add( intersect ); @@ -244,19 +242,19 @@ public void raycast( Raycaster raycaster, List intersects) int b = i + 1; int c = i + 2; - vA.fromArray( positions, j ); - vB.fromArray( positions, j + 3 ); - vC.fromArray( positions, j + 6 ); + _vA.fromArray( positions, j ); + _vB.fromArray( positions, j + 3 ); + _vC.fromArray( positions, j + 6 ); Vector3 intersectionPoint; if ( material.getSides() == Material.SIDE.BACK ) { - intersectionPoint = ray.intersectTriangle( vC, vB, vA, true, null ); + intersectionPoint = _ray.intersectTriangle( _vC, _vB, _vA, true, null ); } else { - intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.getSides() != Material.SIDE.DOUBLE, null ); + intersectionPoint = _ray.intersectTriangle( _vA, _vB, _vC, material.getSides() != Material.SIDE.DOUBLE, null ); } @@ -271,7 +269,7 @@ public void raycast( Raycaster raycaster, List intersects) Raycaster.Intersect intersect = new Raycaster.Intersect(); intersect.distance = distance; intersect.point = intersectionPoint; - intersect.face = new Face3( a, b, c, Triangle.normal( vA, vB, vC ) ); + intersect.face = new Face3( a, b, c, Triangle.normal( _vA, _vB, _vC ) ); intersect.object = this; intersects.add( intersect ); @@ -304,9 +302,9 @@ public void raycast( Raycaster raycaster, List intersects) List morphTargets = aGeometry.getMorphTargets(); - vA.set( 0, 0, 0 ); - vB.set( 0, 0, 0 ); - vC.set( 0, 0, 0 ); + _vA.set( 0, 0, 0 ); + _vB.set( 0, 0, 0 ); + _vC.set( 0, 0, 0 ); for ( int t = 0, tl = morphTargets.size(); t < tl; t ++ ) { @@ -316,27 +314,27 @@ public void raycast( Raycaster raycaster, List intersects) List targets = morphTargets.get( t ).vertices; - vA.setX( vA.getX() + ( targets.get( face.getA() ).getX() - a.getX() ) * influence ); - vA.setY( vA.getY() + ( targets.get( face.getA() ).getY() - a.getY() ) * influence ); - vA.setZ( vA.getZ() + ( targets.get( face.getA() ).getZ() - a.getZ() ) * influence ); + _vA.setX( _vA.getX() + ( targets.get( face.getA() ).getX() - a.getX() ) * influence ); + _vA.setY( _vA.getY() + ( targets.get( face.getA() ).getY() - a.getY() ) * influence ); + _vA.setZ( _vA.getZ() + ( targets.get( face.getA() ).getZ() - a.getZ() ) * influence ); - vB.setX( vB.getX() + ( targets.get( face.getB() ).getX() - b.getX() ) * influence ); - vB.setY( vB.getY() + ( targets.get( face.getB() ).getY() - b.getY() ) * influence ); - vB.setZ( vB.getZ() + ( targets.get( face.getB() ).getZ() - b.getZ() ) * influence ); + _vB.setX( _vB.getX() + ( targets.get( face.getB() ).getX() - b.getX() ) * influence ); + _vB.setY( _vB.getY() + ( targets.get( face.getB() ).getY() - b.getY() ) * influence ); + _vB.setZ( _vB.getZ() + ( targets.get( face.getB() ).getZ() - b.getZ() ) * influence ); - vC.setX( vC.getX() + ( targets.get( face.getC() ).getX() - c.getX() ) * influence ); - vC.setY( vC.getY() + ( targets.get( face.getC() ).getY() - c.getY() ) * influence ); - vC.setZ( vC.getZ() + ( targets.get( face.getC() ).getZ() - c.getZ() ) * influence ); + _vC.setX( _vC.getX() + ( targets.get( face.getC() ).getX() - c.getX() ) * influence ); + _vC.setY( _vC.getY() + ( targets.get( face.getC() ).getY() - c.getY() ) * influence ); + _vC.setZ( _vC.getZ() + ( targets.get( face.getC() ).getZ() - c.getZ() ) * influence ); } - vA.add( a ); - vB.add( b ); - vC.add( c ); + _vA.add( a ); + _vB.add( b ); + _vC.add( c ); - a = vA; - b = vB; - c = vC; + a = _vA; + b = _vB; + c = _vC; } @@ -344,11 +342,11 @@ public void raycast( Raycaster raycaster, List intersects) if ( material.getSides() == Material.SIDE.BACK ) { - intersectionPoint = ray.intersectTriangle( c, b, a, true ); + intersectionPoint = _ray.intersectTriangle( c, b, a, true ); } else { - intersectionPoint = ray.intersectTriangle( a, b, c, material.getSides() != Material.SIDE.DOUBLE ); + intersectionPoint = _ray.intersectTriangle( a, b, c, material.getSides() != Material.SIDE.DOUBLE ); } From b9fe2995fd2a1a1eba70081ff2209d40001bcbaa Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 2 Mar 2015 04:05:43 +0300 Subject: [PATCH 67/75] Refactored Vectors for performance improvements --- .../core/shared/core/ExtrudeGeometry.java | 9 +- .../parallax/core/shared/curves/Curve.java | 31 ++-- .../parallax/core/shared/curves/Path.java | 27 ++- .../parallax/core/shared/math/Vector.java | 172 ----------------- .../parallax/core/shared/math/Vector2.java | 88 ++++----- .../parallax/core/shared/math/Vector3.java | 175 +++++++++--------- .../parallax/core/shared/math/Vector4.java | 82 +++----- 7 files changed, 183 insertions(+), 401 deletions(-) delete mode 100644 src/thothbot/parallax/core/shared/math/Vector.java diff --git a/src/thothbot/parallax/core/shared/core/ExtrudeGeometry.java b/src/thothbot/parallax/core/shared/core/ExtrudeGeometry.java index 30e92a84..6ea940a5 100644 --- a/src/thothbot/parallax/core/shared/core/ExtrudeGeometry.java +++ b/src/thothbot/parallax/core/shared/core/ExtrudeGeometry.java @@ -30,7 +30,6 @@ import thothbot.parallax.core.shared.curves.Shape; import thothbot.parallax.core.shared.math.Box3; import thothbot.parallax.core.shared.math.Color; -import thothbot.parallax.core.shared.math.Vector; import thothbot.parallax.core.shared.math.Vector2; import thothbot.parallax.core.shared.math.Vector3; import thothbot.parallax.core.shared.utils.ShapeUtils; @@ -127,7 +126,7 @@ public void addShape( Shape shape, ExtrudeGeometryParameters options ) { Log.debug("ExtrudeGeometry: Called addShape() shape=" + shape); - List extrudePts = null; + List extrudePts = null; boolean extrudeByPath = false; Vector3 binormal = new Vector3(); @@ -375,10 +374,10 @@ public void addShape( Shape shape, ExtrudeGeometryParameters options ) buildSideFaces(contour); } - private Vector2 getBevelVec( Vector pt_i, Vector pt_j, Vector pt_k ) + private Vector2 getBevelVec( Vector2 pt_i, Vector2 pt_j, Vector2 pt_k ) { // Algorithm 2 - return getBevelVec2( (Vector2)pt_i, (Vector2)pt_j, (Vector2)pt_k ); + return getBevelVec2( pt_i, pt_j, pt_k ); } private Vector2 getBevelVec1( Vector2 pt_i, Vector2 pt_j, Vector2 pt_k ) @@ -397,7 +396,7 @@ private Vector2 getBevelVec1( Vector2 pt_i, Vector2 pt_j, Vector2 pt_k ) return new Vector2( x, y ); //.normalize(); } - private Vector2 scalePt2 ( Vector pt, Vector vec, double size ) + private Vector2 scalePt2 ( Vector2 pt, Vector2 vec, double size ) { return (Vector2) vec.clone().multiply( size ).add( pt ); } diff --git a/src/thothbot/parallax/core/shared/curves/Curve.java b/src/thothbot/parallax/core/shared/curves/Curve.java index 83e8cdf9..aa6e2a49 100644 --- a/src/thothbot/parallax/core/shared/curves/Curve.java +++ b/src/thothbot/parallax/core/shared/curves/Curve.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.List; -import thothbot.parallax.core.shared.math.Vector; import thothbot.parallax.core.shared.math.Vector2; // Abstract Curve base class @@ -35,19 +34,19 @@ public abstract class Curve /* * Virtual base class method to overwrite and implement in subclasses - t [0 .. 1] */ - public abstract Vector getPoint(double t); + public abstract Vector2 getPoint(double t); /* * Get point at relative position in curve according to arc length - u [0 .. 1] */ - public Vector getPointAt(double u) + public Vector2 getPointAt(double u) { double t = getUtoTmapping(u); return getPoint(t); } - public List getPoints() + public List getPoints() { return getPoints(5); } @@ -55,16 +54,16 @@ public List getPoints() /* * Get sequence of points using getPoint( t ) */ - public List getPoints(int divisions) + public List getPoints(int divisions) { - List pts = new ArrayList(); + List pts = new ArrayList(); for (int d = 0; d <= divisions; d++) pts.add(this.getPoint(d / (double)divisions)); return pts; } - public List getSpacedPoints() + public List getSpacedPoints() { return getSpacedPoints(5); } @@ -72,9 +71,9 @@ public List getSpacedPoints() /* * Get sequence of points using getPointAt( u ) */ - public List getSpacedPoints(int divisions) + public List getSpacedPoints(int divisions) { - List pts = new ArrayList(); + List pts = new ArrayList(); for (int d = 0; d <= divisions; d++) pts.add(this.getPointAt(d / (double)divisions)); @@ -116,11 +115,11 @@ public List getLengths(int divisions) List cache = new ArrayList(); cache.add(0.0); - Vector last = this.getPoint(0.0); + Vector2 last = this.getPoint(0.0); double sum = 0; for (int p = 1; p <= divisions; p++) { - Vector current = getPoint(p / (double)divisions); + Vector2 current = getPoint(p / (double)divisions); sum += current.distanceTo(last); last = current; @@ -224,7 +223,7 @@ public Vector2 getNormalVector( double t ) * delta and find a gradient of the 2 points which seems to make a * reasonable approximation */ - public Vector getTangent(double t) + public Vector2 getTangent(double t) { double delta = 0.0001; double t1 = t - delta; @@ -236,16 +235,16 @@ public Vector getTangent(double t) if (t2 > 1) t2 = 1; - Vector pt1 = this.getPoint(t1); - Vector pt2 = this.getPoint(t2); + Vector2 pt1 = this.getPoint(t1); + Vector2 pt2 = this.getPoint(t2); - Vector vec = pt2.clone(); + Vector2 vec = pt2.clone(); vec.sub(pt1); vec.normalize(); return vec; } - public Vector getTangentAt(double u) + public Vector2 getTangentAt(double u) { return this.getTangent(this.getUtoTmapping(u)); } diff --git a/src/thothbot/parallax/core/shared/curves/Path.java b/src/thothbot/parallax/core/shared/curves/Path.java index 729bc322..d5474537 100644 --- a/src/thothbot/parallax/core/shared/curves/Path.java +++ b/src/thothbot/parallax/core/shared/curves/Path.java @@ -23,7 +23,6 @@ import java.util.List; import thothbot.parallax.core.shared.core.Geometry; -import thothbot.parallax.core.shared.math.Vector; import thothbot.parallax.core.shared.math.Vector2; import thothbot.parallax.core.shared.math.Vector3; import thothbot.parallax.core.shared.utils.ShapeUtils; @@ -208,14 +207,14 @@ public void absellipse(double aX, double aY, double xRadius, double yRadius, - public List getSpacedPoints( boolean closedPath ) + public List getSpacedPoints( boolean closedPath ) { return getSpacedPoints(40, closedPath); } - public List getSpacedPoints( int divisions, boolean closedPath ) + public List getSpacedPoints( int divisions, boolean closedPath ) { - List points = new ArrayList(); + List points = new ArrayList(); for ( int i = 0; i < divisions; i ++ ) points.add( this.getPoint( i / (double)divisions ) ); @@ -229,17 +228,17 @@ public List getSpacedPoints( int divisions, boolean closedPath ) /* * @return an List of {@link Vector2} based on contour of the path */ - public List getPoints( boolean closedPath ) + public List getPoints( boolean closedPath ) { return getPoints(12, closedPath); } - public List getPoints( int divisions, boolean closedPath ) + public List getPoints( int divisions, boolean closedPath ) { if (this.useSpacedPoints) return this.getSpacedPoints( divisions, closedPath ); - List points = new ArrayList(); + List points = new ArrayList(); double cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0; @@ -273,10 +272,10 @@ public List getPoints( int divisions, boolean closedPath ) if ( points.size() > 0 ) { - Vector laste = points.get( points.size() - 1 ); + Vector2 laste = points.get( points.size() - 1 ); - cpx0 = ((Vector2)laste).getX(); - cpy0 = ((Vector2)laste).getY(); + cpx0 = laste.getX(); + cpy0 = laste.getY(); } else { @@ -311,10 +310,10 @@ public List getPoints( int divisions, boolean closedPath ) if ( points.size() > 0 ) { - Vector laste = points.get( points.size() - 1 ); + Vector2 laste = points.get( points.size() - 1 ); - cpx0 = ((Vector2)laste).getX(); - cpy0 = ((Vector2)laste).getY(); + cpx0 = laste.getX(); + cpy0 = laste.getY(); } else { @@ -598,7 +597,7 @@ public Geometry createSpacedPointsGeometry( int divisions ) return createGeometry( getSpacedPoints( divisions, true ) ); } - private Geometry createGeometry(List points) + private Geometry createGeometry(List points) { Geometry geometry = new Geometry(); diff --git a/src/thothbot/parallax/core/shared/math/Vector.java b/src/thothbot/parallax/core/shared/math/Vector.java deleted file mode 100644 index da298a33..00000000 --- a/src/thothbot/parallax/core/shared/math/Vector.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2012 Alex Usachev, thothbot@gmail.com - * - * This file is part of Parallax project. - * - * Parallax is free software: you can redistribute it and/or modify it - * under the terms of the Creative Commons Attribution 3.0 Unported License. - * - * Parallax is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution - * 3.0 Unported License. for more details. - * - * You should have received a copy of the the Creative Commons Attribution - * 3.0 Unported License along with Parallax. - * If not, see http://creativecommons.org/licenses/by/3.0/. - */ - -package thothbot.parallax.core.shared.math; - -/** - * Interface of the vector. - */ -public interface Vector -{ - /** - * Sets the value of this vector to the vector sum of itself and vector v. - * - * @param v the other vector - * - * @return the current vector - */ - public Vector add(Vector v); - - /** - * Sets the value of this vector to the vector sum of vectors v1 and v2. - * - * @param v1 the first vector - * @param v2 the second vector - * - * @return the current vector - */ - public Vector add(Vector v1, Vector v2); - - /** - * Sets the value of this vector to the vector sum of itself and scalar s. - * (this = this + s) - * - * @param s the scalar value - * - * @return the current vector - */ - public Vector add(double s); - - /** - * Sets the value of this vector to the vector difference of itself and - * vector v. - * (this = this - v) - * - * @param v the other vector - * - * @return the current vector - */ - public Vector sub(Vector v); - - /** - * Sets the value of this vector to the vector difference of v1 and - * vector v2. - * - * @param v1 the first vector - * @param v2 the second vector - * - * @return the current vector - */ - public Vector sub(Vector v1, Vector v2); - - /** - * Sets the value of this vector to the vector multiplication of itself and - * vector v. - * (this = this * v) - * - * @param v the other vector - * - * @return the current vector - */ - public Vector multiply(Vector v); - - /** - * Sets the value of this vector to the vector multiplication of v1 and - * vector v2. - * - * @param v1 the first vector - * @param v2 the second vector - * - * @return the current vector - */ - public Vector multiply(Vector v1, Vector v2); - - /** - * Sets the value of this vector to the scalar multiplication of the scale - * factor with this. - * - * @param s the scalar value - * - * @return the current vector - */ - public Vector multiply(double s); - - /** - * Sets the value of this vector to the vector division of itself and - * vector v. - * (this = this / v) - * - * @param v the other vector - * - * @return the current vector - */ - public Vector divide(Vector v); - - /** - * Sets the value of this vector to the scalar division of the scale - * factor with this. - * If the scalar is 0 then will be vector where last coordinate is 1. - * - * @param s the scalar value - * - * @return the current vector - */ - public Vector divide(double s); - - /** - * Sets the value of this vector to the vector division of v1 and - * vector v2. - * - * @param v1 the first vector - * @param v2 the second vector - * - * @return the current vector - */ - public Vector divide(Vector v1, Vector v2); - - /** - * Negates the value of this vector in place. - * - * @return the current vector - */ - public Vector negate(); - - /** - * get distance between two vectors. - * - * @param v1 - * second vector - * @return a distance between two vectors - */ - public double distanceTo(Vector v1); - - /** - * get squared distance between two vectors. - * - * @param v - * second vector - * @return a squared distance between two vectors. - */ - public double distanceToSquared(Vector v); - - - public Vector normalize(); - - public Vector clone(); - public String toString(); -} diff --git a/src/thothbot/parallax/core/shared/math/Vector2.java b/src/thothbot/parallax/core/shared/math/Vector2.java index 85442a25..fce0d653 100644 --- a/src/thothbot/parallax/core/shared/math/Vector2.java +++ b/src/thothbot/parallax/core/shared/math/Vector2.java @@ -28,7 +28,7 @@ * * @author thothbot */ -public class Vector2 implements Vector +public class Vector2 { /** * The X-coordinate @@ -170,25 +170,24 @@ public double getComponent ( int index ) { */ public Vector2 copy(Vector2 v) { - this.set(v.getX(), v.getY()); + this.set(v.x, v.y); + return this; } - @Override - public Vector2 add(Vector v) + public Vector2 add(Vector2 v) { return this.add(this, v); } - @Override - public Vector2 add(Vector v1, Vector v2) + public Vector2 add(Vector2 v1, Vector2 v2) { - this.setX(((Vector2)v1).getX() + ((Vector2)v2).getX()); - this.setY(((Vector2)v1).getY() + ((Vector2)v2).getY()); + this.x = v1.x + v2.x; + this.y = v1.y + v2.y; + return this; } - @Override public Vector2 add(double s) { this.addX(s); @@ -197,37 +196,32 @@ public Vector2 add(double s) return this; } - @Override - public Vector2 sub(Vector v) + public Vector2 sub(Vector2 v) { return this.sub(this, v); } - @Override - public Vector2 sub(Vector v1, Vector v2) + public Vector2 sub(Vector2 v1, Vector2 v2) { - this.setX(((Vector2)v1).getX() - ((Vector2)v2).getX()); - this.setY(((Vector2)v1).getY() - ((Vector2)v2).getY()); - + this.x = v1.x - v2.x; + this.y = v1.y - v2.y; + return this; } - @Override - public Vector2 multiply(Vector v) + public Vector2 multiply(Vector2 v) { return this.multiply(this, v); } - @Override - public Vector2 multiply(Vector v1, Vector v2) + public Vector2 multiply(Vector2 v1, Vector2 v2) { - this.setX(((Vector2)v1).getX() * ((Vector2)v2).getX()); - this.setY(((Vector2)v1).getY() * ((Vector2)v2).getY()); - + this.x = v1.x * v2.x; + this.y = v1.y * v2.y; + return this; } - @Override public Vector2 multiply(double s) { this.x *= s; @@ -236,22 +230,19 @@ public Vector2 multiply(double s) return this; } - @Override - public Vector2 divide(Vector v) + public Vector2 divide(Vector2 v) { return this.divide(this, v); } - @Override - public Vector2 divide(Vector v1, Vector v2) + public Vector2 divide(Vector2 v1, Vector2 v2) { - this.setX(((Vector2)v1).getX() / ((Vector2)v2).getX()); - this.setY(((Vector2)v1).getY() / ((Vector2)v2).getY()); - + this.x = v1.x / v2.x; + this.y = v1.y / v2.y; + return this; } - @Override public Vector2 divide(double s) { if (s != 0) @@ -323,16 +314,16 @@ else if ( this.y > max.y ) return this; } - - public Vector2 clamp (double minVal, double maxVal) { - Vector2 min = new Vector2(); - Vector2 max = new Vector2(); + static Vector2 _min = new Vector2(); + static Vector2 _max = new Vector2(); - min.set( minVal, minVal ); - max.set( maxVal, maxVal ); + public Vector2 clamp(double minVal, double maxVal) + { + _min.set( minVal, minVal ); + _max.set( maxVal, maxVal ); - return this.clamp( min, max ); + return this.clamp( _min, _max ); } public Vector2 floor() { @@ -416,7 +407,6 @@ public double length() /** * Normalizes this vector in place. */ - @Override public Vector2 normalize() { this.divide(length()); @@ -427,11 +417,10 @@ public Vector2 normalize() * (non-Javadoc) * @see thothbot.parallax.core.shared.core.Vector#distanceToSquared(thothbot.parallax.core.shared.core.Vector) */ - @Override - public double distanceToSquared(Vector v) + public double distanceToSquared(Vector2 v) { - double dx = this.getX() - ((Vector2) v).getX(); - double dy = this.getY() - ((Vector2) v).getY(); + double dx = this.x - v.x; + double dy = this.y - v.y; return (dx * dx + dy * dy); } @@ -439,8 +428,7 @@ public double distanceToSquared(Vector v) * (non-Javadoc) * @see thothbot.parallax.core.shared.core.Vector#distanceTo(thothbot.parallax.core.shared.core.Vector) */ - @Override - public double distanceTo(Vector v1) + public double distanceTo(Vector2 v1) { return Math.sqrt(distanceToSquared(v1)); } @@ -483,20 +471,20 @@ public Vector2 fromArray( Float32Array array, int offset ) { } - public Float32Array toArray() { + public Float32Array toArray() + { return toArray(Float32Array.create(2), 0); } - public Float32Array toArray( Float32Array array, int offset ) { + public Float32Array toArray( Float32Array array, int offset ) + { array.set( offset , this.x); array.set( offset + 1 , this.y); return array; - } - @Override public Vector2 clone() { return new Vector2(this.x, this.y); diff --git a/src/thothbot/parallax/core/shared/math/Vector3.java b/src/thothbot/parallax/core/shared/math/Vector3.java index 419420f6..76e1b56b 100644 --- a/src/thothbot/parallax/core/shared/math/Vector3.java +++ b/src/thothbot/parallax/core/shared/math/Vector3.java @@ -31,7 +31,7 @@ * * @author thothbot */ -public class Vector3 extends Vector2 implements Vector +public class Vector3 extends Vector2 { /** * The Z-coordinate @@ -155,21 +155,21 @@ public double getComponent( int index ) { public Vector3 copy(Vector3 v) { this.set(v.getX(), v.getY(), v.getZ()); + return this; } - @Override - public Vector3 add(Vector v) + public Vector3 add(Vector3 v) { return this.add(this, v); } - @Override - public Vector3 add(Vector v1, Vector v2) + public Vector3 add(Vector3 v1, Vector3 v2) { - this.setX(((Vector3)v1).getX() + ((Vector3)v2).getX()); - this.setY(((Vector3)v1).getY() + ((Vector3)v2).getY()); - this.setZ(((Vector3)v1).getZ() + ((Vector3)v2).getZ()); + this.x = v1.x + v2.x; + this.y = v1.y + v2.y; + this.z = v1.z + v2.z; + return this; } @@ -179,40 +179,38 @@ public Vector3 add(double s) this.addX(s); this.addY(s); this.addZ(s); + return this; } - @Override - public Vector3 sub(Vector v) + public Vector3 sub(Vector3 v) { return this.sub(this, v); } - @Override - public Vector3 sub(Vector v1, Vector v2) + public Vector3 sub(Vector3 v1, Vector3 v2) { - this.setX(((Vector3)v1).getX() - ((Vector3)v2).getX()); - this.setY(((Vector3)v1).getY() - ((Vector3)v2).getY()); - this.setZ(((Vector3)v1).getZ() - ((Vector3)v2).getZ()); + this.x = v1.x - v2.x; + this.y = v1.y - v2.y; + this.z = v1.z - v2.z; + return this; } - @Override - public Vector3 multiply(Vector v) + public Vector3 multiply(Vector3 v) { return this.multiply(this, v); } - @Override - public Vector3 multiply(Vector v1, Vector v2) + public Vector3 multiply(Vector3 v1, Vector3 v2) { - this.setX(((Vector3)v1).getX() * ((Vector3)v2).getX()); - this.setY(((Vector3)v1).getY() * ((Vector3)v2).getY()); - this.setZ(((Vector3)v1).getZ() * ((Vector3)v2).getZ()); + this.x = v1.x * v2.x; + this.y = v1.y * v2.y; + this.z = v1.z * v2.z; + return this; } - @Override public Vector3 multiply(double s) { this.x *= s; @@ -221,20 +219,17 @@ public Vector3 multiply(double s) return this; } + static Quaternion _quaternion = new Quaternion(); public Vector3 applyEuler( Euler euler) - { - Quaternion quaternion = new Quaternion(); - - this.apply( quaternion.setFromEuler( euler ) ); + { + this.apply( _quaternion.setFromEuler( euler ) ); return this; } public Vector3 applyAxisAngle(Vector3 axis, double angle) { - Quaternion quaternion = new Quaternion(); - - this.apply( quaternion.setFromAxisAngle( axis, angle ) ); + this.apply( _quaternion.setFromAxisAngle( axis, angle ) ); return this; } @@ -254,11 +249,13 @@ public Vector3 apply( Matrix3 m ) return this; } + /** + * + * @param m Matrix4 affine matrix + * @return + */ public Vector3 apply( Matrix4 m ) { - - // input: THREE.Matrix4 affine matrix - double x = this.x, y = this.y, z = this.z; Float32Array e = m.getArray(); @@ -316,22 +313,19 @@ public Vector3 apply( Quaternion q ) return this; } - - public Vector3 project(Camera camera) { - - Matrix4 matrix = new Matrix4(); - matrix.multiply( camera.getProjectionMatrix(), matrix.getInverse( camera.getMatrixWorld() ) ); - return this.applyProjection( matrix ); + static Matrix4 _matrix = new Matrix4(); + public Vector3 project(Camera camera) + { + _matrix.multiply( camera.getProjectionMatrix(), _matrix.getInverse( camera.getMatrixWorld() ) ); + return this.applyProjection( _matrix ); } - public Vector3 unproject(Camera camera) { - - Matrix4 matrix = new Matrix4(); - - matrix.multiply( camera.getMatrixWorld(), matrix.getInverse( camera.getProjectionMatrix() ) ); - return this.applyProjection( matrix ); + public Vector3 unproject(Camera camera) + { + _matrix.multiply( camera.getMatrixWorld(), _matrix.getInverse( camera.getProjectionMatrix() ) ); + return this.applyProjection( _matrix ); } /** @@ -354,18 +348,17 @@ public Vector3 transformDirection( Matrix4 m ) return this; } - @Override - public Vector3 divide(Vector v) + public Vector3 divide(Vector3 v) { return this.divide(this, v); } - @Override - public Vector3 divide(Vector v1, Vector v2) + public Vector3 divide(Vector3 v1, Vector3 v2) { - this.setX(((Vector3)v1).getX() / ((Vector3)v2).getX()); - this.setY(((Vector3)v1).getY() / ((Vector3)v2).getY()); - this.setZ(((Vector3)v1).getZ() / ((Vector3)v2).getZ()); + this.x = v1.x / v2.x; + this.y = v1.y / v2.y; + this.z = v1.z / v2.z; + return this; } @@ -471,18 +464,19 @@ public Vector3 clamp( Vector3 min, Vector3 max ) return this; } - - public Vector3 clamp(double minVal, double maxVal) { - Vector3 min = new Vector3(), max = new Vector3(); - - min.set( minVal, minVal, minVal ); - max.set( maxVal, maxVal, maxVal ); + static Vector3 _min = new Vector3(); + static Vector3 _max = new Vector3(); + public Vector3 clamp(double minVal, double maxVal) + { + _min.set( minVal, minVal, minVal ); + _max.set( maxVal, maxVal, maxVal ); - return this.clamp( min, max ); + return this.clamp( _min, _max ); } - public Vector3 floor() { + public Vector3 floor() + { this.x = Math.floor( this.x ); this.y = Math.floor( this.y ); @@ -492,7 +486,8 @@ public Vector3 floor() { } - public Vector3 ceil() { + public Vector3 ceil() + { this.x = Math.ceil( this.x ); this.y = Math.ceil( this.y ); @@ -502,7 +497,8 @@ public Vector3 ceil() { } - public Vector3 round() { + public Vector3 round() + { this.x = Math.round( this.x ); this.y = Math.round( this.y ); @@ -512,7 +508,8 @@ public Vector3 round() { } - public Vector3 roundToZero() { + public Vector3 roundToZero() + { this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x ); this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y ); @@ -624,25 +621,20 @@ public Vector3 cross(Vector3 v) return cross(this, v); } - public Vector3 projectOnVector(Vector3 vector) { - Vector3 v1 = new Vector3(); - - v1.copy( vector ).normalize(); + _v1.copy( vector ).normalize(); - double dot = this.dot( v1 ); + double dot = this.dot( _v1 ); - return this.copy( v1 ).multiply( dot ); + return this.copy( _v1 ).multiply( dot ); } public Vector3 projectOnPlane(Vector3 planeNormal) { - Vector3 v1 = new Vector3(); - - v1.copy( this ).projectOnVector( planeNormal ); + _v1.copy( this ).projectOnVector( planeNormal ); - return this.sub( v1 ); + return this.sub( _v1 ); } @@ -667,22 +659,21 @@ public double angleTo( Vector3 v ) return Math.acos( Mathematics.clamp( theta, - 1, 1 ) ); } - @Override - public double distanceTo(Vector v1) + public double distanceTo(Vector3 v1) { return Math.sqrt(distanceToSquared(v1)); } - - @Override - public double distanceToSquared(Vector v1) + + public double distanceToSquared(Vector3 v1) { - double dx = this.getX() - ((Vector3)v1).getX(); - double dy = this.getY() - ((Vector3)v1).getY(); - double dz = this.getZ() - ((Vector3)v1).getZ(); + double dx = this.x - v1.x; + double dy = this.y - v1.y; + double dz = this.z - v1.z; return (dx * dx + dy * dy + dz * dz); } - public Vector3 setFromMatrixPosition( Matrix4 m ) { + public Vector3 setFromMatrixPosition( Matrix4 m ) + { this.x = m.getArray().get( 12 ); this.y = m.getArray().get( 13 ); @@ -691,7 +682,8 @@ public Vector3 setFromMatrixPosition( Matrix4 m ) { return this; } - public Vector3 setFromMatrixScale( Matrix4 m ) { + public Vector3 setFromMatrixScale( Matrix4 m ) + { double sx = this.set( m.getArray().get( 0 ), m.getArray().get( 1 ), m.getArray().get( 2 ) ).length(); double sy = this.set( m.getArray().get( 4 ), m.getArray().get( 5 ), m.getArray().get( 6 ) ).length(); @@ -704,7 +696,8 @@ public Vector3 setFromMatrixScale( Matrix4 m ) { return this; } - public Vector3 setFromMatrixColumn( int index, Matrix4 matrix ) { + public Vector3 setFromMatrixColumn( int index, Matrix4 matrix ) + { int offset = index * 4; @@ -731,11 +724,13 @@ public boolean equals(Vector3 v1) return (this.x == v1.x && this.y == v1.y && this.z == v1.z); } - public Vector3 fromArray ( Float32Array array ) { + public Vector3 fromArray ( Float32Array array ) + { return fromArray(array, 0); } - public Vector3 fromArray ( Float32Array array, int offset ) { + public Vector3 fromArray ( Float32Array array, int offset ) + { this.x = array.get( offset ); this.y = array.get( offset + 1 ); @@ -745,11 +740,13 @@ public Vector3 fromArray ( Float32Array array, int offset ) { } - public Float32Array toArray() { + public Float32Array toArray() + { return toArray(Float32Array.create(3), 0); } - public Float32Array toArray( Float32Array array, int offset ) { + public Float32Array toArray( Float32Array array, int offset ) + { array.set( offset , this.x); array.set( offset + 1 , this.y); @@ -758,13 +755,11 @@ public Float32Array toArray( Float32Array array, int offset ) { return array; } - @Override public Vector3 clone() { return new Vector3(this.getX(), this.getY(), this.getZ()); } - @Override public String toString() { return "(" + this.x + ", " + this.y + ", " + this.z + ")"; diff --git a/src/thothbot/parallax/core/shared/math/Vector4.java b/src/thothbot/parallax/core/shared/math/Vector4.java index 7884cf6c..933fcb74 100644 --- a/src/thothbot/parallax/core/shared/math/Vector4.java +++ b/src/thothbot/parallax/core/shared/math/Vector4.java @@ -30,7 +30,7 @@ * * @author thothbot */ -public class Vector4 extends Vector3 implements Vector +public class Vector4 extends Vector3 { /** * The W-coordinate @@ -125,7 +125,8 @@ public Vector4 set(double x, double y, double z, double w) return this; } - public void setComponent( int index, double value ) { + public void setComponent( int index, double value ) + { switch ( index ) { @@ -139,7 +140,8 @@ public void setComponent( int index, double value ) { } - public double getComponent( int index ) { + public double getComponent( int index ) + { switch ( index ) { @@ -162,7 +164,7 @@ public double getComponent( int index ) { */ public Vector4 copy(Vector4 v) { - return this.set(v.getX(), v.getY(), v.getZ(), v.getW()); + return this.set(v.x, v.y, v.z, v.w); } /** @@ -174,12 +176,7 @@ public Vector4 copy(Vector4 v) */ public Vector4 copy(Vector3 v) { - return this.set(v.getX(), v.getY(), v.getZ(), 1.0); - } - - public Vector4 add(Vector4 v) - { - return this.add(this, v); + return this.set(v.x, v.y, v.z, 1.0); } /** @@ -205,10 +202,9 @@ public Vector4 add(Vector4 v1, Vector4 v2) * @param v * the other vector */ - @Override - public Vector4 add(Vector v) + public Vector4 add(Vector4 v) { - return this.add(this, (Vector4) v); + return this.add(this, v); } public Vector4 add(double s) @@ -220,11 +216,6 @@ public Vector4 add(double s) return this; } - public Vector4 sub(Vector4 v) - { - return this.sub(this, v); - } - /** * Sets the value of this vector to the difference of vectors v1 and v2 * (this = v1 - v2). @@ -250,10 +241,9 @@ public Vector4 sub(Vector4 v1, Vector4 v2) * @param v * the other vector */ - @Override - public Vector4 sub(Vector v) + public Vector4 sub(Vector4 v) { - return this.sub(this, (Vector4)v); + return this.sub(this, v); } public Vector4 multiply(Vector4 v) @@ -351,7 +341,7 @@ public Vector4 divide(double scalar) */ public Vector4 setAxisAngleFromQuaternion( Quaternion q ) { - this.w = 2 * Math.acos( q.w ); + this.w = 2.0 * Math.acos( q.w ); double s = Math.sqrt( 1 - q.w * q.w ); @@ -591,18 +581,19 @@ else if ( this.w > max.w ) return this; } - - public Vector4 clamp( double minVal, double maxVal ) { - - Vector4 min = new Vector4(), max = new Vector4(); - min.set( minVal, minVal, minVal, minVal ); - max.set( maxVal, maxVal, maxVal, maxVal ); + static Vector4 _min = new Vector4(); + static Vector4 _max = new Vector4(); + public Vector4 clamp( double minVal, double maxVal ) + { + _min.set( minVal, minVal, minVal, minVal ); + _max.set( maxVal, maxVal, maxVal, maxVal ); - return this.clamp( min, max ); + return this.clamp( _min, _max ); } - public Vector4 floor() { + public Vector4 floor() + { this.x = Math.floor( this.x ); this.y = Math.floor( this.y ); @@ -613,7 +604,8 @@ public Vector4 floor() { } - public Vector4 ceil() { + public Vector4 ceil() + { this.x = Math.ceil( this.x ); this.y = Math.ceil( this.y ); @@ -624,7 +616,8 @@ public Vector4 ceil() { } - public Vector4 round() { + public Vector4 round() + { this.x = Math.round( this.x ); this.y = Math.round( this.y ); @@ -635,7 +628,8 @@ public Vector4 round() { } - public Vector4 roundToZero() { + public Vector4 roundToZero() + { this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x ); this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y ); @@ -694,7 +688,7 @@ public double lengthSq() public double lengthManhattan() { - return Math.abs( getX() ) + Math.abs( getY() ) + Math.abs( getZ() ) + Math.abs( getW() ); + return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w ); } /** @@ -736,33 +730,13 @@ public boolean equals( Vector4 v ) return ( ( v.x == this.x ) && ( v.y == this.y ) && ( v.z == this.z ) && ( v.w == this.w ) ); } - @Override public Vector4 clone() { return new Vector4(this.x, this.y, this.z, this.w); } - @Override public String toString() { return "(" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + ")"; } - -// /** -// * This method is not implemented yet. -// */ -// @Override -// public double distanceToSquared(Vector v1) -// { -// return 0; -// } -// -// /** -// * This method is not implemented yet. -// */ -// @Override -// public double distanceTo(Vector v) -// { -// return 0; -// } } From 929d528125135cd0d4488d3e7954efd608c4bb1b Mon Sep 17 00:00:00 2001 From: thothbot Date: Mon, 2 Mar 2015 15:03:44 +0300 Subject: [PATCH 68/75] Some performance update --- .../parallax/core/shared/core/Raycaster.java | 1 - .../parallax/core/shared/math/Box2.java | 21 +++-- .../parallax/core/shared/math/Box3.java | 20 ++--- .../parallax/core/shared/math/Euler.java | 75 ++++++++-------- .../parallax/core/shared/math/Frustum.java | 37 ++++---- .../parallax/core/shared/math/Line3.java | 15 ++-- .../parallax/core/shared/math/Matrix3.java | 25 +++--- .../parallax/core/shared/math/Matrix4.java | 88 +++++++++---------- .../parallax/core/shared/math/Plane.java | 28 +++--- .../parallax/core/shared/math/Quaternion.java | 71 ++++++++------- .../parallax/core/shared/math/Ray.java | 35 ++++---- .../parallax/core/shared/math/Sphere.java | 4 +- .../parallax/core/shared/math/Triangle.java | 49 +++++------ .../parallax/core/shared/math/Vector2.java | 7 +- .../parallax/core/shared/math/Vector3.java | 14 +-- .../parallax/core/shared/math/Vector4.java | 6 +- .../parallax/core/shared/objects/Mesh.java | 18 ++-- 17 files changed, 259 insertions(+), 255 deletions(-) diff --git a/src/thothbot/parallax/core/shared/core/Raycaster.java b/src/thothbot/parallax/core/shared/core/Raycaster.java index f8e88282..03595637 100644 --- a/src/thothbot/parallax/core/shared/core/Raycaster.java +++ b/src/thothbot/parallax/core/shared/core/Raycaster.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.List; -import thothbot.parallax.core.shared.Log; import thothbot.parallax.core.shared.math.Ray; import thothbot.parallax.core.shared.math.Vector3; import thothbot.parallax.core.shared.objects.Line; diff --git a/src/thothbot/parallax/core/shared/math/Box2.java b/src/thothbot/parallax/core/shared/math/Box2.java index 6355b8c4..7150bf61 100644 --- a/src/thothbot/parallax/core/shared/math/Box2.java +++ b/src/thothbot/parallax/core/shared/math/Box2.java @@ -24,6 +24,9 @@ public class Box2 { private Vector2 min; private Vector2 max; + + // Temporary variables + static Vector2 _v1 = new Vector2(); public Box2() { @@ -36,17 +39,21 @@ public Box2( Vector2 min, Vector2 max ) this.max = max; } - public Vector2 getMin() { + public Vector2 getMin() + { return min; } - public Vector2 getMax() { + public Vector2 getMax() + { return max; } - public void setMin(Vector2 min) { + public void setMin(Vector2 min) + { this.min = min; } - public void setMax(Vector2 max) { + public void setMax(Vector2 max) + { this.max = max; } @@ -73,10 +80,8 @@ public Box2 setFromPoints( Listpoints ) } public Box2 setFromCenterAndSize( Vector2 center, Vector2 size ) - { - Vector2 v1 = new Vector2(); - - Vector2 halfSize = v1.copy( size ).multiply( 0.5 ); + { + Vector2 halfSize = _v1.copy( size ).multiply( 0.5 ); this.min.copy( center ).sub( halfSize ); this.max.copy( center ).add( halfSize ); diff --git a/src/thothbot/parallax/core/shared/math/Box3.java b/src/thothbot/parallax/core/shared/math/Box3.java index 01744429..55f61b54 100644 --- a/src/thothbot/parallax/core/shared/math/Box3.java +++ b/src/thothbot/parallax/core/shared/math/Box3.java @@ -32,6 +32,9 @@ public class Box3 { private Vector3 min; private Vector3 max; + + // Temporary variables + static Vector3 _v1 = new Vector3(); public Box3() { @@ -87,10 +90,8 @@ public Box3 setFromPoints( Vector3[] points ) } public Box3 setFromCenterAndSize( Vector3 center, Vector3 size ) - { - Vector3 v1 = new Vector3(); - - Vector3 halfSize = v1.copy( size ).multiply( 0.5 ); + { + Vector3 halfSize = _v1.copy( size ).multiply( 0.5 ); this.min.copy( center ).sub( halfSize ); this.max.copy( center ).add( halfSize ); @@ -99,7 +100,8 @@ public Box3 setFromCenterAndSize( Vector3 center, Vector3 size ) } - public Box3 setFromObject(Object3D object) { + public Box3 setFromObject(Object3D object) + { // Computes the world-axis-aligned bounding box of an object (including its children), // accounting for both the object's, and childrens', world transforms @@ -289,8 +291,7 @@ public Vector3 clampPoint( Vector3 point, Vector3 optionalTarget ) public double distanceToPoint( Vector3 point ) { - Vector3 v1 = new Vector3(); - Vector3 clampedPoint = v1.copy( point ).clamp( this.min, this.max ); + Vector3 clampedPoint = _v1.copy( point ).clamp( this.min, this.max ); return clampedPoint.sub( point ).length(); } @@ -301,13 +302,10 @@ public Sphere getBoundingSphere() public Sphere getBoundingSphere( Sphere optionalTarget ) { - Vector3 v1 = new Vector3(); - optionalTarget.setCenter( this.center() ); - optionalTarget.setRadius( this.size( v1 ).length() * 0.5 ); + optionalTarget.setRadius( this.size( _v1 ).length() * 0.5 ); return optionalTarget; - } public Box3 intersect( Box3 box ) diff --git a/src/thothbot/parallax/core/shared/math/Euler.java b/src/thothbot/parallax/core/shared/math/Euler.java index 3ebedc71..f4401225 100644 --- a/src/thothbot/parallax/core/shared/math/Euler.java +++ b/src/thothbot/parallax/core/shared/math/Euler.java @@ -50,26 +50,34 @@ public static interface EulerChangeHandler private EulerChangeHandler handler; - public Euler() { + // Temporary variables + static Quaternion _q = new Quaternion(); + + public Euler() + { this(0.0,0.0,0.0); } - public Euler (double x, double y, double z) { + public Euler (double x, double y, double z) + { this(x, y, z, DefaultOrder); } - public Euler (double x, double y, double z, String order) { + public Euler (double x, double y, double z, String order) + { this.x = x; this.y = y; this.z = z; this.order = order; } - public void setHandler(EulerChangeHandler handler) { + public void setHandler(EulerChangeHandler handler) + { this.handler = handler; } - private void onChange() { + private void onChange() + { if(this.handler != null) this.handler.onChange(Euler.this); } @@ -125,7 +133,8 @@ public double getY() { return this.y; } - public void setY ( double value ) { + public void setY ( double value ) + { this.y = value; this.onChange(); @@ -135,27 +144,32 @@ public double getZ() { return this.z; } - public void setZ ( double value ) { + public void setZ ( double value ) + { this.z = value; this.onChange(); } - public String getOrder () { + public String getOrder () + { return this.order; } - public void setOrder ( String value ) { + public void setOrder ( String value ) + { this.order = value; this.onChange(); } - public Euler set( double x, double y, double z) { + public Euler set( double x, double y, double z) + { return set(x, y, z, DefaultOrder); } - public Euler set( double x, double y, double z, String order ) { + public Euler set( double x, double y, double z, String order ) + { this.x = x; this.y = y; this.z = z; @@ -166,7 +180,8 @@ public Euler set( double x, double y, double z, String order ) { return this; } - public Euler copy ( Euler euler ) { + public Euler copy ( Euler euler ) + { this.x = euler.x; this.y = euler.y; @@ -178,11 +193,13 @@ public Euler copy ( Euler euler ) { return this; } - public Euler setFromRotationMatrix( Matrix4 m ) { + public Euler setFromRotationMatrix( Matrix4 m ) + { return setFromRotationMatrix(m, this.order); } - public Euler setFromRotationMatrix( Matrix4 m, String order ) { + public Euler setFromRotationMatrix( Matrix4 m, String order ) + { // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) @@ -370,38 +387,20 @@ public Euler setFromQuaternion ( Quaternion q, String order, boolean update ) { return this; } - public Euler reorder(String newOrder) { + public Euler reorder(String newOrder) + { // WARNING: this discards revolution information -bhouston - Quaternion q = new Quaternion(); - q.setFromEuler( this ); - return this.setFromQuaternion( q, newOrder ); + _q.setFromEuler( this ); + return this.setFromQuaternion( _q, newOrder ); } - public boolean equals( Euler euler ) { - + public boolean equals( Euler euler ) + { return ( euler.x == this.x ) && ( euler.y == this.y ) && ( euler.z == this.z ) && ( euler.order.equals(this.order) ); - } -// public Euler fromArray ( Object[] array ) { -// -// this.x = array[ 0 ]; -// this.y = array[ 1 ]; -// this.z = array[ 2 ]; -// if ( array[ 3 ] !== undefined ) this.order = array[ 3 ]; -// -// return this; -// } -// -// toArray: function () { -// -// return [ this.x, this.y, this.z, this.order ]; -// -// }, - - public Euler clone() { return new Euler( this.x, this.y, this.z, this.order ); diff --git a/src/thothbot/parallax/core/shared/math/Frustum.java b/src/thothbot/parallax/core/shared/math/Frustum.java index 776f85a4..8efdd524 100644 --- a/src/thothbot/parallax/core/shared/math/Frustum.java +++ b/src/thothbot/parallax/core/shared/math/Frustum.java @@ -38,6 +38,11 @@ public class Frustum * Panes of the Frustum of a rectangular pyramid */ private List planes; + + // Temporary variables + static Sphere _sphere = new Sphere(); + static Vector3 _p1 = new Vector3(); + static Vector3 _p2 = new Vector3(); /** * Default constructor will make Frustum of a rectangular pyramid @@ -104,18 +109,16 @@ public Frustum setFromMatrix( Matrix4 m ) } public boolean isIntersectsObject( GeometryObject object ) - { - Sphere sphere = new Sphere(); - + { AbstractGeometry geometry = object.getGeometry(); if ( geometry.getBoundingSphere() == null ) geometry.computeBoundingSphere(); - sphere.copy( geometry.getBoundingSphere() ); - sphere.apply( object.getMatrixWorld() ); + _sphere.copy( geometry.getBoundingSphere() ); + _sphere.apply( object.getMatrixWorld() ); - return this.isIntersectsSphere( sphere ); + return this.isIntersectsSphere( _sphere ); } public boolean isIntersectsSphere( Sphere sphere ) @@ -136,24 +139,22 @@ public boolean isIntersectsSphere( Sphere sphere ) return true; } - public boolean isIntersectsBox(Box3 box) { - - Vector3 p1 = new Vector3(), - p2 = new Vector3(); + public boolean isIntersectsBox(Box3 box) + { for ( int i = 0; i < 6 ; i ++ ) { Plane plane = planes.get( i ); - p1.x = plane.getNormal().x > 0 ? box.getMin().x : box.getMax().x; - p2.x = plane.getNormal().x > 0 ? box.getMax().x : box.getMin().x; - p1.y = plane.getNormal().y > 0 ? box.getMin().y : box.getMax().y; - p2.y = plane.getNormal().y > 0 ? box.getMax().y : box.getMin().y; - p1.z = plane.getNormal().z > 0 ? box.getMin().z : box.getMax().z; - p2.z = plane.getNormal().z > 0 ? box.getMax().z : box.getMin().z; + _p1.x = plane.getNormal().x > 0 ? box.getMin().x : box.getMax().x; + _p2.x = plane.getNormal().x > 0 ? box.getMax().x : box.getMin().x; + _p1.y = plane.getNormal().y > 0 ? box.getMin().y : box.getMax().y; + _p2.y = plane.getNormal().y > 0 ? box.getMax().y : box.getMin().y; + _p1.z = plane.getNormal().z > 0 ? box.getMin().z : box.getMax().z; + _p2.z = plane.getNormal().z > 0 ? box.getMax().z : box.getMin().z; - double d1 = plane.distanceToPoint( p1 ); - double d2 = plane.distanceToPoint( p2 ); + double d1 = plane.distanceToPoint( _p1 ); + double d2 = plane.distanceToPoint( _p2 ); // if both outside plane, no intersection diff --git a/src/thothbot/parallax/core/shared/math/Line3.java b/src/thothbot/parallax/core/shared/math/Line3.java index cedcb29f..1d5fb181 100644 --- a/src/thothbot/parallax/core/shared/math/Line3.java +++ b/src/thothbot/parallax/core/shared/math/Line3.java @@ -23,6 +23,10 @@ public class Line3 private Vector3 start; private Vector3 end; + + //Temporary variables + static Vector3 _startP = new Vector3(); + static Vector3 _startEnd = new Vector3(); public Line3() { @@ -114,14 +118,11 @@ public double closestPointToPointParameter( Vector3 point ) public double closestPointToPointParameter( Vector3 point, boolean clampToLine ) { - Vector3 startP = new Vector3(); - Vector3 startEnd = new Vector3(); - - startP.sub( point, this.start ); - startEnd.sub( this.end, this.start ); + _startP.sub( point, this.start ); + _startEnd.sub( this.end, this.start ); - double startEnd2 = startEnd.dot( startEnd ); - double startEnd_startP = startEnd.dot( startP ); + double startEnd2 = _startEnd.dot( _startEnd ); + double startEnd_startP = _startEnd.dot( _startP ); double t = startEnd_startP / startEnd2; diff --git a/src/thothbot/parallax/core/shared/math/Matrix3.java b/src/thothbot/parallax/core/shared/math/Matrix3.java index 0ab9f417..865ab746 100644 --- a/src/thothbot/parallax/core/shared/math/Matrix3.java +++ b/src/thothbot/parallax/core/shared/math/Matrix3.java @@ -39,6 +39,9 @@ public class Matrix3 { private Float32Array elements; + + // Temporary variables + static Vector3 _v1 = new Vector3(); /** * Default constructor will make empty three-dimensional matrix. @@ -107,25 +110,25 @@ public Matrix3 copy( Matrix3 m ) return this; } - public Float32Array applyToVector3Array (Float32Array array) { + public Float32Array applyToVector3Array (Float32Array array) + { return applyToVector3Array(array, 0, array.getLength()); } - public Float32Array applyToVector3Array (Float32Array array, int offset, int length) { - - Vector3 v1 = new Vector3(); + public Float32Array applyToVector3Array (Float32Array array, int offset, int length) + { for ( int i = 0, j = offset, il; i < length; i += 3, j += 3 ) { - v1.x = array.get( j ); - v1.y = array.get( j + 1 ); - v1.z = array.get( j + 2 ); + _v1.x = array.get( j ); + _v1.y = array.get( j + 1 ); + _v1.z = array.get( j + 2 ); - v1.apply( this ); + _v1.apply( this ); - array.set( j , v1.x ); - array.set( j + 1 , v1.y ); - array.set( j + 2 , v1.z ); + array.set( j , _v1.x ); + array.set( j + 1 , _v1.y ); + array.set( j + 2 , _v1.z ); } diff --git a/src/thothbot/parallax/core/shared/math/Matrix4.java b/src/thothbot/parallax/core/shared/math/Matrix4.java index 4494d15a..d7c738db 100644 --- a/src/thothbot/parallax/core/shared/math/Matrix4.java +++ b/src/thothbot/parallax/core/shared/math/Matrix4.java @@ -40,6 +40,14 @@ public class Matrix4 { private Float32Array elements; + + // Temporary variables + static Vector3 _x = new Vector3(); + static Vector3 _y = new Vector3(); + static Vector3 _z = new Vector3(); + static Vector3 _v1 = new Vector3(); + static Vector3 _vector = new Vector3(); + static Matrix4 _matrix = new Matrix4(); /** * Default constructor will make identity four-dimensional matrix. @@ -396,35 +404,31 @@ public Matrix4 makeRotationFromQuaternion( Quaternion q ) { */ public Matrix4 lookAt(Vector3 eye, Vector3 target, Vector3 up) { - Vector3 x = new Vector3(); - Vector3 y = new Vector3(); - Vector3 z = new Vector3(); - Float32Array te = this.elements; - z.sub( eye, target ).normalize(); + _z.sub( eye, target ).normalize(); - if ( z.length() == 0 ) { + if ( _z.length() == 0 ) { - z.z = 1.0; + _z.z = 1.0; } - x.cross( up, z ).normalize(); + _x.cross( up, _z ).normalize(); - if ( x.length() == 0 ) { + if ( _x.length() == 0 ) { - z.x += 0.0001; - x.cross( up, z ).normalize(); + _z.x += 0.0001; + _x.cross( up, _z ).normalize(); } - y.cross( z, x ); + _y.cross( _z, _x ); - te.set(0, x.getX()); te.set(4, y.getX()); te.set(8, z.getX()); - te.set(1, x.getY()); te.set(5, y.getY()); te.set(9, z.getY()); - te.set(2, x.getZ()); te.set(6, y.getZ()); te.set(10, z.getZ()); + te.set(0, _x.getX()); te.set(4, _y.getX()); te.set(8, _z.getX()); + te.set(1, _x.getY()); te.set(5, _y.getY()); te.set(9, _z.getY()); + te.set(2, _x.getZ()); te.set(6, _y.getZ()); te.set(10, _z.getZ()); return this; @@ -521,25 +525,24 @@ public Matrix4 multiply(double s) return this; } - public Float32Array applyToVector3Array (Float32Array array) { + public Float32Array applyToVector3Array (Float32Array array) + { return applyToVector3Array(array, 0, array.getLength()); } - public Float32Array applyToVector3Array (Float32Array array, int offset, int length) { - - Vector3 v1 = new Vector3(); - + public Float32Array applyToVector3Array (Float32Array array, int offset, int length) + { for ( int i = 0, j = offset, il; i < length; i += 3, j += 3 ) { - v1.x = array.get( j ); - v1.y = array.get( j + 1 ); - v1.z = array.get( j + 2 ); + _v1.x = array.get( j ); + _v1.y = array.get( j + 1 ); + _v1.z = array.get( j + 2 ); - v1.apply( this ); + _v1.apply( this ); - array.set( j , v1.x); - array.set( j + 1 , v1.y); - array.set( j + 2 , v1.z); + array.set( j , _v1.x); + array.set( j + 1 , _v1.y); + array.set( j + 2 , _v1.z); } @@ -928,14 +931,11 @@ public Matrix4 compose(Vector3 position, Quaternion quaternion, Vector3 scale) public Matrix4 decompose(Vector3 position, Quaternion quaternion, Vector3 scale) { - Vector3 vector = new Vector3(); - Matrix4 matrix = new Matrix4(); - Float32Array te = this.elements; - double sx = vector.set( te.get( 0 ), te.get( 1 ), te.get( 2 ) ).length(); - double sy = vector.set( te.get( 4 ), te.get( 5 ), te.get( 6 ) ).length(); - double sz = vector.set( te.get( 8 ), te.get( 9 ), te.get( 10 ) ).length(); + double sx = _vector.set( te.get( 0 ), te.get( 1 ), te.get( 2 ) ).length(); + double sy = _vector.set( te.get( 4 ), te.get( 5 ), te.get( 6 ) ).length(); + double sz = _vector.set( te.get( 8 ), te.get( 9 ), te.get( 10 ) ).length(); // if determine is negative, we need to invert one scale double det = this.determinant(); @@ -949,25 +949,25 @@ public Matrix4 decompose(Vector3 position, Quaternion quaternion, Vector3 scale) // scale the rotation part - matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy() + _matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy() double invSX = 1.0 / sx; double invSY = 1.0 / sy; double invSZ = 1.0 / sz; - matrix.elements.set( 0, matrix.elements.get( 0 ) * invSX ); - matrix.elements.set( 1, matrix.elements.get( 1 ) * invSX ); - matrix.elements.set( 2, matrix.elements.get( 2 ) * invSX ); + _matrix.elements.set( 0, _matrix.elements.get( 0 ) * invSX ); + _matrix.elements.set( 1, _matrix.elements.get( 1 ) * invSX ); + _matrix.elements.set( 2, _matrix.elements.get( 2 ) * invSX ); - matrix.elements.set( 4, matrix.elements.get( 4 ) * invSY ); - matrix.elements.set( 5, matrix.elements.get( 5 ) * invSY ); - matrix.elements.set( 6, matrix.elements.get( 6 ) * invSY ); + _matrix.elements.set( 4, _matrix.elements.get( 4 ) * invSY ); + _matrix.elements.set( 5, _matrix.elements.get( 5 ) * invSY ); + _matrix.elements.set( 6, _matrix.elements.get( 6 ) * invSY ); - matrix.elements.set( 8, matrix.elements.get( 8 ) * invSZ ); - matrix.elements.set( 9, matrix.elements.get( 9 ) * invSZ ); - matrix.elements.set( 10, matrix.elements.get( 10 ) * invSZ ); + _matrix.elements.set( 8, _matrix.elements.get( 8 ) * invSZ ); + _matrix.elements.set( 9, _matrix.elements.get( 9 ) * invSZ ); + _matrix.elements.set( 10, _matrix.elements.get( 10 ) * invSZ ); - quaternion.setFromRotationMatrix( matrix ); + quaternion.setFromRotationMatrix( _matrix ); scale.x = sx; scale.y = sy; diff --git a/src/thothbot/parallax/core/shared/math/Plane.java b/src/thothbot/parallax/core/shared/math/Plane.java index 6457dd53..f493d0f4 100644 --- a/src/thothbot/parallax/core/shared/math/Plane.java +++ b/src/thothbot/parallax/core/shared/math/Plane.java @@ -23,6 +23,11 @@ public class Plane private Vector3 normal; private double constant; + // Temporary variables + static Vector3 _v1 = new Vector3(); + static Vector3 _v2 = new Vector3(); + static Matrix3 _m1 = new Matrix3(); + public Plane() { this(new Vector3(1, 0, 0), 0); @@ -76,10 +81,7 @@ public Plane setFromNormalAndCoplanarPoint(Vector3 normal, Vector3 point ) public Plane setFromCoplanarPoints( Vector3 a, Vector3 b, Vector3 c ) { - Vector3 v1 = new Vector3(); - Vector3 v2 = new Vector3(); - - Vector3 normal = v1.sub( c, b ).cross( v2.sub( a, b ) ).normalize(); + Vector3 normal = _v1.sub( c, b ).cross( _v2.sub( a, b ) ).normalize(); // Q: should an error be thrown if normal is zero (e.g. degenerate plane)? @@ -162,10 +164,7 @@ public Vector3 intersectLine( Line3 line ) public Vector3 intersectLine( Line3 line, Vector3 optionalTarget ) { - - Vector3 v1 = new Vector3(); - - Vector3 direction = line.delta( v1 ); + Vector3 direction = line.delta( _v1 ); double denominator = this.normal.dot( direction ); @@ -206,22 +205,17 @@ public Vector3 coplanarPoint( Vector3 optionalTarget ) } public Plane apply( Matrix4 matrix ) - { - Matrix3 m1 = new Matrix3(); - - return apply(matrix, m1.getNormalMatrix( matrix )); + { + return apply(matrix, _m1.getNormalMatrix( matrix )); } public Plane apply( Matrix4 matrix, Matrix3 normalMatrix ) { - Vector3 v1 = new Vector3(); - Vector3 v2 = new Vector3(); - // compute new normal based on theory here: // http://www.songho.ca/opengl/gl_normaltransform.html - Vector3 newNormal = v1.copy( this.normal ).apply( normalMatrix ); + Vector3 newNormal = _v1.copy( this.normal ).apply( normalMatrix ); - Vector3 newCoplanarPoint = this.coplanarPoint( v2 ); + Vector3 newCoplanarPoint = this.coplanarPoint( _v2 ); newCoplanarPoint.apply( matrix ); this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint ); diff --git a/src/thothbot/parallax/core/shared/math/Quaternion.java b/src/thothbot/parallax/core/shared/math/Quaternion.java index f4daf470..ec95a0e2 100644 --- a/src/thothbot/parallax/core/shared/math/Quaternion.java +++ b/src/thothbot/parallax/core/shared/math/Quaternion.java @@ -66,6 +66,9 @@ public static interface QuaternionChangeHandler public double w; private QuaternionChangeHandler handler; + + // Temporary variables + static Vector3 _v1 = new Vector3(); /** * Default constructor will make Quaternion (0.0, 0.0, 0.0, 1.0) @@ -113,11 +116,13 @@ public Quaternion(double x, double y, double z) this.z = z; } - public void setHandler(QuaternionChangeHandler handler) { + public void setHandler(QuaternionChangeHandler handler) + { this.handler = handler; } - private void onChange() { + private void onChange() + { if(this.handler != null) this.handler.onChange(Quaternion.this); } @@ -196,7 +201,8 @@ public Quaternion setFromEuler( Euler euler ) return setFromEuler(euler, false); } - public Quaternion setFromEuler( Euler euler, boolean update ) { + public Quaternion setFromEuler( Euler euler, boolean update ) + { // http://www.mathworks.com/matlabcentral/fileexchange/ // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/ @@ -279,11 +285,15 @@ public Quaternion setFromAxisAngle(Vector3 axis, double angle) return this; } - public Quaternion setFromRotationMatrix( Matrix4 m ) { - - // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm - - // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) + /** + * http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm + * assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) + * + * @param m + * @return + */ + public Quaternion setFromRotationMatrix( Matrix4 m ) + { Float32Array te = m.getArray(); @@ -338,19 +348,16 @@ public Quaternion setFromRotationMatrix( Matrix4 m ) { } -// public void calculateW() -// { -// this.w = -Math.sqrt(Math.abs(1.0 - this.x * this.x - this.y * this.y - this.z * this.z)); -// } - - public Quaternion setFromUnitVectors(Vector3 vFrom, Vector3 vTo ) { - - // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final - - // assumes direction vectors vFrom and vTo are normalized - - Vector3 v1 = new Vector3(); - + /** + * http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final + * assumes direction vectors vFrom and vTo are normalized + * + * @param vFrom + * @param vTo + * @return + */ + public Quaternion setFromUnitVectors(Vector3 vFrom, Vector3 vTo ) + { double EPS = 0.000001; double r = vFrom.dot( vTo ) + 1; @@ -361,23 +368,23 @@ public Quaternion setFromUnitVectors(Vector3 vFrom, Vector3 vTo ) { if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) { - v1.set( - vFrom.y, vFrom.x, 0 ); + _v1.set( - vFrom.y, vFrom.x, 0 ); } else { - v1.set( 0, - vFrom.z, vFrom.y ); + _v1.set( 0, - vFrom.z, vFrom.y ); } } else { - v1.cross( vFrom, vTo ); + _v1.cross( vFrom, vTo ); } - this.x = v1.x; - this.y = v1.y; - this.z = v1.z; + this.x = _v1.x; + this.y = _v1.y; + this.z = _v1.z; this.w = r; this.normalize(); @@ -408,10 +415,9 @@ public Quaternion conjugate() return this; } - public double dot( Quaternion v ) { - + public double dot( Quaternion v ) + { return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w; - } public double lengthSq() @@ -579,10 +585,9 @@ public Quaternion slerp(Quaternion qb, double t) return this; } - public static Quaternion slerp(Quaternion qa, Quaternion qb, Quaternion qm, double t ) { - + public static Quaternion slerp(Quaternion qa, Quaternion qb, Quaternion qm, double t ) + { return qm.copy( qa ).slerp( qb, t ); - } public boolean equals( Quaternion quaternion ) diff --git a/src/thothbot/parallax/core/shared/math/Ray.java b/src/thothbot/parallax/core/shared/math/Ray.java index 35fa29bd..bbe29bc5 100644 --- a/src/thothbot/parallax/core/shared/math/Ray.java +++ b/src/thothbot/parallax/core/shared/math/Ray.java @@ -37,6 +37,14 @@ public class Ray // A vector pointing in the direction the ray goes. Default is 0, 0, 0. private Vector3 direction; + //Temporary variables + static Vector3 _v1 = new Vector3(); + static Vector3 _v2 = new Vector3(); + static Vector3 _diff = new Vector3(); + static Vector3 _edge1 = new Vector3(); + static Vector3 _edge2 = new Vector3(); + static Vector3 _normal = new Vector3(); + public Ray() { this(new Vector3(), new Vector3()); @@ -92,8 +100,7 @@ public Vector3 at( double t, Vector3 optionalTarget ) public Ray recast( double t ) { - Vector3 v1 = new Vector3(); - this.origin.copy( this.at( t, v1 ) ); + this.origin.copy( this.at( t, _v1 ) ); return this; } @@ -118,11 +125,8 @@ public Vector3 closestPointToPoint( Vector3 point, Vector3 optionalTarget ) } public double distanceToPoint( Vector3 point ) - { - - Vector3 v1 = new Vector3(); - - double directionDistance = v1.sub( point, this.origin ).dot( this.direction ); + { + double directionDistance = _v1.sub( point, this.origin ).dot( this.direction ); // point behind the ray @@ -132,14 +136,14 @@ public double distanceToPoint( Vector3 point ) } - v1.copy( this.direction ).multiply( directionDistance ).add( this.origin ); + _v1.copy( this.direction ).multiply( directionDistance ).add( this.origin ); - return v1.distanceTo( point ); + return _v1.distanceTo( point ); } - public double distanceSqToSegment( Vector3 v0, Vector3 v1, Vector3 optionalPointOnRay, Vector3 optionalPointOnSegment ) { - + public double distanceSqToSegment( Vector3 v0, Vector3 v1, Vector3 optionalPointOnRay, Vector3 optionalPointOnSegment ) + { // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp // It returns the min distance between the ray and the segment // defined by v0 and v1 @@ -261,7 +265,8 @@ public boolean isIntersectionSphere( Sphere sphere ) return ( this.distanceToPoint( sphere.getCenter() ) <= sphere.getRadius() ); } - public Vector3 intersectSphere( Sphere sphere ) { + public Vector3 intersectSphere( Sphere sphere ) + { return intersectSphere(sphere, null); } @@ -271,7 +276,6 @@ public Vector3 intersectSphere( Sphere sphere ) { * @param optionalTarget * @return */ - static Vector3 _v1 = new Vector3(); public Vector3 intersectSphere( Sphere sphere, Vector3 optionalTarget ) { _v1.sub( sphere.getCenter(), this.getOrigin() ); @@ -373,7 +377,6 @@ public Vector3 intersectPlane( Plane plane, Vector3 optionalTarget ) return this.at( t, optionalTarget ); } - static Vector3 _v2 = new Vector3(); public boolean isIntersectionBox(Box3 box) { return this.intersectBox( box, _v2 ) != null; @@ -462,10 +465,6 @@ public Vector3 intersectTriangle(Vector3 a, Vector3 b, Vector3 c, boolean backfa * @param optionalTarget * @return */ - static Vector3 _diff = new Vector3(); - static Vector3 _edge1 = new Vector3(); - static Vector3 _edge2 = new Vector3(); - static Vector3 _normal = new Vector3(); public Vector3 intersectTriangle(Vector3 a, Vector3 b, Vector3 c, boolean backfaceCulling, Vector3 optionalTarget) { // Compute the offset origin, edges, and normal. diff --git a/src/thothbot/parallax/core/shared/math/Sphere.java b/src/thothbot/parallax/core/shared/math/Sphere.java index bc8c6a8d..ef30db87 100644 --- a/src/thothbot/parallax/core/shared/math/Sphere.java +++ b/src/thothbot/parallax/core/shared/math/Sphere.java @@ -26,6 +26,9 @@ public class Sphere private Vector3 center; private double radius; + // Temporary variables + static Box3 _box = new Box3(); + public Sphere() { this(new Vector3(), 0); @@ -71,7 +74,6 @@ public Sphere setFromPoints(List points, Vector3 optionalCenter) return setFromPoints(points.toArray(new Vector3[points.size()]), optionalCenter); } - static Box3 _box = new Box3(); public Sphere setFromPoints(Vector3[] points, Vector3 optionalCenter) { if ( optionalCenter != null ) diff --git a/src/thothbot/parallax/core/shared/math/Triangle.java b/src/thothbot/parallax/core/shared/math/Triangle.java index 528ca57a..87241fa8 100644 --- a/src/thothbot/parallax/core/shared/math/Triangle.java +++ b/src/thothbot/parallax/core/shared/math/Triangle.java @@ -26,6 +26,11 @@ public class Triangle private Vector3 b; private Vector3 c; + // Temporary variables + static Vector3 _v0 = new Vector3(); + static Vector3 _v1 = new Vector3(); + static Vector3 _v2 = new Vector3(); + public Triangle() { this(new Vector3(), new Vector3(), new Vector3()); @@ -69,12 +74,10 @@ public static Vector3 normal( Vector3 a, Vector3 b, Vector3 c) } public static Vector3 normal( Vector3 a, Vector3 b, Vector3 c, Vector3 optionalTarget ) - { - Vector3 v0 = new Vector3(); - + { optionalTarget.sub( c, b ); - v0.sub( a, b ); - optionalTarget.cross( v0 ); + _v0.sub( a, b ); + optionalTarget.cross( _v0 ); double resultLengthSq = optionalTarget.lengthSq(); if ( resultLengthSq > 0 ) { @@ -98,20 +101,15 @@ public static Vector3 barycoordFromPoint( Vector3 point, Vector3 a, Vector3 b, V public static Vector3 barycoordFromPoint( Vector3 point, Vector3 a, Vector3 b, Vector3 c, Vector3 optionalTarget ) { + _v0.sub( c, a ); + _v1.sub( b, a ); + _v2.sub( point, a ); - Vector3 v0 = new Vector3(); - Vector3 v1 = new Vector3(); - Vector3 v2 = new Vector3(); - - v0.sub( c, a ); - v1.sub( b, a ); - v2.sub( point, a ); - - double dot00 = v0.dot( v0 ); - double dot01 = v0.dot( v1 ); - double dot02 = v0.dot( v2 ); - double dot11 = v1.dot( v1 ); - double dot12 = v1.dot( v2 ); + double dot00 = _v0.dot( _v0 ); + double dot01 = _v0.dot( _v1 ); + double dot02 = _v0.dot( _v2 ); + double dot11 = _v1.dot( _v1 ); + double dot12 = _v1.dot( _v2 ); double denom = ( dot00 * dot11 - dot01 * dot01 ); @@ -132,10 +130,8 @@ public static Vector3 barycoordFromPoint( Vector3 point, Vector3 a, Vector3 b, V } public static boolean containsPoint( Vector3 point, Vector3 a, Vector3 b, Vector3 c ) - { - Vector3 v1 = new Vector3(); - - Vector3 result = Triangle.barycoordFromPoint( point, a, b, c, v1 ); + { + Vector3 result = Triangle.barycoordFromPoint( point, a, b, c, _v1 ); return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 ); } @@ -169,13 +165,10 @@ public Triangle copy( Triangle triangle ) public double area() { - Vector3 v0 = new Vector3(); - Vector3 v1 = new Vector3(); - - v0.sub( this.c, this.b ); - v1.sub( this.a, this.b ); + _v0.sub( this.c, this.b ); + _v1.sub( this.a, this.b ); - return v0.cross( v1 ).length() * 0.5; + return _v0.cross( _v1 ).length() * 0.5; } public Vector3 midpoint() diff --git a/src/thothbot/parallax/core/shared/math/Vector2.java b/src/thothbot/parallax/core/shared/math/Vector2.java index fce0d653..99866b92 100644 --- a/src/thothbot/parallax/core/shared/math/Vector2.java +++ b/src/thothbot/parallax/core/shared/math/Vector2.java @@ -39,6 +39,10 @@ public class Vector2 * The Y-coordinate */ protected double y; + + // Temporary variables + static Vector2 _min = new Vector2(); + static Vector2 _max = new Vector2(); /** * This default constructor will initialize vector (0, 0); @@ -315,9 +319,6 @@ else if ( this.y > max.y ) return this; } - static Vector2 _min = new Vector2(); - static Vector2 _max = new Vector2(); - public Vector2 clamp(double minVal, double maxVal) { _min.set( minVal, minVal ); diff --git a/src/thothbot/parallax/core/shared/math/Vector3.java b/src/thothbot/parallax/core/shared/math/Vector3.java index 76e1b56b..30f912cb 100644 --- a/src/thothbot/parallax/core/shared/math/Vector3.java +++ b/src/thothbot/parallax/core/shared/math/Vector3.java @@ -37,7 +37,14 @@ public class Vector3 extends Vector2 * The Z-coordinate */ protected double z; - + + // Temporary variables + static Quaternion _quaternion = new Quaternion(); + static Matrix4 _matrix = new Matrix4(); + static Vector3 _min = new Vector3(); + static Vector3 _max = new Vector3(); + static Vector3 _v1 = new Vector3(); + /** * This default constructor will initialize vector (0, 0, 0); */ @@ -219,7 +226,6 @@ public Vector3 multiply(double s) return this; } - static Quaternion _quaternion = new Quaternion(); public Vector3 applyEuler( Euler euler) { this.apply( _quaternion.setFromEuler( euler ) ); @@ -314,7 +320,6 @@ public Vector3 apply( Quaternion q ) } - static Matrix4 _matrix = new Matrix4(); public Vector3 project(Camera camera) { _matrix.multiply( camera.getProjectionMatrix(), _matrix.getInverse( camera.getMatrixWorld() ) ); @@ -465,8 +470,6 @@ public Vector3 clamp( Vector3 min, Vector3 max ) return this; } - static Vector3 _min = new Vector3(); - static Vector3 _max = new Vector3(); public Vector3 clamp(double minVal, double maxVal) { _min.set( minVal, minVal, minVal ); @@ -644,7 +647,6 @@ public Vector3 projectOnPlane(Vector3 planeNormal) * @param normal * @return */ - static Vector3 _v1 = new Vector3(); public Vector3 reflect(Vector3 normal) { return this.sub( _v1.copy( normal ).multiply( 2 * this.dot( normal ) ) ); diff --git a/src/thothbot/parallax/core/shared/math/Vector4.java b/src/thothbot/parallax/core/shared/math/Vector4.java index 933fcb74..16c43c6c 100644 --- a/src/thothbot/parallax/core/shared/math/Vector4.java +++ b/src/thothbot/parallax/core/shared/math/Vector4.java @@ -37,6 +37,10 @@ public class Vector4 extends Vector3 */ protected double w; + // Temporary variables + static Vector4 _min = new Vector4(); + static Vector4 _max = new Vector4(); + /** * This default constructor will initialize vector (0, 0, 0, 1); */ @@ -582,8 +586,6 @@ else if ( this.w > max.w ) return this; } - static Vector4 _min = new Vector4(); - static Vector4 _max = new Vector4(); public Vector4 clamp( double minVal, double maxVal ) { _min.set( minVal, minVal, minVal, minVal ); diff --git a/src/thothbot/parallax/core/shared/objects/Mesh.java b/src/thothbot/parallax/core/shared/objects/Mesh.java index 2d899892..4aec0ebe 100644 --- a/src/thothbot/parallax/core/shared/objects/Mesh.java +++ b/src/thothbot/parallax/core/shared/objects/Mesh.java @@ -85,6 +85,15 @@ public class Mesh extends GeometryObject defaultMaterial.setWireframe( true ); }; + // Temporary variables + static Matrix4 _inverseMatrix = new Matrix4(); + static Ray _ray = new Ray(); + static Sphere _sphere = new Sphere(); + + static Vector3 _vA = new Vector3(); + static Vector3 _vB = new Vector3(); + static Vector3 _vC = new Vector3(); + public Mesh() { this(new Geometry()); } @@ -126,15 +135,6 @@ public void updateMorphTargets() { } - - Matrix4 _inverseMatrix = new Matrix4(); - Ray _ray = new Ray(); - Sphere _sphere = new Sphere(); - - Vector3 _vA = new Vector3(); - Vector3 _vB = new Vector3(); - Vector3 _vC = new Vector3(); - public void raycast( Raycaster raycaster, List intersects) { // Checking boundingSphere distance to ray From da3893ae003155f0b871763bcd818ff489507559 Mon Sep 17 00:00:00 2001 From: thothbot Date: Sun, 29 Mar 2015 13:13:03 +0300 Subject: [PATCH 69/75] Fixed issue in modules hierarchy --- src/thothbot/parallax/core/client/renderers/Plugin.java | 4 ++++ .../parallax/core/client/renderers/WebGLRenderer.java | 3 +-- .../parallax/plugins/postprocessing/Postprocessing.java | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/thothbot/parallax/core/client/renderers/Plugin.java b/src/thothbot/parallax/core/client/renderers/Plugin.java index 17ad2a39..b00fa011 100644 --- a/src/thothbot/parallax/core/client/renderers/Plugin.java +++ b/src/thothbot/parallax/core/client/renderers/Plugin.java @@ -53,6 +53,10 @@ public Scene getScene() { return this.scene; } + public boolean isMulty() { + return false; + } + public boolean isEnabled() { return isEnabled; } diff --git a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java index b29d4b47..5267fa3f 100644 --- a/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java +++ b/src/thothbot/parallax/core/client/renderers/WebGLRenderer.java @@ -115,7 +115,6 @@ import thothbot.parallax.core.shared.scenes.AbstractFog; import thothbot.parallax.core.shared.scenes.FogExp2; import thothbot.parallax.core.shared.scenes.Scene; -import thothbot.parallax.plugins.postprocessing.Postprocessing; import com.google.gwt.canvas.dom.client.Context2d; import com.google.gwt.core.client.GWT; @@ -1956,7 +1955,7 @@ private boolean renderPlugins( List plugins, Scene scene, Camera camera, if( ! plugin.isEnabled() || plugin.isRendering() || plugin.getType() != type - || ( !(plugin instanceof Postprocessing) && !plugin.getScene().equals(scene))) + || ( !(plugin.isMulty()) && !plugin.getScene().equals(scene))) continue; plugin.setRendering(true); diff --git a/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java b/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java index cd46023d..be88fca1 100644 --- a/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java +++ b/src/thothbot/parallax/plugins/postprocessing/Postprocessing.java @@ -97,6 +97,11 @@ public void onResize(ViewportResizeEvent event) { getScene().add( camera ); } + @Override + public boolean isMulty() { + return true; + } + public Plugin.TYPE getType() { return Plugin.TYPE.POST_RENDER; } From 095c90101f7bf629dcebe4f369417d79b2e8d68e Mon Sep 17 00:00:00 2001 From: thothbot Date: Sun, 29 Mar 2015 13:14:33 +0300 Subject: [PATCH 70/75] Updated version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 46817fac..222a04b5 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The aim of the project is to use GWT which helps maintaining complex pieces of c Parallax supports WebGL-canvas renderer only. -### Download - new Parallax v1.5 ### +### Download - new Parallax v1.6 ### [Download JAR](http://github.com/thothbot/parallax/wiki/Download) | [Change log](https://github.com/thothbot/parallax/releases) From 2985ccf05f7f6156b7611e0faa4b0b1f92a17aeb Mon Sep 17 00:00:00 2001 From: thothbot Date: Sun, 29 Mar 2015 13:31:46 +0300 Subject: [PATCH 71/75] Updated docs --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 222a04b5..19a363fe 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,10 @@ which is Java to JavaScript cross-compiler. GWT allows developers to write Java Parallax based on [three.js](http://github.com/mrdoob/three.js) project. The most methods and objects are equivalent three.js for the back compatibility. The aim of the project is to use GWT which helps maintaining complex pieces of code, and provides better design-time support in IDEs like refactoring, validation, etc...
    -Parallax supports WebGL-canvas renderer only. +Parallax includes: +* WebGL renderer +* Raytracing renderer. ### Download - new Parallax v1.6 ### From dae1a8216739cb63af58854f6ac7c96807e944d6 Mon Sep 17 00:00:00 2001 From: ftosi Date: Fri, 19 Jun 2015 10:31:16 +0200 Subject: [PATCH 72/75] Transform Controls - class used in order to scale, rotate and translate geometries. Adapted from http://threejs.org/examples/js/controls/TransformControls.js --- .../client/controls/TransformControls.java | 1199 +++++++++++++++++ 1 file changed, 1199 insertions(+) create mode 100644 src/thothbot/parallax/core/client/controls/TransformControls.java diff --git a/src/thothbot/parallax/core/client/controls/TransformControls.java b/src/thothbot/parallax/core/client/controls/TransformControls.java new file mode 100644 index 00000000..b19892d8 --- /dev/null +++ b/src/thothbot/parallax/core/client/controls/TransformControls.java @@ -0,0 +1,1199 @@ +package thothbot.parallax.core.client.controls; +/* + * Author Francesca Tosi, francesca.tosi@gmail.com + * + * Adapted from http://threejs.org/examples/js/controls/TransformControls.js + * + * This file is part of Parallax project. + * + * Parallax is free software: you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution 3.0 Unported License. + * + * Parallax is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Creative Commons Attribution + * 3.0 Unported License. for more details. + * + * You should have received a copy of the the Creative Commons Attribution + * 3.0 Unported License along with Parallax. + * If not, see http://creativecommons.org/licenses/by/3.0/. + */ + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import thothbot.parallax.core.shared.cameras.Camera; +import thothbot.parallax.core.shared.core.Geometry; +import thothbot.parallax.core.shared.core.GeometryObject; +import thothbot.parallax.core.shared.core.Object3D; +import thothbot.parallax.core.shared.core.Raycaster; +import thothbot.parallax.core.shared.core.Raycaster.Intersect; +import thothbot.parallax.core.shared.geometries.BoxGeometry; +import thothbot.parallax.core.shared.geometries.CylinderGeometry; +import thothbot.parallax.core.shared.geometries.OctahedronGeometry; +import thothbot.parallax.core.shared.geometries.PlaneGeometry; +import thothbot.parallax.core.shared.geometries.TorusGeometry; +import thothbot.parallax.core.shared.materials.LineBasicMaterial; +import thothbot.parallax.core.shared.materials.Material.SIDE; +import thothbot.parallax.core.shared.materials.MeshBasicMaterial; +import thothbot.parallax.core.shared.math.Color; +import thothbot.parallax.core.shared.math.Euler; +import thothbot.parallax.core.shared.math.Matrix4; +import thothbot.parallax.core.shared.math.Quaternion; +import thothbot.parallax.core.shared.math.Vector3; +import thothbot.parallax.core.shared.objects.Line; +import thothbot.parallax.core.shared.objects.Mesh; + +import com.google.gwt.core.shared.GWT; +import com.google.gwt.event.dom.client.MouseDownEvent; +import com.google.gwt.event.dom.client.MouseDownHandler; +import com.google.gwt.event.dom.client.MouseEvent; +import com.google.gwt.event.dom.client.MouseMoveEvent; +import com.google.gwt.event.dom.client.MouseMoveHandler; +import com.google.gwt.event.dom.client.MouseOverEvent; +import com.google.gwt.event.dom.client.MouseOverHandler; +import com.google.gwt.event.dom.client.MouseUpEvent; +import com.google.gwt.event.dom.client.MouseUpHandler; +import com.google.gwt.user.client.ui.Widget; + +public class TransformControls extends Object3D implements MouseDownHandler, MouseMoveHandler, MouseUpHandler, MouseOverHandler /*, MouseOutHandler */ { + + Widget domElement; + TransformGizmoTranslate gizmoTranslate; + TransformGizmoRotate gizmoRotate; + TransformGizmoScale gizmoScale; + + boolean _dragging = false; + String _mode = TransformControls.Mode.TRANSLATE; + String _plane = "XY"; + + Object3D object = null; + Double snap = null; + String space = "world"; + int size = 1; + String axis = null; + + LocalEvent changeEvent; + LocalEvent mouseDownEvent; + LocalEvent mouseUpEvent; + LocalEvent objectChangeEvent; + + Raycaster ray = new Raycaster(); + Vector3 pointerVector = new Vector3(); + + Vector3 point = new Vector3(); + Vector3 offset = new Vector3(); + + Vector3 rotation = new Vector3(); + Vector3 offsetRotation = new Vector3(); + double scale = 1; + double scaleFactor=0.2; + + Matrix4 lookAtMatrix = new Matrix4(); + Vector3 eye = new Vector3(); + + Matrix4 tempMatrix = new Matrix4(); + Vector3 tempVector = new Vector3(); + Quaternion tempQuaternion = new Quaternion(); + Vector3 unitX = new Vector3( 1, 0, 0 ); + Vector3 unitY = new Vector3( 0, 1, 0 ); + Vector3 unitZ = new Vector3( 0, 0, 1 ); + + Quaternion quaternionXYZ = new Quaternion(); + Quaternion quaternionX = new Quaternion(); + Quaternion quaternionY = new Quaternion(); + Quaternion quaternionZ = new Quaternion(); + Quaternion quaternionE = new Quaternion(); + + Vector3 oldPosition = new Vector3(); + Vector3 oldScale = new Vector3(); + Matrix4 oldRotationMatrix = new Matrix4(); + + Matrix4 parentRotationMatrix = new Matrix4(); + Vector3 parentScale = new Vector3(); + + Vector3 worldPosition = new Vector3(); + Euler worldRotation = new Euler(); + Matrix4 worldRotationMatrix = new Matrix4(); + Vector3 camPosition = new Vector3(); + Euler camRotation = new Euler(); + + Camera camera; + + Mesh geometry=new Mesh(); + + public class Mode { + public final static String ROTATE="rotate"; + public final static String TRANSLATE="translate"; + public final static String SCALE="scale"; + } + + public TransformControls(Camera camera, Widget domElement) { + super(); + if(domElement==null) + throw new NullPointerException("TransformControl - domElement could not be null "); + + this.camera=camera; + this.domElement=domElement; + + this.gizmoTranslate = new TransformGizmoTranslate(); + this.gizmoRotate = new TransformGizmoRotate(); + this.gizmoScale = new TransformGizmoScale(); + + this.add(this.gizmoTranslate); + this.add(this.gizmoRotate); + this.add(this.gizmoScale); + + this.gizmoTranslate.hide(); + this.gizmoRotate.hide(); + this.gizmoScale.hide(); + + _dragging = false; + _mode = TransformControls.Mode.TRANSLATE; + _plane = "XY"; + + changeEvent = new LocalEvent("change",null); + mouseDownEvent = new LocalEvent("mouseDown",null); + mouseUpEvent = new LocalEvent("mouseUp",_mode); + objectChangeEvent = new LocalEvent("objectChange",null); + + this.domElement.addDomHandler(this, MouseDownEvent.getType()); + this.domElement.addDomHandler(this, MouseUpEvent.getType()); + this.domElement.addDomHandler(this, MouseMoveEvent.getType()); + this.domElement.addDomHandler(this, MouseOverEvent.getType()); + + } + public GeometryObject getGeometry() { + return this.geometry; + } + + /** + * Set the factor for scale transform. + * + * @param scaleFactor must be between 0 and 1. Default 0.2 + * + */ + public void setScaleFactor(double scaleFactor) { + if(scaleFactor<=0 || scaleFactor>1) + return; + this.scaleFactor=scaleFactor; + } + + @Override + public void onMouseOver(MouseOverEvent event) { + + } + + public void onPointerHover(MouseEvent event) { + //OnPointerHover + + if (this.object==null || this._dragging) return; + + event.preventDefault(); + + MouseEvent pointer = event; + + Intersect intersect = intersectObjects(pointer,this.getTransformGizmo(_mode).pickers.getChildren()); + + String axis=""; + if(intersect!=null && intersect.object!=null) { + axis=intersect.object.getName(); + } + + if(!axis.equals(this.axis)) { + this.axis=axis; + this.update(); + } + } + + @Override + public void onMouseUp(MouseUpEvent event) { + //onPointerUp + if ( _dragging && ( this.axis != null ) ) { + mouseUpEvent.mode = _mode; + } + _dragging = false; + onPointerHover( event ); + } + + @Override + public void onMouseMove(MouseMoveEvent event) { + onPointerHover(event); + onPointerMove(event); + } + + public void onPointerMove(MouseEvent event) { + //onPointerMove + + if(this.object==null || this.axis==null || !this._dragging) + return; + + event.preventDefault(); + event.stopPropagation(); + + MouseEvent pointer = event; + + List tmpList=new ArrayList(); + tmpList.add(this.getTransformGizmo(_mode).activePlane); + Intersect planeIntersect = intersectObjects(pointer,tmpList); + + if(planeIntersect==null || planeIntersect.point==null) + return; + this.point.copy(planeIntersect.point); + + if(TransformControls.Mode.TRANSLATE.equals(_mode)) { + this.point.sub(this.offset); + this.point.multiply(this.parentScale); + + if("local".equals(this.space)) { + this.point.apply(this.tempMatrix.getInverse(this.worldRotationMatrix)); + + if(!this.axis.contains("X")) + this.point.setX(0); + if(!this.axis.contains("Y")) + this.point.setY(0); + if(!this.axis.contains("Z")) + this.point.setZ(0); + + this.point.apply(this.oldRotationMatrix); + + this.object.getPosition().copy(this.oldPosition); + this.object.getPosition().add(this.point); + } + if("world".equals(this.space) || (this.axis!=null && !this.axis.contains("XYZ"))) { + + if(!this.axis.contains("X")) + this.point.setX(0); + if(!this.axis.contains("Y")) + this.point.setY(0); + if(!this.axis.contains("Z")) + this.point.setZ(0); + + this.point.apply(this.tempMatrix.getInverse(this.parentRotationMatrix)); + + this.object.getPosition().copy(this.oldPosition); + this.object.getPosition().add(this.point); + } + if(this.snap!=null) { + if(!this.axis.contains("X")) + this.object.getPosition().setX(Math.round(this.getPosition().getX()/this.snap.doubleValue())*this.snap.doubleValue()); + if(!this.axis.contains("Y")) + this.object.getPosition().setY(Math.round(this.getPosition().getY()/this.snap.doubleValue())*this.snap.doubleValue()); + if(!this.axis.contains("Z")) + this.object.getPosition().setZ(Math.round(this.getPosition().getZ()/this.snap.doubleValue())*this.snap.doubleValue()); + } + } else if(TransformControls.Mode.SCALE.equals(_mode)) { + this.point.sub(this.offset); + this.point.multiply(this.parentScale); + + if("local".equals(this.space)) { + if("XYZ".equals(this.axis)) { + this.scale = 1.+this.point.getY()*this.scaleFactor; + + this.object.getScale().setX(this.oldScale.getX()*this.scale); + this.object.getScale().setY(this.oldScale.getY()*this.scale); + this.object.getScale().setZ(this.oldScale.getZ()*this.scale); + } else { + this.point.apply(this.tempMatrix.getInverse(this.worldRotationMatrix)); + + if("X".equals(this.axis)) + this.object. getScale().setX(this.oldScale.getX()*(1+this.point.getX()*this.scaleFactor)); + if("Y".equals(this.axis)) + this.object.getScale().setY(this.oldScale.getY()*(1+this.point.getY()*this.scaleFactor)); + if("Z".equals(this.axis)) + this.object.getScale().setZ(this.oldScale.getZ()*(1+this.point.getZ()*this.scaleFactor)); + } + } + } else if(TransformControls.Mode.ROTATE.equals(_mode)) { + this.point.sub(this.worldPosition); + this.point.multiply(this.parentScale); + this.tempVector.copy(this.offset).sub(this.worldPosition); + this.tempVector.multiply(this.parentScale); + + if("E".equals(this.axis)) { + this.point.apply(this.tempMatrix.getInverse(this.lookAtMatrix)); + this.tempVector.apply(this.tempMatrix.getInverse(this.lookAtMatrix)); + + this.rotation.set(Math.atan2(this.point.getZ(), this.point.getY()), Math.atan2(this.point.getX(), this.point.getZ()),Math.atan2(this.point.getY(), this.point.getX())); + this.offsetRotation.set(Math.atan2(this.tempVector.getZ(), this.point.getY()), Math.atan2(this.tempVector.getX(), this.point.getZ()), Math.atan2(this.tempVector.getY(), this.point.getX())); + + this.tempQuaternion.setFromRotationMatrix(this.tempMatrix.getInverse(this.parentRotationMatrix)); + + this.quaternionE.setFromAxisAngle(this.eye, this.rotation.getZ()-this.offsetRotation.getZ()); + this.quaternionXYZ.setFromRotationMatrix(this.worldRotationMatrix); + + this.tempQuaternion.multiply(this.tempQuaternion, this.quaternionE); + this.tempQuaternion.multiply(this.tempQuaternion, this.quaternionXYZ); + + this.object.getQuaternion().copy(tempQuaternion); + } else if ("XYZE".equals(this.axis)) { + Vector3 pointLoc=this.point.clone().cross(this.tempVector).normalize(); + this.quaternionE.setFromEuler(new Euler(pointLoc.getX(), pointLoc.getY(), pointLoc.getZ())); //rotation axis + + this.tempQuaternion.setFromRotationMatrix(this.tempMatrix.getInverse(this.parentRotationMatrix)); + this.quaternionX.setFromAxisAngle(new Vector3(this.quaternionE.getX(),this.quaternionE.getY(),this.quaternionE.getZ()), -point.clone().angleTo(this.tempVector)); + this.quaternionXYZ.setFromRotationMatrix(this.worldRotationMatrix); + + this.tempQuaternion.multiply(this.tempQuaternion,this.quaternionX); + this.tempQuaternion.multiply(this.tempQuaternion,this.quaternionXYZ); + + this.object.getQuaternion().copy(this.tempQuaternion); + } else if ("local".equals(this.space)) { + Matrix4 tmpMatrix4=this.tempMatrix.getInverse(this.worldRotationMatrix); + + this.point.apply(tmpMatrix4); + + this.tempVector.apply(tmpMatrix4); + + this.rotation.set(Math.atan2( point.getZ(), point.getY() ), Math.atan2( point.getX(), point.getZ() ), Math.atan2( point.getY(), point.getX() )); + this.offsetRotation.set(Math.atan2( tempVector.getZ(), tempVector.getY() ), Math.atan2( tempVector.getX(), tempVector.getZ() ), Math.atan2( tempVector.getY(), tempVector.getX() )); + + this.quaternionXYZ.setFromRotationMatrix(this.oldRotationMatrix); + this.quaternionX.setFromAxisAngle( this.unitX, this.rotation.getX() - this.offsetRotation.getX() ); + this.quaternionY.setFromAxisAngle( this.unitY, this.rotation.getY() - this.offsetRotation.getY() ); + this.quaternionZ.setFromAxisAngle( this.unitZ, this.rotation.getZ() - this.offsetRotation.getZ() ); + + if ( "X".equals(this.axis) ) + this.quaternionXYZ.multiply( quaternionXYZ, quaternionX ); + if ( "Y".equals(this.axis) ) + this.quaternionXYZ.multiply( quaternionXYZ, quaternionY ); + if ( "Z".equals(this.axis) ) + this.quaternionXYZ.multiply( quaternionXYZ, quaternionZ ); + + this.object.getQuaternion().copy(this.quaternionXYZ); + } else if ( "world".equals(this.space) ) { + this.rotation.set( Math.atan2( point.getZ(), point.getY() ), Math.atan2( point.getX(), point.getZ() ), Math.atan2( point.getY(), point.getX() ) ); + this.offsetRotation.set( Math.atan2( tempVector.getZ(), tempVector.getY() ), Math.atan2( tempVector.getX(), tempVector.getZ() ), Math.atan2( tempVector.getY(), tempVector.getX() ) ); + + this.tempQuaternion.setFromRotationMatrix( this.tempMatrix.getInverse( this.parentRotationMatrix ) ); + + this.quaternionX.setFromAxisAngle( unitX, rotation.getX() - offsetRotation.getX() ); + this.quaternionY.setFromAxisAngle( unitY, rotation.getY() - offsetRotation.getY() ); + this.quaternionZ.setFromAxisAngle( unitZ, rotation.getZ() - offsetRotation.getZ() ); + this.quaternionXYZ.setFromRotationMatrix( worldRotationMatrix ); + + if ( "X".equals(this.axis) ) tempQuaternion.multiply( tempQuaternion, quaternionX ); + if ( "Y".equals(this.axis) ) tempQuaternion.multiply( tempQuaternion, quaternionY ); + if ( "Z".equals(this.axis) ) tempQuaternion.multiply( tempQuaternion, quaternionZ ); + + tempQuaternion.multiply( tempQuaternion, quaternionXYZ ); + + this.object.getQuaternion().copy( tempQuaternion ); + } + } + this.update(); + } + + @Override + public void onMouseDown(MouseDownEvent event) { + //onPointerDown + if(this.object==null || this._dragging) + return; + + event.preventDefault(); + event.stopPropagation(); + + MouseDownEvent pointer = event; + + if(pointer.getNativeButton()==com.google.gwt.dom.client.NativeEvent.BUTTON_LEFT) { + Intersect intersect = this.intersectObjects(pointer, this.getTransformGizmo(_mode).pickers.getChildren()); + if(intersect!=null && intersect.object!=null) { + this.axis=intersect.object.getName(); + + this.update(); + + this.eye.copy(this.camPosition).sub(this.worldPosition).normalize(); + + this.getTransformGizmo(_mode).setActivePlane(this.axis,this.eye); + + List tmpList=new ArrayList(); + tmpList.add(this.getTransformGizmo(_mode).activePlane); + Intersect planeIntersect = this.intersectObjects(pointer,tmpList); + + this.oldPosition.copy(this.object.getPosition()); + this.oldScale.copy(this.object.getScale()); + + this.oldRotationMatrix.extractRotation(this.object.getMatrix()); + this.worldRotationMatrix.extractRotation(this.object.getMatrixWorld()); + + this.parentRotationMatrix.extractRotation(this.object.getParent().getMatrixWorld()); + this.parentScale.setFromMatrixScale(this.tempMatrix.getInverse(this.object.getParent().getMatrixWorld())); + + if(planeIntersect!=null && planeIntersect.point!=null) + this.offset.copy(planeIntersect.point); + } + } + this._dragging=true; + } + + private Intersect intersectObjects(MouseEvent pointer,List objects ) { + + double posX = (pointer.getX() / (double) this.domElement.getOffsetWidth() ) * 2.0 - 1.0; + double posY = - (pointer.getY() / (double) this.domElement.getOffsetHeight() ) * 2.0 + 1.0; + + this.pointerVector.set(posX, posY,0.5); + this.pointerVector.unproject(this.camera); + this.ray.set(this.camera.getPosition(), this.pointerVector.sub(this.camera.getPosition()).normalize()); + List intersections = this.ray.intersectObjects(objects,true); + if(intersections!=null) { + if(intersections.size()>0) + return intersections.get(0); + } + return null; + } + + public void update() { + + if (this.object==null) return; + this.object.updateMatrixWorld(true); + + this.worldPosition.setFromMatrixPosition(this.object.getMatrixWorld()); + this.worldRotation.setFromRotationMatrix(this.tempMatrix.extractRotation(this.object.getMatrixWorld())); + + this.camera.updateMatrixWorld(true); + this.camPosition.setFromMatrixPosition(camera.getMatrixWorld()); + this.camRotation.setFromRotationMatrix(this.tempMatrix.extractRotation(camera.getMatrixWorld())); + + this.scale = (this.worldPosition.distanceTo(camPosition)/6.)*this.size; + this.position.copy(this.worldPosition); + this.eye.copy(this.camPosition).sub(this.worldPosition).normalize(); + + TransformGizmo transformation = this.getTransformGizmo(_mode); + if ("local".equals(this.space)) + transformation.update(this.worldRotation, this.eye); + else if("world".equals(this.space)) + transformation.update(new Euler(), this.eye); + transformation.highlight(this.axis); + } + + public TransformGizmo getTransformGizmo(String mode) { + if(TransformControls.Mode.TRANSLATE.equals(mode)) { + return this.gizmoTranslate; + } else if(TransformControls.Mode.ROTATE.equals(mode)) { + return this.gizmoRotate; + } else /*if("scale".equals(mode))*/ { + return this.gizmoScale; + } + } + + public void setSize (int size ) { + this.size = size; + this.update(); + } + + public void setSpace (String space ) { + this.space = space; + this.update(); + } + + public void setSnap (Double snap ) { + this.snap = snap; + } + + public void setMode (String mode ) { + _mode = mode!=null ? mode : _mode; + GWT.log("mode: "+mode+" _mode: "+_mode); + if (TransformControls.Mode.SCALE.equals(_mode)) + this.space = "local"; + + this.gizmoTranslate.hide(); + this.gizmoRotate.hide(); + this.gizmoScale.hide(); + + this.setGeometry(_mode); + + this.showMode(_mode); + + this.update(); + } + + private void setGeometry(String mode) { + if(MyTransformControls.Mode.TRANSLATE.equals(mode)) { +// this.gizmoTranslate.show(); + } else if(MyTransformControls.Mode.ROTATE.equals(mode)) { +// this.gizmoRotate.show(); + } else if(MyTransformControls.Mode.SCALE.equals(mode)) { + this.geometry=this.gizmoScale.getGeometry(); + } + } + + private void showMode(String mode) { + if(TransformControls.Mode.TRANSLATE.equals(mode)) { + this.gizmoTranslate.show(); + } else if(TransformControls.Mode.ROTATE.equals(mode)) { + this.gizmoRotate.show(); + } else if(TransformControls.Mode.SCALE.equals(mode)) { + this.gizmoScale.show(); + } + } + + public void detach (Object3D object ) { + this.object=null; + this.axis = null; + + this.gizmoTranslate.hide(); + this.gizmoRotate.hide(); + this.gizmoScale.hide(); + } + + public void attach(Object3D object ) { + this.object=object; + this.gizmoTranslate.hide(); + this.gizmoRotate.hide(); + this.gizmoScale.hide(); + this.showMode(_mode); + + this.update(); + } + + public class LocalEvent { + public String type; + public String mode; + + public LocalEvent(String type, String mode) { + this.type=type; + this.mode=mode; + } + } + + public class TransformGizmoScale extends TransformGizmo { + + Mesh geometryScale = new Mesh(); + + public TransformGizmoScale() { + super(); + + Geometry arrowGeometry = new Geometry(); + Mesh mesh = new Mesh(new BoxGeometry(0.125,0.125,0.125)); + mesh.getPosition().setY(0.5); + mesh.updateMatrix(); + + arrowGeometry.merge((Geometry)mesh.getGeometry(),mesh.getMatrix()); + + Geometry lineXGeometry = new Geometry(); + lineXGeometry.getVertices().add(new Vector3(0,0,0)); + lineXGeometry.getVertices().add(new Vector3( 1,0,0)); + + Geometry lineYGeometry = new Geometry(); + lineYGeometry.getVertices().add(new Vector3(0,0,0)); + lineYGeometry.getVertices().add(new Vector3(0,1,0)); + + Geometry lineZGeometry = new Geometry(); + lineZGeometry.getVertices().add(new Vector3(0,0,0)); + lineZGeometry.getVertices().add(new Vector3(0,0,1)); + + this.handleGizmos=new HashMap>(); + { + //X + ArrayList xList=new ArrayList(); + xList.add(new HandleGizmos(new Mesh( arrowGeometry, new GizmoMaterial(new Color(0xff0000),null)), new Vector3(0.5,0,0), new Vector3(0,0,-Math.PI/2.))); + xList.add(new HandleGizmos(new Line( lineXGeometry, new GizmoLineMaterial(new Color(0xff0000))), null, null)); + this.handleGizmos.put("X",xList); + //Y + ArrayList yList=new ArrayList(); + yList.add(new HandleGizmos(new Mesh( arrowGeometry, new GizmoMaterial(new Color(0x00ff00),null)), new Vector3(0,0.5,0), null)); + yList.add(new HandleGizmos(new Line( lineYGeometry, new GizmoLineMaterial(new Color(0x00ff00))), null, null)); + this.handleGizmos.put("Y",yList); + //Z + ArrayList zList=new ArrayList(); + zList.add(new HandleGizmos(new Mesh( arrowGeometry, new GizmoMaterial(new Color(0x0000ff),null)), new Vector3(0,0,0.5), new Vector3(Math.PI/2.,0,0))); + zList.add(new HandleGizmos(new Line( lineZGeometry, new GizmoLineMaterial(new Color(0x0000ff))), null, null)); + this.handleGizmos.put("Z",zList); + //XYZ + ArrayList xyzList=new ArrayList(); + xyzList.add(new HandleGizmos(new Mesh( new BoxGeometry(0.125,0.125,0.125), new GizmoMaterial(new Color(0xffffff),0.25)), null, null)); + this.handleGizmos.put("XYZ",xyzList); + + } + this.pickerGizmos=new HashMap>(); + { + //X + ArrayList xList=new ArrayList(); + CylinderGeometry obj_xx=new CylinderGeometry(0.2,0.,1,4,1); + Object3D obj_x=new Mesh(obj_xx , new GizmoMaterial(new Color(0xff0000),.25)); + xList.add(new HandleGizmos(obj_x, new Vector3(0.6,0,0), new Vector3(0,0,-Math.PI/2.))); + this.pickerGizmos.put("X",xList); + obj_x.setName("X"); + geometryScale.add (obj_x); + GWT.log("SIZE: "+geometryScale.getChildren().size()); + //Y + ArrayList yList=new ArrayList(); + Object3D obj_y=new Mesh( new CylinderGeometry(0.2,0.,1,4,1), new GizmoMaterial(new Color(0x00ff00),.25)); + yList.add(new HandleGizmos(obj_y, new Vector3(0,0.6,0), null)); + this.pickerGizmos.put("Y",yList); + obj_x.setName("Y"); + geometryScale.add(obj_y); + GWT.log("SIZE: "+geometryScale.getChildren().size()); + //Z + ArrayList zList=new ArrayList(); + Object3D obj_z=new Mesh( new CylinderGeometry(0.2,0.,1,4,1), new GizmoMaterial(new Color(0x0000ff),0.25)); + zList.add(new HandleGizmos(obj_z, new Vector3(0,0,0.6), new Vector3(Math.PI/2.,0,0))); + this.pickerGizmos.put("Z",zList); + obj_x.setName("Z"); + geometryScale.add(obj_z); + GWT.log("SIZE: "+geometryScale.getChildren().size()); + //XYZ + ArrayList xyzList=new ArrayList(); + Object3D obj_xyz=new Mesh( new BoxGeometry(0.4,0.4,0.4), new GizmoMaterial(new Color(0x000000),0.25)); + xyzList.add(new HandleGizmos(obj_xyz, null, null)); + this.pickerGizmos.put("XYZ",xyzList); + obj_x.setName("XYZ"); + geometryScale.add(obj_xyz); + GWT.log("SIZE: "+geometryScale.getChildren().size()); + } + + this.init(); + } + + public Mesh getGeometry() { + return geometryScale; + } + + @Override + public void setActivePlane(String axis, Vector3 eye) { + + Matrix4 tempMatrix = new Matrix4(); + eye.apply(tempMatrix.getInverse( tempMatrix.extractRotation( this.planes.getObjectByName("XY",true).getMatrixWorld()))); + + if ("X".equals(axis)) { + this.activePlane = this.planes.getObjectByName("XY",true); + if(Math.abs(eye.getY()) > Math.abs(eye.getZ())) + this.activePlane = this.planes.getObjectByName("XZ",true); + } + if ("Y".equals(axis)){ + this.activePlane = this.planes.getObjectByName("XY",true); + if ( Math.abs(eye.getX()) > Math.abs(eye.getZ()) ) + this.activePlane = this.planes.getObjectByName("YZ",true); + } + if ("Z".equals(axis)){ + this.activePlane = this.planes.getObjectByName("XZ",true); + if ( Math.abs(eye.getX()) > Math.abs(eye.getY()) ) + this.activePlane = this.planes.getObjectByName("YZ",true); + } + if ("XYZ".equals(axis)) + this.activePlane = this.planes.getObjectByName("XYZE",true); + + this.hide(); + this.show(); + } + } + + public class TransformGizmoRotate extends TransformGizmo { + + public TransformGizmoRotate() { + super(); + + this.handleGizmos=new HashMap>(); + { + //X + ArrayList xList=new ArrayList(); + xList.add(new HandleGizmos(new Line( CircleGeometry(1.,"x",0.5), new GizmoLineMaterial(new Color(0xff0000))), null, null)); + this.handleGizmos.put("X",xList); + //Y + ArrayList yList=new ArrayList(); + yList.add(new HandleGizmos(new Line( CircleGeometry(1.,"y",0.5), new GizmoLineMaterial(new Color(0x00ff00))), null, null)); + this.handleGizmos.put("Y",yList); + //Z + ArrayList zList=new ArrayList(); + zList.add(new HandleGizmos(new Line( CircleGeometry(1.,"z",0.5), new GizmoLineMaterial(new Color(0x0000ff))), null, null)); + this.handleGizmos.put("Z",zList); + //E + ArrayList eList=new ArrayList(); + eList.add(new HandleGizmos(new Line( CircleGeometry(1.25,"z",1.), new GizmoLineMaterial(new Color(0xcccc00))), null, null)); + this.handleGizmos.put("E",eList); + //XYZE + ArrayList xyzeList=new ArrayList(); + xyzeList.add(new HandleGizmos(new Line( CircleGeometry(1.,"z",1.), new GizmoLineMaterial(new Color(0x787878))), null, null)); + this.handleGizmos.put("XYZE",xyzeList); + } + + this.pickerGizmos = new HashMap>(); + { + //X + ArrayList xList=new ArrayList(); + xList.add(new HandleGizmos(new Mesh( new TorusGeometry(1.,0.12,4,12,Math.PI), new GizmoMaterial(new Color(0xff0000),0.25)), new Vector3(0,0,0), new Vector3(0,-Math.PI/2.,-Math.PI/2.))); + this.pickerGizmos.put("X",xList); + //Y + ArrayList yList=new ArrayList(); + yList.add(new HandleGizmos(new Mesh( new TorusGeometry(1.,0.12,4,12,Math.PI), new GizmoMaterial(new Color(0x00ff00),0.25)), new Vector3(0,0,0), new Vector3(Math.PI/2.,0,0))); + this.pickerGizmos.put("Y",yList); + //Z + ArrayList zList=new ArrayList(); + zList.add(new HandleGizmos(new Mesh( new TorusGeometry(1., 0.12, 4,12,Math.PI), new GizmoMaterial(new Color(0x0000ff),0.25)), new Vector3(0,0,0), new Vector3(0,0,-Math.PI/2.))); + this.pickerGizmos.put("Z",zList); + //E + ArrayList eList=new ArrayList(); + eList.add(new HandleGizmos(new Mesh( new TorusGeometry(1.25,0.12,2,24), new GizmoMaterial(new Color(0xcccc00),0.25)), null, null)); + this.pickerGizmos.put("E",eList); + //XYZE + ArrayList xyzeList=new ArrayList(); + xyzeList.add(new HandleGizmos(new Mesh(new Geometry()), null, null)); + this.pickerGizmos.put("XYZE",xyzeList); + } + this.init(); + } + + public class Models { + public Map> handles ; + public Map> pickers ; + } + + public void update(Euler rotation, Vector3 eyeP) { + super.update(rotation, eyeP); + + Matrix4 tempMatrix = new Matrix4(); + final Euler worldRotation = new Euler(0,0,1); + final Quaternion tempQuaternion = new Quaternion(); + final Vector3 unitX = new Vector3(1,0,0); + final Vector3 unitY = new Vector3(0,1,0); + final Vector3 unitZ = new Vector3(0,0,1); + + final Quaternion quaternionX = new Quaternion(); + final Quaternion quaternionY = new Quaternion(); + final Quaternion quaternionZ = new Quaternion(); + + final Vector3 eye = eyeP.clone(); + + worldRotation.copy(this.planes.getObjectByName("XY",true).getRotation()); + tempQuaternion.setFromEuler(worldRotation); + + tempMatrix.makeRotationFromQuaternion(tempQuaternion).getInverse(tempMatrix); + eye.apply(tempMatrix); + + this.traverse(new Traverse() { + @Override + public void callback(Object3D child) { + tempQuaternion.setFromEuler(worldRotation); + + if ("X".equals(child.getName())) { + quaternionX.setFromAxisAngle( unitX, Math.atan2(-eye.getY(),eye.getZ())); + tempQuaternion.multiply(tempQuaternion,quaternionX); + child.getQuaternion().copy(tempQuaternion); + } + if ("Y".equals(child.getName())) { + quaternionY.setFromAxisAngle(unitY,Math.atan2(eye.getX(),eye.getZ())); + tempQuaternion.multiply(tempQuaternion,quaternionY); + child.getQuaternion().copy(tempQuaternion); + } + if ("Z".equals(child.getName())) { + quaternionZ.setFromAxisAngle(unitZ,Math.atan2(eye.getY(),eye.getX())); + tempQuaternion.multiply(tempQuaternion,quaternionZ); + child.getQuaternion().copy(tempQuaternion); + } + } + }); + } + + //Mettiamo il secondo parametro anche se non utilizzato + @Override + public void setActivePlane(String axis, Vector3 eye) { + if ( "E".equals(axis) ) this.activePlane = this.planes.getObjectByName("XYZE",true); + if ( "X".equals(axis) ) this.activePlane = this.planes.getObjectByName("YZ",true); + if ( "Y".equals(axis) ) this.activePlane = this.planes.getObjectByName("XZ",true); + if ( "Z".equals(axis) ) this.activePlane = this.planes.getObjectByName("XY",true); + + this.hide(); + this.show(); + } + + public Geometry CircleGeometry(Double radius, String facing, Double arc ) { + Geometry geometry = new Geometry(); + arc = (arc!=null) ? arc : 1; + for ( int i = 0; i <= 64 * arc; ++i ) { + if ( "x".equals(facing) ) + geometry.getVertices().add( new Vector3( 0, Math.cos( (double)i / 32. * Math.PI ), Math.sin( (double)i / 32. * Math.PI ) ).multiply(radius) ); + if ( "y".equals(facing) ) + geometry.getVertices().add( new Vector3( Math.cos( (double)i / 32. * Math.PI ), 0, Math.sin( (double)i / 32. * Math.PI ) ).multiply(radius) ); + if ( "z".equals(facing) ) + geometry.getVertices().add( new Vector3( Math.sin( (double)i / 32. * Math.PI ), Math.cos( (double)i / 32. * Math.PI ), 0 ).multiply(radius) ); + } + return geometry; + } + } + + public class TransformGizmoTranslate extends TransformGizmo { + + public TransformGizmoTranslate() { + super(); + + Geometry arrowGeometry = new Geometry(); + Mesh mesh = new Mesh(new CylinderGeometry( 0, 0.05, 0.2, 12, 1)); + mesh.getPosition().setY(0.5); + mesh.updateMatrix(); + + arrowGeometry.merge((Geometry)mesh.getGeometry(),mesh.getMatrix()); + + Geometry lineXGeometry = new Geometry(); + lineXGeometry.getVertices().add(new Vector3( 0, 0, 0 )); + lineXGeometry.getVertices().add(new Vector3( 1, 0, 0 )); + + Geometry lineYGeometry = new Geometry(); + lineYGeometry.getVertices().add(new Vector3( 0, 0, 0 )); + lineYGeometry.getVertices().add(new Vector3( 0, 1, 0 )); + + Geometry lineZGeometry = new Geometry(); + lineZGeometry.getVertices().add(new Vector3( 0, 0, 0 )); + lineZGeometry.getVertices().add(new Vector3( 0, 0, 1 )); + + this.handleGizmos=new HashMap>(); + { + //X + ArrayList xList=new ArrayList(); + xList.add(new HandleGizmos(new Mesh( arrowGeometry.clone(), new GizmoMaterial(new Color(0xff0000),null)), new Vector3(0.5,0,0), new Vector3(0, 0, -Math.PI/2.))); + xList.add(new HandleGizmos(new Line( lineXGeometry, new GizmoLineMaterial(new Color(0xff0000))), null, null)); + this.handleGizmos.put("X",xList); + //Y + ArrayList yList=new ArrayList(); + yList.add(new HandleGizmos(new Mesh( arrowGeometry.clone(), new GizmoMaterial(new Color(0x00ff00),null)), new Vector3(0,0.5,0), null)); + yList.add(new HandleGizmos(new Line( lineYGeometry, new GizmoLineMaterial(new Color(0x00ff00))), null, null)); + this.handleGizmos.put("Y",yList); + //Z + ArrayList zList=new ArrayList(); + zList.add(new HandleGizmos(new Mesh( arrowGeometry.clone(), new GizmoMaterial(new Color(0x0000ff),null)), new Vector3(0,0,0.5), new Vector3(Math.PI/2.,0,0))); + zList.add(new HandleGizmos(new Line( lineZGeometry, new GizmoLineMaterial(new Color(0x0000ff))), null, null)); + this.handleGizmos.put("Z",zList); + //XYZ + ArrayList xyzList=new ArrayList(); + xyzList.add(new HandleGizmos(new Mesh(new OctahedronGeometry( 0.1, 0), new GizmoMaterial(new Color(0xffffff),0.25)), new Vector3(0,0,0), new Vector3(0,0,0))); + this.handleGizmos.put("XYZ",xyzList); + //XY + ArrayList xyList=new ArrayList(); + xyList.add(new HandleGizmos(new Mesh(new PlaneGeometry( 0.29, 0.29), new GizmoMaterial(new Color(0xffff00),0.25)), new Vector3(0.15,0.15,0), null)); + this.handleGizmos.put("XY",xyList); + //YZ + ArrayList yzList=new ArrayList(); + yzList.add(new HandleGizmos(new Mesh(new PlaneGeometry(0.29, 0.29), new GizmoMaterial(new Color(0x00ffff),0.25)), new Vector3(0,0.15,0.15), new Vector3(0,Math.PI/2.,0))); + this.handleGizmos.put("YZ",yzList); + //XZ + ArrayList xzList=new ArrayList(); + xzList.add(new HandleGizmos(new Mesh(new PlaneGeometry(0.29, 0.29), new GizmoMaterial(new Color(0xff00ff),0.25)), new Vector3(0.15,0,0.15), new Vector3(-Math.PI/2.,0,0))); + this.handleGizmos.put("XZ",xzList); + } + this.pickerGizmos=new HashMap>(); + { + //X + ArrayList xList=new ArrayList(); + xList.add(new HandleGizmos(new Mesh( new CylinderGeometry( 0.2, 0., 1., 4, 1 ), new GizmoMaterial(new Color(0xff0000),0.25)), new Vector3(0.6,0,0), new Vector3(0, 0, -Math.PI/2.))); + this.pickerGizmos.put("X",xList); + //Y + ArrayList yList=new ArrayList(); + yList.add(new HandleGizmos(new Mesh( new CylinderGeometry( 0.2, 0., 1., 4, 1 ), new GizmoMaterial(new Color(0x00ff00),0.25)), new Vector3(0,0.6,0), null)); + this.pickerGizmos.put("Y",yList); + //Z + ArrayList zList=new ArrayList(); + zList.add(new HandleGizmos(new Mesh( new CylinderGeometry( 0.2, 0., 1., 4, 1 ), new GizmoMaterial(new Color(0x0000ff),0.25)), new Vector3(0,0,0.6), new Vector3(Math.PI/2.,0,0))); + this.pickerGizmos.put("Z",zList); + //XYZ + ArrayList xyzList=new ArrayList(); + xyzList.add(new HandleGizmos(new Mesh( new OctahedronGeometry( 0.2, 0 ), new GizmoMaterial(new Color(0xffffff),0.25)), null, null)); + this.pickerGizmos.put("XYZ",xyzList); + //XY + ArrayList xyList=new ArrayList(); + xyList.add(new HandleGizmos(new Mesh( new PlaneGeometry( 0.4, 0.4 ), new GizmoMaterial(new Color(0xffff00),0.25)), new Vector3(0.2,0.2,0), null)); + this.pickerGizmos.put("XY",xyList); + //YZ + ArrayList yzList=new ArrayList(); + yzList.add(new HandleGizmos(new Mesh( new PlaneGeometry( 0.4, 0.4 ), new GizmoMaterial(new Color(0x00ffff),0.25)), new Vector3(0,0.2,0.2), new Vector3(0,Math.PI/2.,0))); + this.pickerGizmos.put("YZ",yzList); + //XZ + ArrayList xzList=new ArrayList(); + xzList.add(new HandleGizmos(new Mesh( new PlaneGeometry( 0.4, 0.4 ), new GizmoMaterial(new Color(0xff00ff),0.25)), new Vector3(0.2,0,0.2), new Vector3(-Math.PI/2.,0,0))); + this.pickerGizmos.put("XZ",xzList); + } + + this.init(); + } + + @Override + public void setActivePlane(String axis, Vector3 eye) { + + Matrix4 tempMatrix = new Matrix4(); + + eye.apply(tempMatrix.getInverse(tempMatrix.extractRotation( this.planes.getObjectByName("XY", true).getMatrixWorld() ) )); + + if ( "X".equals(axis) ) { + this.activePlane = this.planes.getObjectByName("XY", true); + if(Math.abs(eye.getY()) > Math.abs(eye.getZ())) + this.activePlane = this.planes.getObjectByName("XZ", true); + } + if ( "Y".equals(axis) ){ + this.activePlane = this.planes.getObjectByName("XY", true); + if(Math.abs(eye.getX()) > Math.abs(eye.getZ())) + this.activePlane = this.planes.getObjectByName("YZ", true); + } + if ( "Z".equals(axis) ){ + this.activePlane = this.planes.getObjectByName("XZ", true); + if(Math.abs(eye.getX()) > Math.abs(eye.getY())) + this.activePlane = this.planes.getObjectByName("YZ", true); + } + + if ( "XYZ".equals(axis) ) + this.activePlane = this.planes.getObjectByName("XYZE",true); + if ( "XY".equals(axis) ) + this.activePlane = this.planes.getObjectByName("XY",true); + if ("YZ".equals(axis) ) + this.activePlane = this.planes.getObjectByName("YZ",true); + if ( "XZ".equals(axis) ) + this.activePlane =this.planes.getObjectByName("XZ",true); + + this.hide(); + this.show(); + } + } + + abstract class TransformGizmo extends Object3D { + boolean showPickers = false; //debug + boolean showActivePlane = false; //debug + + Object3D handles; + Object3D pickers; + Object3D planes; + + Map> handleGizmos; + Map> pickerGizmos; + + public Object3D activePlane; + + public TransformGizmo() { + super(); + } + + abstract public void setActivePlane(String axis, Vector3 eye); + + public void init() { + this.handles = new Object3D(); + this.pickers = new Object3D(); + this.planes = new Object3D(); + + this.add(this.handles); + this.add(this.pickers); + this.add(this.planes); + + //// PLANES + PlaneGeometry planeGeometry = new PlaneGeometry( 50, 50, 2, 2 ); + MeshBasicMaterial planeMaterial = new MeshBasicMaterial(); + planeMaterial.setWireframe(true); + planeMaterial.setSide(SIDE.DOUBLE); + + Map planesLocal = new HashMap(); + + planesLocal.put("XY",new Mesh(planeGeometry.clone(),planeMaterial)); + planesLocal.put("YZ",new Mesh(planeGeometry.clone(),planeMaterial)); + planesLocal.put("XZ",new Mesh(planeGeometry.clone(),planeMaterial)); + planesLocal.put("XYZE",new Mesh(planeGeometry,planeMaterial)); + + this.activePlane = planesLocal.get("XYZE"); + + planesLocal.get("YZ").getRotation().set( 0, Math.PI/2., 0 ); + planesLocal.get("XZ").getRotation().set( -Math.PI/2., 0, 0 ); + + for(Entry entry:planesLocal.entrySet()) { + Mesh mesh = entry.getValue(); + mesh.setName(entry.getKey()+""); + this.planes.add(mesh); + mesh.setVisible(false); + } + + this.setupGizmos(handleGizmos, this.handles); + this.setupGizmos(pickerGizmos, this.pickers); + + this.traverse(new Traverse() { + + @Override + public void callback(Object3D child) { + if (child instanceof Mesh) { + Mesh localChild=(Mesh) child; + localChild.updateMatrix(); + + Geometry tempGeometry = new Geometry(); + tempGeometry.merge( (Geometry)localChild.getGeometry(), child.getMatrix() ); + + ((Mesh) child).setGeometry(tempGeometry); + child.setPosition(new Vector3(0, 0, 0)); + child.setRotation(new Euler(0, 0, 0)); + child.setScale(new Vector3( 1, 1, 1)); + } + } + }); + } + + public void update(final Euler rotation, final Vector3 eye ) { + + final Vector3 vec1 = new Vector3( 0, 0, 0 ); + final Vector3 vec2 = new Vector3( 0, 1, 0 ); + final Matrix4 lookAtMatrix = new Matrix4(); + + this.traverse(new Traverse() { + @Override + public void callback(Object3D child) { + if(child.getName().contains("E")) { + child.getQuaternion().setFromRotationMatrix(lookAtMatrix.lookAt(eye, vec1, vec2)); + } else if(child.getName().contains("X") || child.getName().contains("Y") || child.getName().contains("Z")) { + child.getQuaternion().setFromEuler(rotation); + } + } + }); + }; + + public void show() { + this.traverse(new Traverse() { + @Override + public void callback(Object3D child) { + child.setVisible(true); + if (child.getParent().equals(pickers)) + child.setVisible(showPickers); + if (child.getParent().equals(planes)) + child.setVisible(false); + } + }); + this.activePlane.setVisible(showActivePlane); + } + + public void highlight(final String axis) { + this.traverse(new Traverse() { + @Override + public void callback(Object3D child) { + if(child instanceof GeometryObject) { + GeometryObject geoLoc=(GeometryObject)child; + if(geoLoc.getMaterial() instanceof HasHighlight) { + HasHighlight material = (HasHighlight) geoLoc.getMaterial(); + if ( geoLoc.getName().equals(axis) ) { + material.highlight(true); + } else { + material.highlight(false); + } + } + } + } + }); + } + + public void hide() { + this.traverse(new Traverse() { + @Override + public void callback(Object3D child) { + child.setVisible(false); + } + }); + } + + private void setupGizmos(Map> gizmoMap, Object3D parent) { + for (String key : gizmoMap.keySet()) { + ArrayList gizmoList=gizmoMap.get(key); + for(HandleGizmos gizmo:gizmoList) { + Object3D object=gizmo.getGeometry(); + Vector3 position=gizmo.getPos(); + Vector3 rotation=gizmo.getRot(); + + object.setName(key); + if(position!=null) { + object.getPosition().set(position.getX(), position.getY(), position.getZ()); + } + if(rotation!=null) { + object.getRotation().set(rotation. getX(), rotation. getY(), rotation. getZ()); + } + parent.add(object); + } + } + } + } + + public class HandleGizmos { + //private GeometryObject geometry; + private Object3D geometry; + //private AbstractGeometry geometry; + private Vector3 pos=new Vector3(); + private Vector3 rot=new Vector3(); + + public HandleGizmos(Object3D geometry, Vector3 pos, Vector3 rot) { + this.geometry=geometry; + if(pos!=null) + this.pos=pos; + if(rot!=null) + this.rot=rot; + } + public Object3D getGeometry() { + return this.geometry; + } + public Vector3 getPos() { + return this.pos; + } + public Vector3 getRot() { + return this.rot; + } + } + + public class GizmoLineMaterial extends LineBasicMaterial implements HasHighlight { + + public Color oldColor; + private double opacity; + private double oldOpacity; + + public GizmoLineMaterial(Color color) { + super(); + + this.setDepthTest(false); + this.setDepthWrite(false); + this.setTransparent(true); + this.setLinewidth(1.); + + this.setColor(color); + this.oldColor=this.getColor().clone(); + this.oldOpacity = this.opacity; + } + + @Override + public void highlight(boolean highlighted) { + if ( highlighted ) { + this.setColor(new Color().setRGB(1,1,0)); + this.opacity = 1; + } else { + this.getColor().copy(this.oldColor); + this.opacity = this.oldOpacity; + } + } + } + + public interface HasHighlight { + public void highlight(boolean highlighted); + } + + public class GizmoMaterial extends MeshBasicMaterial implements HasHighlight { + + private Color oldColor; + private double oldOpacity; + + public GizmoMaterial(Color color, Double opacity/*vedremo in seguito i parametri utilizzati*/) { + super(); + + this.setDepthTest(false); + this.setDepthWrite(false); + this.setSide(SIDE.FRONT); + this.setTransparent(true); + + if(color!=null) + this.setColor(color); + if(opacity!=null) { + super.setOpacity(opacity); + } + + this.oldColor = this.getColor().clone(); + this.oldOpacity = super.getOpacity(); + } + + @Override + public void highlight(boolean highlighted) { + if ( highlighted ) { + this.setColor(new Color().setRGB(1,1,0)); + super.setOpacity(1); + } else { + this.getColor().copy(this.oldColor); + super.setOpacity(this.oldOpacity); + } + } + } +} + From ea256d1b5c0dcb0a80120a819f58f36d75c30a37 Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 20 Aug 2015 22:46:39 -0400 Subject: [PATCH 73/75] typo correction --- .../parallax/core/client/controls/TransformControls.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/thothbot/parallax/core/client/controls/TransformControls.java b/src/thothbot/parallax/core/client/controls/TransformControls.java index b19892d8..def262c7 100644 --- a/src/thothbot/parallax/core/client/controls/TransformControls.java +++ b/src/thothbot/parallax/core/client/controls/TransformControls.java @@ -511,11 +511,11 @@ public void setMode (String mode ) { } private void setGeometry(String mode) { - if(MyTransformControls.Mode.TRANSLATE.equals(mode)) { + if(TransformControls.Mode.TRANSLATE.equals(mode)) { // this.gizmoTranslate.show(); - } else if(MyTransformControls.Mode.ROTATE.equals(mode)) { + } else if(TransformControls.Mode.ROTATE.equals(mode)) { // this.gizmoRotate.show(); - } else if(MyTransformControls.Mode.SCALE.equals(mode)) { + } else if(TransformControls.Mode.SCALE.equals(mode)) { this.geometry=this.gizmoScale.getGeometry(); } } From 2ec3b728ce62b2132e5d4699cd06e68db14cadee Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 20 Aug 2015 22:47:07 -0400 Subject: [PATCH 74/75] gitignore update --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 115655df..70866814 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ /war/thothbot.* /www-test /gwt-unitCache +/.idea +/target +*.iml From 9475323993b098f81c8c59cac987671b1858b904 Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 20 Aug 2015 22:47:52 -0400 Subject: [PATCH 75/75] pom.xml added specially for support maven build projects --- pom.xml | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 pom.xml diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..813831d0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,58 @@ + + 4.0.0 + thothbot.parallax + parallax + jar + 0.1-SNAPSHOT + parallax3d + + + 2.7.0 + + + + + com.google.gwt + gwt-servlet + ${gwt.version} + runtime + + + com.google.gwt + gwt-user + ${gwt.version} + provided + + + + + src + + + org.codehaus.mojo + gwt-maven-plugin + ${gwt.version} + + + + compile + test + + + + + 2 + + + + maven-war-plugin + org.apache.maven.plugins + + war + + + + + + \ No newline at end of file