three-stdlib 2.12.0 → 2.13.1
Sign up to get free protection for your applications and to get access to all the features.
- package/geometries/ConvexGeometry.cjs.js +1 -1
- package/geometries/ConvexGeometry.js +1 -1
- package/index.cjs.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/misc/ProgressiveLightmap.cjs.js +1 -1
- package/misc/ProgressiveLightmap.js +2 -2
- package/objects/GroundProjectedEnv.cjs.js +1 -0
- package/objects/GroundProjectedEnv.d.ts +12 -0
- package/objects/GroundProjectedEnv.js +145 -0
- package/package.json +1 -1
- package/webxr/OculusHandModel.cjs.js +1 -1
- package/webxr/OculusHandModel.d.ts +1 -1
- package/webxr/OculusHandModel.js +2 -2
- package/webxr/XRHandMeshModel.d.ts +1 -1
- package/webxr/XRHandMeshModel.js +3 -3
package/index.d.ts
CHANGED
@@ -104,6 +104,7 @@ export * from './objects/ReflectorRTT';
|
|
104
104
|
export * from './objects/ReflectorForSSRPass';
|
105
105
|
export * from './objects/Sky';
|
106
106
|
export * from './objects/Water2';
|
107
|
+
export * from './objects/GroundProjectedEnv';
|
107
108
|
export * from './utils/SceneUtils';
|
108
109
|
export * from './utils/UVsDebug';
|
109
110
|
export * from './utils/GeometryUtils';
|
package/index.js
CHANGED
@@ -50,6 +50,7 @@ export { ReflectorRTT } from './objects/ReflectorRTT.js';
|
|
50
50
|
export { ReflectorForSSRPass } from './objects/ReflectorForSSRPass.js';
|
51
51
|
export { Sky } from './objects/Sky.js';
|
52
52
|
export { Water2 } from './objects/Water2.js';
|
53
|
+
export { GroundProjectedEnv } from './objects/GroundProjectedEnv.js';
|
53
54
|
export { SceneUtils } from './utils/SceneUtils.js';
|
54
55
|
export { UVsDebug } from './utils/UVsDebug.js';
|
55
56
|
export { GeometryUtils } from './utils/GeometryUtils.js';
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=t(require("potpack"));exports.ProgressiveLightMap=class{constructor(t,i=1024){this.renderer=t,this.res=i,this.lightMapContainers=[],this.compiled=!1,this.scene=new e.Scene,this.scene.background=null,this.tinyTarget=new e.WebGLRenderTarget(1,1),this.buffer1Active=!1,this.firstUpdate=!0,this.warned=!1;const r=/(Android|iPad|iPhone|iPod)/g.test(navigator.userAgent)?alfFloatType:e.FloatType;this.progressiveLightMap1=new e.WebGLRenderTarget(this.res,this.res,{type:r}),this.progressiveLightMap2=new e.WebGLRenderTarget(this.res,this.res,{type:r}),this.uvMat=new e.MeshPhongMaterial,this.uvMat.uniforms={},this.uvMat.onBeforeCompile=e=>{e.vertexShader="#define USE_LIGHTMAP\n"+e.vertexShader.slice(0,-1)+"\tgl_Position = vec4((uv2 - 0.5) * 2.0, 1.0, 1.0); }";const t=e.fragmentShader.indexOf("void main() {");e.fragmentShader="varying vec2 vUv2;\n"+e.fragmentShader.slice(0,t)+"\tuniform sampler2D previousShadowMap;\n\tuniform float averagingWindow;\n"+e.fragmentShader.slice(t-1,-1)+"\nvec3 texelOld = texture2D(previousShadowMap, vUv2).rgb;\n\t\t\t\tgl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/averagingWindow);\n\t\t\t}",e.uniforms.previousShadowMap={value:this.progressiveLightMap1.texture},e.uniforms.averagingWindow={value:100},this.uvMat.uniforms=e.uniforms,this.uvMat.userData.shader=e,this.compiled=!0}}addObjectsToLightMap(e){this.uv_boxes=[];const t=3/this.res;for(let i=0;i<e.length;i++){const r=e[i];r.isLight?this.scene.attach(r):r.geometry.hasAttribute("uv")?(null==this.blurringPlane&&this._initializeBlurPlane(this.res,this.progressiveLightMap1),r.material.lightMap=this.progressiveLightMap2.texture,r.material.dithering=!0,r.castShadow=!0,r.receiveShadow=!0,r.renderOrder=1e3+i,this.uv_boxes.push({w:1+2*t,h:1+2*t,index:i}),this.lightMapContainers.push({basicMat:r.material,object:r}),this.compiled=!1):console.warn("All lightmap objects need UVs!")}const r=i.default(this.uv_boxes);this.uv_boxes.forEach((i=>{const s=e[i.index].geometry.getAttribute("uv").clone();for(let e=0;e<s.array.length;e+=s.itemSize)s.array[e]=(s.array[e]+i.x+t)/r.w,s.array[e+1]=(s.array[e+1]+i.y+t)/r.h;e[i.index].geometry.setAttribute("uv2",s),e[i.index].geometry.getAttribute("uv2").needsUpdate=!0}))}update(e,t=100,i=!0){if(null==this.blurringPlane)return;const r=this.renderer.getRenderTarget();this.blurringPlane.visible=i;for(let e=0;e<this.lightMapContainers.length;e++)this.lightMapContainers[e].object.oldScene=this.lightMapContainers[e].object.parent,this.scene.attach(this.lightMapContainers[e].object);this.firstUpdate&&(this.renderer.setRenderTarget(this.tinyTarget),this.renderer.render(this.scene,e),this.firstUpdate=!1);for(let e=0;e<this.lightMapContainers.length;e++)this.uvMat.uniforms.averagingWindow={value:t},this.lightMapContainers[e].object.material=this.uvMat,this.lightMapContainers[e].object.oldFrustumCulled=this.lightMapContainers[e].object.frustumCulled,this.lightMapContainers[e].object.frustumCulled=!1;const s=this.buffer1Active?this.progressiveLightMap1:this.progressiveLightMap2,a=this.buffer1Active?this.progressiveLightMap2:this.progressiveLightMap1;this.renderer.setRenderTarget(s),this.uvMat.uniforms.previousShadowMap={value:a.texture},this.blurringPlane.material.uniforms.previousShadowMap={value:a.texture},this.buffer1Active=!this.buffer1Active,this.renderer.render(this.scene,e);for(let e=0;e<this.lightMapContainers.length;e++)this.lightMapContainers[e].object.frustumCulled=this.lightMapContainers[e].object.oldFrustumCulled,this.lightMapContainers[e].object.material=this.lightMapContainers[e].basicMat,this.lightMapContainers[e].object.oldScene.attach(this.lightMapContainers[e].object);this.renderer.setRenderTarget(r)}showDebugLightmap(t,i){0!=this.lightMapContainers.length?(null==this.labelMesh&&(this.labelMaterial=new e.MeshBasicMaterial({map:this.progressiveLightMap1.texture,side:e.DoubleSide}),this.labelPlane=new e.PlaneGeometry(100,100),this.labelMesh=new e.Mesh(this.labelPlane,this.labelMaterial),this.labelMesh.position.y=250,this.lightMapContainers[0].object.parent.add(this.labelMesh)),null!=i&&this.labelMesh.position.copy(i),this.labelMesh.visible=t):this.warned||(console.warn("Call this after adding the objects!"),this.warned=!0)}_initializeBlurPlane(t,i=null){const r=new e.MeshBasicMaterial;r.uniforms={previousShadowMap:{value:null},pixelOffset:{value:1/t},polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:3},r.onBeforeCompile=e=>{e.vertexShader="#define USE_UV\n"+e.vertexShader.slice(0,-1)+"\tgl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }";const s=e.fragmentShader.indexOf("void main() {");e.fragmentShader="#define USE_UV\n"+e.fragmentShader.slice(0,s)+"\tuniform sampler2D previousShadowMap;\n\tuniform float pixelOffset;\n"+e.fragmentShader.slice(s-1,-1)+"\tgl_FragColor.rgb = (\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, 0.0 )).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( 0.0 , pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( 0.0 , -pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, 0.0 )).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, -pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, -pixelOffset)).rgb)/8.0;\n\t\t}",e.uniforms.previousShadowMap={value:i.texture},e.uniforms.pixelOffset={value:.5/t},r.uniforms=e.uniforms,r.userData.shader=e,this.compiled=!0},this.blurringPlane=new e.Mesh(new e.
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=t(require("potpack"));exports.ProgressiveLightMap=class{constructor(t,i=1024){this.renderer=t,this.res=i,this.lightMapContainers=[],this.compiled=!1,this.scene=new e.Scene,this.scene.background=null,this.tinyTarget=new e.WebGLRenderTarget(1,1),this.buffer1Active=!1,this.firstUpdate=!0,this.warned=!1;const r=/(Android|iPad|iPhone|iPod)/g.test(navigator.userAgent)?alfFloatType:e.FloatType;this.progressiveLightMap1=new e.WebGLRenderTarget(this.res,this.res,{type:r}),this.progressiveLightMap2=new e.WebGLRenderTarget(this.res,this.res,{type:r}),this.uvMat=new e.MeshPhongMaterial,this.uvMat.uniforms={},this.uvMat.onBeforeCompile=e=>{e.vertexShader="#define USE_LIGHTMAP\n"+e.vertexShader.slice(0,-1)+"\tgl_Position = vec4((uv2 - 0.5) * 2.0, 1.0, 1.0); }";const t=e.fragmentShader.indexOf("void main() {");e.fragmentShader="varying vec2 vUv2;\n"+e.fragmentShader.slice(0,t)+"\tuniform sampler2D previousShadowMap;\n\tuniform float averagingWindow;\n"+e.fragmentShader.slice(t-1,-1)+"\nvec3 texelOld = texture2D(previousShadowMap, vUv2).rgb;\n\t\t\t\tgl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/averagingWindow);\n\t\t\t}",e.uniforms.previousShadowMap={value:this.progressiveLightMap1.texture},e.uniforms.averagingWindow={value:100},this.uvMat.uniforms=e.uniforms,this.uvMat.userData.shader=e,this.compiled=!0}}addObjectsToLightMap(e){this.uv_boxes=[];const t=3/this.res;for(let i=0;i<e.length;i++){const r=e[i];r.isLight?this.scene.attach(r):r.geometry.hasAttribute("uv")?(null==this.blurringPlane&&this._initializeBlurPlane(this.res,this.progressiveLightMap1),r.material.lightMap=this.progressiveLightMap2.texture,r.material.dithering=!0,r.castShadow=!0,r.receiveShadow=!0,r.renderOrder=1e3+i,this.uv_boxes.push({w:1+2*t,h:1+2*t,index:i}),this.lightMapContainers.push({basicMat:r.material,object:r}),this.compiled=!1):console.warn("All lightmap objects need UVs!")}const r=i.default(this.uv_boxes);this.uv_boxes.forEach((i=>{const s=e[i.index].geometry.getAttribute("uv").clone();for(let e=0;e<s.array.length;e+=s.itemSize)s.array[e]=(s.array[e]+i.x+t)/r.w,s.array[e+1]=(s.array[e+1]+i.y+t)/r.h;e[i.index].geometry.setAttribute("uv2",s),e[i.index].geometry.getAttribute("uv2").needsUpdate=!0}))}update(e,t=100,i=!0){if(null==this.blurringPlane)return;const r=this.renderer.getRenderTarget();this.blurringPlane.visible=i;for(let e=0;e<this.lightMapContainers.length;e++)this.lightMapContainers[e].object.oldScene=this.lightMapContainers[e].object.parent,this.scene.attach(this.lightMapContainers[e].object);this.firstUpdate&&(this.renderer.setRenderTarget(this.tinyTarget),this.renderer.render(this.scene,e),this.firstUpdate=!1);for(let e=0;e<this.lightMapContainers.length;e++)this.uvMat.uniforms.averagingWindow={value:t},this.lightMapContainers[e].object.material=this.uvMat,this.lightMapContainers[e].object.oldFrustumCulled=this.lightMapContainers[e].object.frustumCulled,this.lightMapContainers[e].object.frustumCulled=!1;const s=this.buffer1Active?this.progressiveLightMap1:this.progressiveLightMap2,a=this.buffer1Active?this.progressiveLightMap2:this.progressiveLightMap1;this.renderer.setRenderTarget(s),this.uvMat.uniforms.previousShadowMap={value:a.texture},this.blurringPlane.material.uniforms.previousShadowMap={value:a.texture},this.buffer1Active=!this.buffer1Active,this.renderer.render(this.scene,e);for(let e=0;e<this.lightMapContainers.length;e++)this.lightMapContainers[e].object.frustumCulled=this.lightMapContainers[e].object.oldFrustumCulled,this.lightMapContainers[e].object.material=this.lightMapContainers[e].basicMat,this.lightMapContainers[e].object.oldScene.attach(this.lightMapContainers[e].object);this.renderer.setRenderTarget(r)}showDebugLightmap(t,i){0!=this.lightMapContainers.length?(null==this.labelMesh&&(this.labelMaterial=new e.MeshBasicMaterial({map:this.progressiveLightMap1.texture,side:e.DoubleSide}),this.labelPlane=new e.PlaneGeometry(100,100),this.labelMesh=new e.Mesh(this.labelPlane,this.labelMaterial),this.labelMesh.position.y=250,this.lightMapContainers[0].object.parent.add(this.labelMesh)),null!=i&&this.labelMesh.position.copy(i),this.labelMesh.visible=t):this.warned||(console.warn("Call this after adding the objects!"),this.warned=!0)}_initializeBlurPlane(t,i=null){const r=new e.MeshBasicMaterial;r.uniforms={previousShadowMap:{value:null},pixelOffset:{value:1/t},polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:3},r.onBeforeCompile=e=>{e.vertexShader="#define USE_UV\n"+e.vertexShader.slice(0,-1)+"\tgl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }";const s=e.fragmentShader.indexOf("void main() {");e.fragmentShader="#define USE_UV\n"+e.fragmentShader.slice(0,s)+"\tuniform sampler2D previousShadowMap;\n\tuniform float pixelOffset;\n"+e.fragmentShader.slice(s-1,-1)+"\tgl_FragColor.rgb = (\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, 0.0 )).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( 0.0 , pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( 0.0 , -pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, 0.0 )).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, -pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, -pixelOffset)).rgb)/8.0;\n\t\t}",e.uniforms.previousShadowMap={value:i.texture},e.uniforms.pixelOffset={value:.5/t},r.uniforms=e.uniforms,r.userData.shader=e,this.compiled=!0},this.blurringPlane=new e.Mesh(new e.PlaneGeometry(1,1),r),this.blurringPlane.name="Blurring Plane",this.blurringPlane.frustumCulled=!1,this.blurringPlane.renderOrder=0,this.blurringPlane.material.depthWrite=!1,this.scene.add(this.blurringPlane)}};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Scene, WebGLRenderTarget, FloatType, MeshPhongMaterial, MeshBasicMaterial, DoubleSide, PlaneGeometry, Mesh
|
1
|
+
import { Scene, WebGLRenderTarget, FloatType, MeshPhongMaterial, MeshBasicMaterial, DoubleSide, PlaneGeometry, Mesh } from 'three';
|
2
2
|
import potpack from 'potpack';
|
3
3
|
|
4
4
|
/**
|
@@ -272,7 +272,7 @@ class ProgressiveLightMap {
|
|
272
272
|
this.compiled = true;
|
273
273
|
};
|
274
274
|
|
275
|
-
this.blurringPlane = new Mesh(new
|
275
|
+
this.blurringPlane = new Mesh(new PlaneGeometry(1, 1), blurMaterial);
|
276
276
|
this.blurringPlane.name = 'Blurring Plane';
|
277
277
|
this.blurringPlane.frustumCulled = false;
|
278
278
|
this.blurringPlane.renderOrder = 0;
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class n extends e.Mesh{constructor(n,o){var t,r;const i=(a=n)&&a.isCubeTexture;var a;const c=(null!=(t=i?null===(r=n.image[0])||void 0===r?void 0:r.width:n.image.width)?t:1024)/4,s=Math.floor(Math.log2(c)),l=Math.pow(2,s),d=[i?"#define ENVMAP_TYPE_CUBE":"","#define CUBEUV_TEXEL_WIDTH "+1/(3*Math.max(l,112)),"#define CUBEUV_TEXEL_HEIGHT "+1/(4*l),`#define CUBEUV_MAX_MIP ${s}.0`].join("\n")+"\n #define ENVMAP_TYPE_CUBE_UV\n varying vec3 vWorldPosition;\n uniform float radius;\n uniform float height;\n uniform float angle;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube map;\n #else\n uniform sampler2D map;\n #endif\n // From: https://www.shadertoy.com/view/4tsBD7\n float diskIntersectWithBackFaceCulling( vec3 ro, vec3 rd, vec3 c, vec3 n, float r ) \n {\n float d = dot ( rd, n );\n \n if( d > 0.0 ) { return 1e6; }\n \n vec3 o = ro - c;\n float t = - dot( n, o ) / d;\n vec3 q = o + rd * t;\n \n return ( dot( q, q ) < r * r ) ? t : 1e6;\n }\n // From: https://www.iquilezles.org/www/articles/intersectors/intersectors.htm\n float sphereIntersect( vec3 ro, vec3 rd, vec3 ce, float ra ) \n {\n vec3 oc = ro - ce;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - ra * ra;\n float h = b * b - c;\n \n if( h < 0.0 ) { return -1.0; }\n \n h = sqrt( h );\n \n return - b + h;\n }\n vec3 project() \n {\n vec3 p = normalize( vWorldPosition );\n vec3 camPos = cameraPosition;\n camPos.y -= height;\n float intersection = sphereIntersect( camPos, p, vec3( 0.0 ), radius );\n if( intersection > 0.0 ) {\n \n vec3 h = vec3( 0.0, - height, 0.0 );\n float intersection2 = diskIntersectWithBackFaceCulling( camPos, p, h, vec3( 0.0, 1.0, 0.0 ), radius );\n p = ( camPos + min( intersection, intersection2 ) * p ) / radius;\n } else {\n p = vec3( 0.0, 1.0, 0.0 );\n }\n return p;\n }\n #include <common>\n #include <cube_uv_reflection_fragment>\n void main() \n {\n vec3 projectedWorldPosition = project();\n \n #ifdef ENVMAP_TYPE_CUBE\n vec3 outcolor = textureCube( map, projectedWorldPosition ).rgb;\n #else\n vec3 direction = normalize( projectedWorldPosition );\n vec2 uv = equirectUv( direction );\n vec3 outcolor = texture2D( map, uv ).rgb;\n #endif\n gl_FragColor = vec4( outcolor, 1.0 );\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }\n ",u={map:{value:n},height:{value:(null==o?void 0:o.height)||15},radius:{value:(null==o?void 0:o.radius)||100}};super(new e.IcosahedronGeometry(1,16),new e.ShaderMaterial({uniforms:u,fragmentShader:d,vertexShader:"\n varying vec3 vWorldPosition;\n void main() \n {\n vec4 worldPosition = ( modelMatrix * vec4( position, 1.0 ) );\n vWorldPosition = worldPosition.xyz;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n ",side:e.DoubleSide}))}set radius(e){this.material.uniforms.radius.value=e}get radius(){return this.material.uniforms.radius.value}set height(e){this.material.uniforms.height.value=e}get height(){return this.material.uniforms.height.value}}exports.GroundProjectedEnv=n;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Mesh, ShaderMaterial, Texture, CubeTexture, BufferGeometry } from 'three';
|
2
|
+
export interface GroundProjectedEnvParameters {
|
3
|
+
height?: number;
|
4
|
+
radius?: number;
|
5
|
+
}
|
6
|
+
export declare class GroundProjectedEnv extends Mesh<BufferGeometry, ShaderMaterial> {
|
7
|
+
constructor(texture: CubeTexture | Texture, options?: GroundProjectedEnvParameters);
|
8
|
+
set radius(radius: number);
|
9
|
+
get radius(): number;
|
10
|
+
set height(height: number);
|
11
|
+
get height(): number;
|
12
|
+
}
|
@@ -0,0 +1,145 @@
|
|
1
|
+
import { Mesh, IcosahedronGeometry, ShaderMaterial, DoubleSide } from 'three';
|
2
|
+
|
3
|
+
const isCubeTexture = def => def && def.isCubeTexture;
|
4
|
+
|
5
|
+
class GroundProjectedEnv extends Mesh {
|
6
|
+
constructor(texture, options) {
|
7
|
+
var _ref, _texture$image$;
|
8
|
+
|
9
|
+
const isCubeMap = isCubeTexture(texture);
|
10
|
+
const w = (_ref = isCubeMap ? (_texture$image$ = texture.image[0]) === null || _texture$image$ === void 0 ? void 0 : _texture$image$.width : texture.image.width) != null ? _ref : 1024;
|
11
|
+
const cubeSize = w / 4;
|
12
|
+
|
13
|
+
const _lodMax = Math.floor(Math.log2(cubeSize));
|
14
|
+
|
15
|
+
const _cubeSize = Math.pow(2, _lodMax);
|
16
|
+
|
17
|
+
const width = 3 * Math.max(_cubeSize, 16 * 7);
|
18
|
+
const height = 4 * _cubeSize;
|
19
|
+
const defines = [isCubeMap ? '#define ENVMAP_TYPE_CUBE' : '', `#define CUBEUV_TEXEL_WIDTH ${1.0 / width}`, `#define CUBEUV_TEXEL_HEIGHT ${1.0 / height}`, `#define CUBEUV_MAX_MIP ${_lodMax}.0`];
|
20
|
+
const vertexShader =
|
21
|
+
/* glsl */
|
22
|
+
`
|
23
|
+
varying vec3 vWorldPosition;
|
24
|
+
void main()
|
25
|
+
{
|
26
|
+
vec4 worldPosition = ( modelMatrix * vec4( position, 1.0 ) );
|
27
|
+
vWorldPosition = worldPosition.xyz;
|
28
|
+
|
29
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
30
|
+
}
|
31
|
+
`;
|
32
|
+
const fragmentShader = defines.join('\n') +
|
33
|
+
/* glsl */
|
34
|
+
`
|
35
|
+
#define ENVMAP_TYPE_CUBE_UV
|
36
|
+
varying vec3 vWorldPosition;
|
37
|
+
uniform float radius;
|
38
|
+
uniform float height;
|
39
|
+
uniform float angle;
|
40
|
+
#ifdef ENVMAP_TYPE_CUBE
|
41
|
+
uniform samplerCube map;
|
42
|
+
#else
|
43
|
+
uniform sampler2D map;
|
44
|
+
#endif
|
45
|
+
// From: https://www.shadertoy.com/view/4tsBD7
|
46
|
+
float diskIntersectWithBackFaceCulling( vec3 ro, vec3 rd, vec3 c, vec3 n, float r )
|
47
|
+
{
|
48
|
+
float d = dot ( rd, n );
|
49
|
+
|
50
|
+
if( d > 0.0 ) { return 1e6; }
|
51
|
+
|
52
|
+
vec3 o = ro - c;
|
53
|
+
float t = - dot( n, o ) / d;
|
54
|
+
vec3 q = o + rd * t;
|
55
|
+
|
56
|
+
return ( dot( q, q ) < r * r ) ? t : 1e6;
|
57
|
+
}
|
58
|
+
// From: https://www.iquilezles.org/www/articles/intersectors/intersectors.htm
|
59
|
+
float sphereIntersect( vec3 ro, vec3 rd, vec3 ce, float ra )
|
60
|
+
{
|
61
|
+
vec3 oc = ro - ce;
|
62
|
+
float b = dot( oc, rd );
|
63
|
+
float c = dot( oc, oc ) - ra * ra;
|
64
|
+
float h = b * b - c;
|
65
|
+
|
66
|
+
if( h < 0.0 ) { return -1.0; }
|
67
|
+
|
68
|
+
h = sqrt( h );
|
69
|
+
|
70
|
+
return - b + h;
|
71
|
+
}
|
72
|
+
vec3 project()
|
73
|
+
{
|
74
|
+
vec3 p = normalize( vWorldPosition );
|
75
|
+
vec3 camPos = cameraPosition;
|
76
|
+
camPos.y -= height;
|
77
|
+
float intersection = sphereIntersect( camPos, p, vec3( 0.0 ), radius );
|
78
|
+
if( intersection > 0.0 ) {
|
79
|
+
|
80
|
+
vec3 h = vec3( 0.0, - height, 0.0 );
|
81
|
+
float intersection2 = diskIntersectWithBackFaceCulling( camPos, p, h, vec3( 0.0, 1.0, 0.0 ), radius );
|
82
|
+
p = ( camPos + min( intersection, intersection2 ) * p ) / radius;
|
83
|
+
} else {
|
84
|
+
p = vec3( 0.0, 1.0, 0.0 );
|
85
|
+
}
|
86
|
+
return p;
|
87
|
+
}
|
88
|
+
#include <common>
|
89
|
+
#include <cube_uv_reflection_fragment>
|
90
|
+
void main()
|
91
|
+
{
|
92
|
+
vec3 projectedWorldPosition = project();
|
93
|
+
|
94
|
+
#ifdef ENVMAP_TYPE_CUBE
|
95
|
+
vec3 outcolor = textureCube( map, projectedWorldPosition ).rgb;
|
96
|
+
#else
|
97
|
+
vec3 direction = normalize( projectedWorldPosition );
|
98
|
+
vec2 uv = equirectUv( direction );
|
99
|
+
vec3 outcolor = texture2D( map, uv ).rgb;
|
100
|
+
#endif
|
101
|
+
gl_FragColor = vec4( outcolor, 1.0 );
|
102
|
+
#include <tonemapping_fragment>
|
103
|
+
#include <encodings_fragment>
|
104
|
+
}
|
105
|
+
`;
|
106
|
+
const uniforms = {
|
107
|
+
map: {
|
108
|
+
value: texture
|
109
|
+
},
|
110
|
+
height: {
|
111
|
+
value: (options === null || options === void 0 ? void 0 : options.height) || 15
|
112
|
+
},
|
113
|
+
radius: {
|
114
|
+
value: (options === null || options === void 0 ? void 0 : options.radius) || 100
|
115
|
+
}
|
116
|
+
};
|
117
|
+
const geometry = new IcosahedronGeometry(1, 16);
|
118
|
+
const material = new ShaderMaterial({
|
119
|
+
uniforms,
|
120
|
+
fragmentShader,
|
121
|
+
vertexShader,
|
122
|
+
side: DoubleSide
|
123
|
+
});
|
124
|
+
super(geometry, material);
|
125
|
+
}
|
126
|
+
|
127
|
+
set radius(radius) {
|
128
|
+
this.material.uniforms.radius.value = radius;
|
129
|
+
}
|
130
|
+
|
131
|
+
get radius() {
|
132
|
+
return this.material.uniforms.radius.value;
|
133
|
+
}
|
134
|
+
|
135
|
+
set height(height) {
|
136
|
+
this.material.uniforms.height.value = height;
|
137
|
+
}
|
138
|
+
|
139
|
+
get height() {
|
140
|
+
return this.material.uniforms.height.value;
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
export { GroundProjectedEnv };
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("three"),o=require("./XRHandMeshModel.cjs.js");function
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("three"),o=require("./XRHandMeshModel.cjs.js");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("../loaders/GLTFLoader.cjs.js");var n=r(e);class s extends t.Object3D{constructor(e,t,r){super(),n.default(this,"controller",void 0),n.default(this,"motionController",void 0),n.default(this,"envMap",void 0),n.default(this,"mesh",void 0),n.default(this,"xrInputSource",void 0),this.controller=e,this.motionController=null,this.envMap=null,this.mesh=null,this.xrInputSource=null,e.addEventListener("connected",(n=>{const s=n.data;s.hand&&!this.motionController&&(this.xrInputSource=s,this.motionController=new o.XRHandMeshModel(this,e,void 0,s.handedness,"left"===s.handedness?t:r))})),e.addEventListener("disconnected",(()=>{this.dispose()}))}updateMatrixWorld(e){super.updateMatrixWorld(e),this.motionController&&this.motionController.updateMesh()}getPointerPosition(){const e=this.controller.joints["index-finger-tip"];return e?e.position:null}intersectBoxObject(e){const o=this.getPointerPosition();if(o){const r=new t.Sphere(o,.01),n=(new t.Box3).setFromObject(e);return r.intersectsBox(n)}return!1}checkButton(e){this.intersectBoxObject(e)?e.onPress():e.onClear(),e.isPressed()&&e.whilePressed()}dispose(){this.clear(),this.motionController=null}}exports.OculusHandModel=s;
|
@@ -12,7 +12,7 @@ declare class OculusHandModel extends Object3D {
|
|
12
12
|
envMap: Texture | null;
|
13
13
|
mesh: Mesh | null;
|
14
14
|
xrInputSource: XRInputSource | null;
|
15
|
-
constructor(controller: Object3D,
|
15
|
+
constructor(controller: Object3D, leftModelPath?: string, rightModelPath?: string);
|
16
16
|
updateMatrixWorld(force?: boolean): void;
|
17
17
|
getPointerPosition(): Vector3 | null;
|
18
18
|
intersectBoxObject(boxObject: Object3D): boolean;
|
package/webxr/OculusHandModel.js
CHANGED
@@ -6,7 +6,7 @@ const TOUCH_RADIUS = 0.01;
|
|
6
6
|
const POINTING_JOINT = 'index-finger-tip';
|
7
7
|
|
8
8
|
class OculusHandModel extends Object3D {
|
9
|
-
constructor(controller,
|
9
|
+
constructor(controller, leftModelPath, rightModelPath) {
|
10
10
|
super();
|
11
11
|
|
12
12
|
_defineProperty(this, "controller", void 0);
|
@@ -29,7 +29,7 @@ class OculusHandModel extends Object3D {
|
|
29
29
|
|
30
30
|
if (xrInputSource.hand && !this.motionController) {
|
31
31
|
this.xrInputSource = xrInputSource;
|
32
|
-
this.motionController = new XRHandMeshModel(this, controller, undefined, xrInputSource.handedness, xrInputSource.handedness === 'left' ?
|
32
|
+
this.motionController = new XRHandMeshModel(this, controller, undefined, xrInputSource.handedness, xrInputSource.handedness === 'left' ? leftModelPath : rightModelPath);
|
33
33
|
}
|
34
34
|
});
|
35
35
|
controller.addEventListener('disconnected', () => {
|
@@ -3,7 +3,7 @@ declare class XRHandMeshModel {
|
|
3
3
|
controller: Object3D;
|
4
4
|
handModel: Object3D;
|
5
5
|
bones: Object3D[];
|
6
|
-
constructor(handModel: Object3D, controller: Object3D, path: string | undefined, handedness: string,
|
6
|
+
constructor(handModel: Object3D, controller: Object3D, path: string | undefined, handedness: string, customModelPath?: string);
|
7
7
|
updateMesh(): void;
|
8
8
|
}
|
9
9
|
export { XRHandMeshModel };
|
package/webxr/XRHandMeshModel.js
CHANGED
@@ -4,7 +4,7 @@ import { GLTFLoader } from '../loaders/GLTFLoader.js';
|
|
4
4
|
const DEFAULT_HAND_PROFILE_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/';
|
5
5
|
|
6
6
|
class XRHandMeshModel {
|
7
|
-
constructor(handModel, controller, path = DEFAULT_HAND_PROFILE_PATH, handedness,
|
7
|
+
constructor(handModel, controller, path = DEFAULT_HAND_PROFILE_PATH, handedness, customModelPath) {
|
8
8
|
_defineProperty(this, "controller", void 0);
|
9
9
|
|
10
10
|
_defineProperty(this, "handModel", void 0);
|
@@ -15,8 +15,8 @@ class XRHandMeshModel {
|
|
15
15
|
this.handModel = handModel;
|
16
16
|
this.bones = [];
|
17
17
|
const loader = new GLTFLoader();
|
18
|
-
if (!
|
19
|
-
loader.load(
|
18
|
+
if (!customModelPath) loader.setPath(path);
|
19
|
+
loader.load(customModelPath != null ? customModelPath : `${handedness}.glb`, gltf => {
|
20
20
|
const object = gltf.scene.children[0];
|
21
21
|
this.handModel.add(object);
|
22
22
|
const mesh = object.getObjectByProperty('type', 'SkinnedMesh');
|