@p100-web/core-three 100.0.62 → 100.0.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/App.d.ts +40 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +171 -0
- package/dist/App.js.map +1 -0
- package/dist/ComponentFactory.d.ts +5 -0
- package/dist/ComponentFactory.d.ts.map +1 -0
- package/dist/ComponentFactory.js +17 -0
- package/dist/ComponentFactory.js.map +1 -0
- package/dist/PCanvas.d.ts +171 -0
- package/dist/PCanvas.d.ts.map +1 -0
- package/dist/PCanvas.js +992 -0
- package/dist/PCanvas.js.map +1 -0
- package/dist/ThreeEngine.d.ts +25 -0
- package/dist/ThreeEngine.d.ts.map +1 -0
- package/dist/ThreeEngine.js +102 -0
- package/dist/ThreeEngine.js.map +1 -0
- package/dist/ThreeNodeRenderer.d.ts +32 -0
- package/dist/ThreeNodeRenderer.d.ts.map +1 -0
- package/dist/ThreeNodeRenderer.js +87 -0
- package/dist/ThreeNodeRenderer.js.map +1 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/media/AudioLoader.d.ts +32 -0
- package/dist/media/AudioLoader.d.ts.map +1 -0
- package/dist/media/AudioLoader.js +110 -0
- package/dist/media/AudioLoader.js.map +1 -0
- package/dist/media/EnvironmentLoader.d.ts +40 -0
- package/dist/media/EnvironmentLoader.d.ts.map +1 -0
- package/dist/media/EnvironmentLoader.js +120 -0
- package/dist/media/EnvironmentLoader.js.map +1 -0
- package/dist/media/ImageLoader.d.ts +36 -0
- package/dist/media/ImageLoader.d.ts.map +1 -0
- package/dist/media/ImageLoader.js +160 -0
- package/dist/media/ImageLoader.js.map +1 -0
- package/dist/media/MediaLoader.d.ts +14 -0
- package/dist/media/MediaLoader.d.ts.map +1 -0
- package/dist/media/MediaLoader.js +70 -0
- package/dist/media/MediaLoader.js.map +1 -0
- package/dist/media/ModelLoader.d.ts +49 -0
- package/dist/media/ModelLoader.d.ts.map +1 -0
- package/dist/media/ModelLoader.js +223 -0
- package/dist/media/ModelLoader.js.map +1 -0
- package/dist/media/VideoLoader.d.ts +35 -0
- package/dist/media/VideoLoader.d.ts.map +1 -0
- package/dist/media/VideoLoader.js +105 -0
- package/dist/media/VideoLoader.js.map +1 -0
- package/dist/pcomponents/PAnimator.d.ts +24 -0
- package/dist/pcomponents/PAnimator.d.ts.map +1 -0
- package/dist/pcomponents/PAnimator.js +129 -0
- package/dist/pcomponents/PAnimator.js.map +1 -0
- package/dist/pcomponents/PBasicMaterial.d.ts +17 -0
- package/dist/pcomponents/PBasicMaterial.d.ts.map +1 -0
- package/dist/pcomponents/PBasicMaterial.js +142 -0
- package/dist/pcomponents/PBasicMaterial.js.map +1 -0
- package/dist/pcomponents/PCollider.d.ts +11 -0
- package/dist/pcomponents/PCollider.d.ts.map +1 -0
- package/dist/pcomponents/PCollider.js +61 -0
- package/dist/pcomponents/PCollider.js.map +1 -0
- package/dist/pcomponents/PCubeGeometry.d.ts +8 -0
- package/dist/pcomponents/PCubeGeometry.d.ts.map +1 -0
- package/dist/pcomponents/PCubeGeometry.js +23 -0
- package/dist/pcomponents/PCubeGeometry.js.map +1 -0
- package/dist/pcomponents/PEnvironment.d.ts +14 -0
- package/dist/pcomponents/PEnvironment.d.ts.map +1 -0
- package/dist/pcomponents/PEnvironment.js +86 -0
- package/dist/pcomponents/PEnvironment.js.map +1 -0
- package/dist/pcomponents/PImageBackground.d.ts +14 -0
- package/dist/pcomponents/PImageBackground.d.ts.map +1 -0
- package/dist/pcomponents/PImageBackground.js +85 -0
- package/dist/pcomponents/PImageBackground.js.map +1 -0
- package/dist/pcomponents/PLight.d.ts +8 -0
- package/dist/pcomponents/PLight.d.ts.map +1 -0
- package/dist/pcomponents/PLight.js +22 -0
- package/dist/pcomponents/PLight.js.map +1 -0
- package/dist/pcomponents/PLightDirectional.d.ts +8 -0
- package/dist/pcomponents/PLightDirectional.d.ts.map +1 -0
- package/dist/pcomponents/PLightDirectional.js +36 -0
- package/dist/pcomponents/PLightDirectional.js.map +1 -0
- package/dist/pcomponents/PMaskedMaterial.d.ts +17 -0
- package/dist/pcomponents/PMaskedMaterial.d.ts.map +1 -0
- package/dist/pcomponents/PMaskedMaterial.js +214 -0
- package/dist/pcomponents/PMaskedMaterial.js.map +1 -0
- package/dist/pcomponents/PModelGLTF.d.ts +18 -0
- package/dist/pcomponents/PModelGLTF.d.ts.map +1 -0
- package/dist/pcomponents/PModelGLTF.js +98 -0
- package/dist/pcomponents/PModelGLTF.js.map +1 -0
- package/dist/pcomponents/PPhysicalMaterial.d.ts +13 -0
- package/dist/pcomponents/PPhysicalMaterial.d.ts.map +1 -0
- package/dist/pcomponents/PPhysicalMaterial.js +106 -0
- package/dist/pcomponents/PPhysicalMaterial.js.map +1 -0
- package/dist/pcomponents/PPlaneGeometry.d.ts +8 -0
- package/dist/pcomponents/PPlaneGeometry.d.ts.map +1 -0
- package/dist/pcomponents/PPlaneGeometry.js +23 -0
- package/dist/pcomponents/PPlaneGeometry.js.map +1 -0
- package/dist/pcomponents/PProjectRoot.d.ts +8 -0
- package/dist/pcomponents/PProjectRoot.d.ts.map +1 -0
- package/dist/pcomponents/PProjectRoot.js +24 -0
- package/dist/pcomponents/PProjectRoot.js.map +1 -0
- package/dist/pcomponents/PSlider.d.ts +16 -0
- package/dist/pcomponents/PSlider.d.ts.map +1 -0
- package/dist/pcomponents/PSlider.js +69 -0
- package/dist/pcomponents/PSlider.js.map +1 -0
- package/dist/pcomponents/PSound.d.ts +17 -0
- package/dist/pcomponents/PSound.d.ts.map +1 -0
- package/dist/pcomponents/PSound.js +110 -0
- package/dist/pcomponents/PSound.js.map +1 -0
- package/dist/pcomponents/PSphereGeometry.d.ts +9 -0
- package/dist/pcomponents/PSphereGeometry.d.ts.map +1 -0
- package/dist/pcomponents/PSphereGeometry.js +24 -0
- package/dist/pcomponents/PSphereGeometry.js.map +1 -0
- package/dist/pcomponents/PSprite.d.ts +14 -0
- package/dist/pcomponents/PSprite.d.ts.map +1 -0
- package/dist/pcomponents/PSprite.js +79 -0
- package/dist/pcomponents/PSprite.js.map +1 -0
- package/dist/pcomponents/PSpriteAnimation.d.ts +15 -0
- package/dist/pcomponents/PSpriteAnimation.d.ts.map +1 -0
- package/dist/pcomponents/PSpriteAnimation.js +80 -0
- package/dist/pcomponents/PSpriteAnimation.js.map +1 -0
- package/dist/pcomponents/PText.d.ts +10 -0
- package/dist/pcomponents/PText.d.ts.map +1 -0
- package/dist/pcomponents/PText.js +44 -0
- package/dist/pcomponents/PText.js.map +1 -0
- package/dist/pcomponents/PVideoBackground.d.ts +13 -0
- package/dist/pcomponents/PVideoBackground.d.ts.map +1 -0
- package/dist/pcomponents/PVideoBackground.js +85 -0
- package/dist/pcomponents/PVideoBackground.js.map +1 -0
- package/dist/pcomponents/PVideoPlayer.d.ts +5 -0
- package/dist/pcomponents/PVideoPlayer.d.ts.map +1 -0
- package/dist/pcomponents/PVideoPlayer.js +12 -0
- package/dist/pcomponents/PVideoPlayer.js.map +1 -0
- package/dist/pcomponents.d.ts +21 -21
- package/dist/pcomponents.d.ts.map +1 -1
- package/dist/pcomponents.js +21 -21
- package/dist/pcomponents.js.map +1 -1
- package/dist/postprocessing/PSSRPass.d.ts +19 -0
- package/dist/postprocessing/PSSRPass.d.ts.map +1 -0
- package/dist/postprocessing/PSSRPass.js +69 -0
- package/dist/postprocessing/PSSRPass.js.map +1 -0
- package/dist/postprocessing/ThreeJsPostProcessor.d.ts +32 -0
- package/dist/postprocessing/ThreeJsPostProcessor.d.ts.map +1 -0
- package/dist/postprocessing/ThreeJsPostProcessor.js +264 -0
- package/dist/postprocessing/ThreeJsPostProcessor.js.map +1 -0
- package/dist/three/ColliderObject3D.d.ts +19 -0
- package/dist/three/ColliderObject3D.d.ts.map +1 -0
- package/dist/three/ColliderObject3D.js +146 -0
- package/dist/three/ColliderObject3D.js.map +1 -0
- package/dist/three/FreeCameraControls.d.ts +30 -0
- package/dist/three/FreeCameraControls.d.ts.map +1 -0
- package/dist/three/FreeCameraControls.js +158 -0
- package/dist/three/FreeCameraControls.js.map +1 -0
- package/dist/three/OrbitCameraControls.d.ts +24 -0
- package/dist/three/OrbitCameraControls.d.ts.map +1 -0
- package/dist/three/OrbitCameraControls.js +81 -0
- package/dist/three/OrbitCameraControls.js.map +1 -0
- package/dist/three/VrCameraControls.d.ts +28 -0
- package/dist/three/VrCameraControls.d.ts.map +1 -0
- package/dist/three/VrCameraControls.js +124 -0
- package/dist/three/VrCameraControls.js.map +1 -0
- package/package.json +9 -4
- package/index.js +0 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { BackSide, FrontSide, Texture, SRGBColorSpace, VideoTexture, ShaderMaterial, Color, } from "three";
|
|
2
|
+
import { PMaskedMaterial as PMaskedMaterialBase } from "@p100-web/core";
|
|
3
|
+
import { FileType, FileSubType, } from "@p100-web/core";
|
|
4
|
+
export default class PMaskedMaterial extends PMaskedMaterialBase {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this._material = null;
|
|
8
|
+
this._cacheKey = 0;
|
|
9
|
+
}
|
|
10
|
+
getTexture() {
|
|
11
|
+
return this._material?.uniforms.map.value || null;
|
|
12
|
+
}
|
|
13
|
+
getMaterial() {
|
|
14
|
+
return this._material;
|
|
15
|
+
}
|
|
16
|
+
//
|
|
17
|
+
// PComponent
|
|
18
|
+
//
|
|
19
|
+
dispose() {
|
|
20
|
+
// Release files
|
|
21
|
+
if (this.file_texture)
|
|
22
|
+
this.context.releaseFile(this.file_texture);
|
|
23
|
+
}
|
|
24
|
+
_dispose(unrender) {
|
|
25
|
+
if (this.file_texture) {
|
|
26
|
+
if (this.file_texture.type === FileType.Image) {
|
|
27
|
+
this.context
|
|
28
|
+
.imageLoader()
|
|
29
|
+
.disposeImage(this, this.file_texture, this._cacheKey);
|
|
30
|
+
}
|
|
31
|
+
else if (this.file_texture.type === FileType.Video) {
|
|
32
|
+
// Notify any video player
|
|
33
|
+
const videoPlayer = this.node.findComponent("PVideoPlayer");
|
|
34
|
+
videoPlayer?.onDisposeMaterial();
|
|
35
|
+
this.context
|
|
36
|
+
.videoLoader()
|
|
37
|
+
.disposeVideo(this, this.file_texture);
|
|
38
|
+
}
|
|
39
|
+
this._cacheKey = 0;
|
|
40
|
+
}
|
|
41
|
+
// Check if we should dispose Material
|
|
42
|
+
if (this._material) {
|
|
43
|
+
// Do we have a texture as well?
|
|
44
|
+
if (this._material.uniforms.map.value) {
|
|
45
|
+
this._material.uniforms.map.value.dispose();
|
|
46
|
+
this._material.uniforms.map.value.source.data = null;
|
|
47
|
+
this._material.uniforms.map.value = null;
|
|
48
|
+
}
|
|
49
|
+
this._material.needsUpdate = true;
|
|
50
|
+
// Dispose material
|
|
51
|
+
if (unrender) {
|
|
52
|
+
this._material.dispose();
|
|
53
|
+
this._material = null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
unrender() {
|
|
58
|
+
this._dispose(true);
|
|
59
|
+
// Unregister as material for PNode
|
|
60
|
+
this.node.material = null;
|
|
61
|
+
}
|
|
62
|
+
render() {
|
|
63
|
+
// Register as material for PNode
|
|
64
|
+
this.node.material = this;
|
|
65
|
+
if (!this.node.hasEl()) {
|
|
66
|
+
this.context.error("Material is missing Mesh");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const mesh = this.node.getEl();
|
|
70
|
+
const material = createChromaKeyMaterial({
|
|
71
|
+
side: this.inverted ? BackSide : FrontSide,
|
|
72
|
+
opacity: this.opacity,
|
|
73
|
+
transparent: this.transparent,
|
|
74
|
+
fog: false,
|
|
75
|
+
wireframe: false,
|
|
76
|
+
alphaTest: this.alphaTest,
|
|
77
|
+
depthWrite: this.depthWrite,
|
|
78
|
+
});
|
|
79
|
+
// Set mask threshold
|
|
80
|
+
material.uniforms.keyThreshold.value = this.maskThreshold;
|
|
81
|
+
// Set mask softness
|
|
82
|
+
material.uniforms.keySoftness.value = this.maskSoftness;
|
|
83
|
+
// Set green screen color
|
|
84
|
+
material.uniforms.keyColor.value.set(this.maskColor);
|
|
85
|
+
this._material = material;
|
|
86
|
+
mesh.material = material;
|
|
87
|
+
mesh.renderOrder = this.renderOrder;
|
|
88
|
+
if (this.file_texture !== null) {
|
|
89
|
+
// Check which loader to use
|
|
90
|
+
if (this.file_texture.type === FileType.Image)
|
|
91
|
+
this.context
|
|
92
|
+
.imageLoader()
|
|
93
|
+
.load(this, this.file_texture);
|
|
94
|
+
else if (this.file_texture.type === FileType.Video)
|
|
95
|
+
this.context
|
|
96
|
+
.videoLoader()
|
|
97
|
+
.load(this, this.file_texture);
|
|
98
|
+
else
|
|
99
|
+
this.context.error("Unsuppotred material texture");
|
|
100
|
+
}
|
|
101
|
+
material.needsUpdate = true;
|
|
102
|
+
}
|
|
103
|
+
setTextureRepeat(file, texture) {
|
|
104
|
+
if (this._material) {
|
|
105
|
+
if (file.subType === FileSubType.Stereo) {
|
|
106
|
+
this._material.uniforms.stereoMultiplier.value = 0.5;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
this._material.uniforms.stereoMultiplier.value = 1;
|
|
110
|
+
}
|
|
111
|
+
texture.needsUpdate = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//
|
|
115
|
+
// IVideoLoader
|
|
116
|
+
//
|
|
117
|
+
onVideoLoaded(file, value) {
|
|
118
|
+
if (this._material === null) {
|
|
119
|
+
this.context.error("onVideoLoaded and material was null");
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const texture = new VideoTexture(value);
|
|
123
|
+
texture.colorSpace = SRGBColorSpace;
|
|
124
|
+
this.setTextureRepeat(file, texture);
|
|
125
|
+
this._material.uniforms.map.value = texture;
|
|
126
|
+
this._material.needsUpdate = true;
|
|
127
|
+
}
|
|
128
|
+
//
|
|
129
|
+
// IImageLoader
|
|
130
|
+
//
|
|
131
|
+
onImageLoaded(file, data, cacheKey) {
|
|
132
|
+
this._cacheKey = cacheKey;
|
|
133
|
+
if (this._material === null) {
|
|
134
|
+
this.context.error("onImageLoaded and material was null");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const texture = new Texture();
|
|
138
|
+
texture.userData.id = file._id;
|
|
139
|
+
texture.colorSpace = SRGBColorSpace;
|
|
140
|
+
texture.image = data;
|
|
141
|
+
this.setTextureRepeat(file, texture);
|
|
142
|
+
this._material.uniforms.map.value = texture;
|
|
143
|
+
this._material.needsUpdate = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function createChromaKeyMaterial(args) {
|
|
147
|
+
return new ShaderMaterial({
|
|
148
|
+
...args,
|
|
149
|
+
uniforms: {
|
|
150
|
+
map: { value: null }, // set later
|
|
151
|
+
keyColor: { value: new Color(0, 1, 0) }, // green screen
|
|
152
|
+
keyThreshold: { value: 0.0025 }, // squared threshold
|
|
153
|
+
keySoftness: { value: 0.001 }, // squared threshold
|
|
154
|
+
stereoMultiplier: { value: 1 }, // squared threshold
|
|
155
|
+
},
|
|
156
|
+
vertexShader: `
|
|
157
|
+
varying vec2 vUv;
|
|
158
|
+
void main() {
|
|
159
|
+
vUv = uv;
|
|
160
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
161
|
+
}
|
|
162
|
+
`,
|
|
163
|
+
fragmentShader: args.transparent
|
|
164
|
+
? `
|
|
165
|
+
uniform sampler2D map;
|
|
166
|
+
uniform vec3 keyColor;
|
|
167
|
+
uniform float keyThreshold;
|
|
168
|
+
uniform float keySoftness;
|
|
169
|
+
uniform float stereoMultiplier;
|
|
170
|
+
varying vec2 vUv;
|
|
171
|
+
|
|
172
|
+
void main() {
|
|
173
|
+
vec2 uv = vUv;
|
|
174
|
+
uv.y *= stereoMultiplier;
|
|
175
|
+
vec4 col = texture2D(map, uv);
|
|
176
|
+
|
|
177
|
+
// squared distance to key color
|
|
178
|
+
vec3 diff = col.rgb - keyColor;
|
|
179
|
+
float distSq = dot(diff, diff);
|
|
180
|
+
|
|
181
|
+
// Smooth alpha:
|
|
182
|
+
// distSq <= keyThreshold → fully transparent
|
|
183
|
+
// distSq >= keyThreshold+softness → fully opaque
|
|
184
|
+
float alpha = smoothstep(keyThreshold, keyThreshold + keySoftness, distSq);
|
|
185
|
+
|
|
186
|
+
// multiply original texture alpha as well
|
|
187
|
+
gl_FragColor = vec4(col.rgb, col.a * alpha);
|
|
188
|
+
}
|
|
189
|
+
`
|
|
190
|
+
: `
|
|
191
|
+
uniform sampler2D map;
|
|
192
|
+
uniform vec3 keyColor;
|
|
193
|
+
uniform float keyThreshold;
|
|
194
|
+
uniform float stereoMultiplier;
|
|
195
|
+
varying vec2 vUv;
|
|
196
|
+
|
|
197
|
+
void main() {
|
|
198
|
+
vec2 uv = vUv;
|
|
199
|
+
uv.y *= stereoMultiplier;
|
|
200
|
+
vec4 col = texture2D(map, uv);
|
|
201
|
+
|
|
202
|
+
// squared distance to key color
|
|
203
|
+
vec3 diff = col.rgb - keyColor;
|
|
204
|
+
float distSq = dot(diff, diff);
|
|
205
|
+
|
|
206
|
+
// branch-free alpha mask
|
|
207
|
+
if (distSq < keyThreshold) discard;
|
|
208
|
+
gl_FragColor = vec4(col.rgb, 1);
|
|
209
|
+
}
|
|
210
|
+
`,
|
|
211
|
+
//
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=PMaskedMaterial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PMaskedMaterial.js","sourceRoot":"","sources":["../../src/pcomponents/PMaskedMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EAET,OAAO,EACP,cAAc,EACd,YAAY,EACZ,cAAc,EACd,KAAK,GAEN,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAGL,QAAQ,EA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G,IAAI,CAAC,GAAG,CAAC;QAC/B,OAAO,CAAC,UAAU,GAAG,cAAc,CAAC;QACpC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;QAErB,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAErC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC;QAE5C,IAAI,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC;IACpC,CAAC;CACF;AAED,SAAS,uBAAuB,CAAC,IAA8B;IAC7D,OAAO,IAAI,cAAc,CAAC;QACxB,GAAG,IAAI;QACP,QAAQ,EAAE;YACR,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,YAAY;YAClC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,eAAe;YACxD,YAAY,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,oBAAoB;YACrD,WAAW,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,oBAAoB;YACnD,gBAAgB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,oBAAoB;SACrD;QACD,YAAY,EAAE;;;;;;KAMb;QACD,cAAc,EAAE,IAAI,CAAC,WAAW;YAC9B,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;KAyBH;YACC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;KAoBH;QACD,EAAE;KACH,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AnimationAction, AnimationMixer, Group, Mesh } from "three";
|
|
2
|
+
import { IAnimationAction, PModelGLTF as PModelGLTFBase } from "@p100-web/core";
|
|
3
|
+
import { IModelLoader, PFile } from "@p100-web/core";
|
|
4
|
+
import { IModel } from "../media/ModelLoader";
|
|
5
|
+
export default class PModelGLTF extends PModelGLTFBase implements IModelLoader {
|
|
6
|
+
el: Group | null;
|
|
7
|
+
mixer: AnimationMixer | null;
|
|
8
|
+
actions: AnimationAction[] | null;
|
|
9
|
+
protected _reflectors: Mesh[] | null;
|
|
10
|
+
unrender(): void;
|
|
11
|
+
render(): void;
|
|
12
|
+
getAnimationAction(clip: string): IAnimationAction | null;
|
|
13
|
+
/**
|
|
14
|
+
* Called when the object has finished loading
|
|
15
|
+
*/
|
|
16
|
+
onModelLoaded: (_file: PFile, model: IModel) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=PModelGLTF.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PModelGLTF.d.ts","sourceRoot":"","sources":["../../src/pcomponents/PModelGLTF.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,EAAY,MAAM,OAAO,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,YAAY,EAAkB,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,cAAe,YAAW,YAAY;IAC5E,EAAE,EAAE,KAAK,GAAG,IAAI,CAAQ;IAExB,KAAK,EAAE,cAAc,GAAG,IAAI,CAAQ;IACpC,OAAO,EAAE,eAAe,EAAE,GAAG,IAAI,CAAQ;IAEzC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,IAAI,CAAQ;IAE5C,QAAQ;IAkBR,MAAM;IAaN,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI;IAYzD;;OAEG;IACH,aAAa,GAAU,OAAO,KAAK,EAAE,OAAO,MAAM,mBAuDhD;CACH"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Group } from "three";
|
|
2
|
+
import { PModelGLTF as PModelGLTFBase } from "@p100-web/core";
|
|
3
|
+
export default class PModelGLTF extends PModelGLTFBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.el = null;
|
|
7
|
+
this.mixer = null;
|
|
8
|
+
this.actions = null;
|
|
9
|
+
this._reflectors = null;
|
|
10
|
+
//
|
|
11
|
+
// IModelLoader
|
|
12
|
+
//
|
|
13
|
+
/**
|
|
14
|
+
* Called when the object has finished loading
|
|
15
|
+
*/
|
|
16
|
+
this.onModelLoaded = async (_file, model) => {
|
|
17
|
+
// await this.parseGLTF(model);
|
|
18
|
+
if (!this.node.hasEl())
|
|
19
|
+
throw new Error("Missing el");
|
|
20
|
+
if (model.actions && model.actions.length) {
|
|
21
|
+
this.mixer = model.mixer;
|
|
22
|
+
this.actions = model.actions;
|
|
23
|
+
}
|
|
24
|
+
this.el = model.modelScene;
|
|
25
|
+
this.node.getEl().add(model.modelScene);
|
|
26
|
+
// Process model
|
|
27
|
+
if (this.forceDepthWrite || this.reflector) {
|
|
28
|
+
let composer = null;
|
|
29
|
+
// Setup custom reflectors
|
|
30
|
+
if (this.reflector) {
|
|
31
|
+
composer = this.context.getPCanvas().getComposer();
|
|
32
|
+
this._reflectors = [];
|
|
33
|
+
}
|
|
34
|
+
model.modelScene.traverse((node) => {
|
|
35
|
+
if (node.material) {
|
|
36
|
+
const material = node.material;
|
|
37
|
+
if (this.reflector) {
|
|
38
|
+
if (node.userData.REFL) {
|
|
39
|
+
this._reflectors?.push(node);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (this.forceDepthWrite &&
|
|
43
|
+
material.transparent &&
|
|
44
|
+
!material.depthWrite) {
|
|
45
|
+
material.depthWrite = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (this._reflectors?.length === 0)
|
|
50
|
+
this._reflectors = null;
|
|
51
|
+
if (composer && this._reflectors) {
|
|
52
|
+
composer.addSSRSelectors(this._reflectors);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (this.node.collider !== null) {
|
|
56
|
+
this.node.collider.computeBounds();
|
|
57
|
+
}
|
|
58
|
+
if (!this.context.editor) {
|
|
59
|
+
this.outevent_onLoaded?.emit(null, this);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
unrender() {
|
|
64
|
+
this.mixer = null;
|
|
65
|
+
this.actions = null;
|
|
66
|
+
if (this._reflectors) {
|
|
67
|
+
const composer = this.context.getPCanvas().getComposer();
|
|
68
|
+
composer?.removeSSRSelectors(this._reflectors);
|
|
69
|
+
this._reflectors = null;
|
|
70
|
+
}
|
|
71
|
+
if (this.el !== null) {
|
|
72
|
+
this.context.modelLoader().disposeModel(this, this.el);
|
|
73
|
+
this.el = null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// getAction(name: string): AnimationAction | null {}
|
|
77
|
+
render() {
|
|
78
|
+
if (this.file_model !== null) {
|
|
79
|
+
this.node.set_el(new Group(), false);
|
|
80
|
+
if (!this.context.modelLoader().load(this, this.file_model)) {
|
|
81
|
+
this.context.error("File type not supported");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//
|
|
86
|
+
// ANIMATIONS
|
|
87
|
+
//
|
|
88
|
+
getAnimationAction(clip) {
|
|
89
|
+
if (this.actions === null)
|
|
90
|
+
return null;
|
|
91
|
+
for (const action of this.actions) {
|
|
92
|
+
if (action.getClip().name === clip)
|
|
93
|
+
return action;
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=PModelGLTF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PModelGLTF.js","sourceRoot":"","sources":["../../src/pcomponents/PModelGLTF.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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
|
+
import { IImageLoader, PFile } from "@p100-web/core";
|
|
4
|
+
export default class PPhysicalMaterial extends PPhysicalMaterialBase implements IImageLoader {
|
|
5
|
+
protected _material: MeshStandardMaterial | null;
|
|
6
|
+
_cacheKey: number;
|
|
7
|
+
setTextureRepeat(): void;
|
|
8
|
+
_dispose(unrender: boolean): void;
|
|
9
|
+
render(): void;
|
|
10
|
+
callback_setOpacity: (payloadValue: string | null) => void;
|
|
11
|
+
onImageLoaded(file: PFile, data: any, cacheKey: number): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=PPhysicalMaterial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PPhysicalMaterial.d.ts","sourceRoot":"","sources":["../../src/pcomponents/PPhysicalMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,oBAAoB,EAKrB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,iBAAiB,IAAI,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAe,YAAY,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAElE,MAAM,CAAC,OAAO,OAAO,iBACnB,SAAQ,qBACR,YAAW,YAAY;IAEvB,SAAS,CAAC,SAAS,EAAE,oBAAoB,GAAG,IAAI,CAAQ;IACxD,SAAS,SAAK;IAEd,gBAAgB;IAgBhB,QAAQ,CAAC,QAAQ,EAAE,OAAO;IA0B1B,MAAM;IAwCN,mBAAmB,GAAI,cAAc,MAAM,GAAG,IAAI,UAKhD;IAMF,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;CAmB9D"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { BackSide, ClampToEdgeWrapping, DoubleSide, FrontSide, MeshStandardMaterial, RepeatWrapping, Texture, Vector2, SRGBColorSpace, } from "three";
|
|
2
|
+
import { PPhysicalMaterial as PPhysicalMaterialBase } from "@p100-web/core";
|
|
3
|
+
import { FileSubType } from "@p100-web/core";
|
|
4
|
+
export default class PPhysicalMaterial extends PPhysicalMaterialBase {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this._material = null;
|
|
8
|
+
this._cacheKey = 0;
|
|
9
|
+
//
|
|
10
|
+
// Event Callbacks
|
|
11
|
+
//
|
|
12
|
+
this.callback_setOpacity = (payloadValue) => {
|
|
13
|
+
if (this._material && payloadValue) {
|
|
14
|
+
const opacity = parseFloat(payloadValue);
|
|
15
|
+
this._material.opacity = opacity;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
setTextureRepeat() {
|
|
20
|
+
const texture = this._material?.map || null;
|
|
21
|
+
if (texture !== null) {
|
|
22
|
+
texture.wrapS = this.repeat.x > 1 ? RepeatWrapping : ClampToEdgeWrapping;
|
|
23
|
+
texture.wrapT = this.repeat.y > 1 ? RepeatWrapping : ClampToEdgeWrapping;
|
|
24
|
+
texture.repeat = new Vector2(this.repeat.x || 1, this.repeat.y || 1);
|
|
25
|
+
texture.offset = new Vector2(this.offset.x, this.offset.y);
|
|
26
|
+
if (this._material)
|
|
27
|
+
this._material.needsUpdate = true;
|
|
28
|
+
texture.needsUpdate = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//
|
|
32
|
+
// PComponent
|
|
33
|
+
//
|
|
34
|
+
_dispose(unrender) {
|
|
35
|
+
if (this.file_texture) {
|
|
36
|
+
this.context
|
|
37
|
+
.imageLoader()
|
|
38
|
+
.disposeImage(this, this.file_texture, this._cacheKey);
|
|
39
|
+
this._cacheKey = 0;
|
|
40
|
+
}
|
|
41
|
+
// Check if we should dispose Material
|
|
42
|
+
if (this._material) {
|
|
43
|
+
// Do we have a texture as well?
|
|
44
|
+
if (this._material.map) {
|
|
45
|
+
this._material.map.dispose();
|
|
46
|
+
this._material.map = null;
|
|
47
|
+
}
|
|
48
|
+
this._material.needsUpdate = true;
|
|
49
|
+
// Dispose material
|
|
50
|
+
if (unrender) {
|
|
51
|
+
this._material.dispose();
|
|
52
|
+
this._material = null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
render() {
|
|
57
|
+
if (!this.node.hasEl()) {
|
|
58
|
+
this.context.error("Material is missing Mesh");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const material = new MeshStandardMaterial({
|
|
62
|
+
color: this.color,
|
|
63
|
+
map: null,
|
|
64
|
+
side: this.inverted ? BackSide : FrontSide,
|
|
65
|
+
opacity: this.opacity,
|
|
66
|
+
transparent: this.transparent,
|
|
67
|
+
fog: false,
|
|
68
|
+
shadowSide: DoubleSide,
|
|
69
|
+
wireframe: false,
|
|
70
|
+
alphaTest: this.alphaTest,
|
|
71
|
+
metalness: this.metalness,
|
|
72
|
+
roughness: this.roughness,
|
|
73
|
+
});
|
|
74
|
+
this._material = material;
|
|
75
|
+
const mesh = this.node.getEl();
|
|
76
|
+
mesh.material = material;
|
|
77
|
+
if (this.inverted) {
|
|
78
|
+
mesh.scale.x = mesh.scale.x * -1;
|
|
79
|
+
}
|
|
80
|
+
mesh.renderOrder = this.renderOrder;
|
|
81
|
+
if (this.file_texture !== null) {
|
|
82
|
+
this.context.imageLoader().load(this, this.file_texture);
|
|
83
|
+
}
|
|
84
|
+
material.needsUpdate = true;
|
|
85
|
+
}
|
|
86
|
+
//
|
|
87
|
+
// IImageLoader
|
|
88
|
+
//
|
|
89
|
+
onImageLoaded(file, data, cacheKey) {
|
|
90
|
+
this._cacheKey = cacheKey;
|
|
91
|
+
if (this._material === null) {
|
|
92
|
+
this.context.error("onImageLoaded and material was null");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const texture = new Texture();
|
|
96
|
+
texture.userData.id = file._id;
|
|
97
|
+
texture.colorSpace = SRGBColorSpace;
|
|
98
|
+
texture.image = data;
|
|
99
|
+
if (file.subType === FileSubType.Stereo)
|
|
100
|
+
texture.repeat = new Vector2(1, 0.5);
|
|
101
|
+
this._material.map = texture;
|
|
102
|
+
this.setTextureRepeat();
|
|
103
|
+
this._material.needsUpdate = true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=PPhysicalMaterial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PPhysicalMaterial.js","sourceRoot":"","sources":["../../src/pcomponents/PPhysicalMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,UAAU,EACV,SAAS,EAET,oBAAoB,EACpB,cAAc,EACd,OAAO,EACP,OAAO,EACP,cAAc,GACf,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,iBAAiB,IAAI,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAuB,MAAM,gBAAgB,CAAC;AAElE,MAAM,CAAC,OAAO,OAAO,iBACnB,SAAQ,qBAAqB;IAD/B;;QAIY,cAAS,GAAgC,IAAI,CAAC;QACxD,cAAS,GAAG,CAAC,CAAC;QAgFd,EAAE;QACF,mBAAmB;QACnB,EAAE;QAEF,wBAAmB,GAAG,CAAC,YAA2B,EAAE,EAAE;YACpD,IAAI,IAAI,CAAC,SAAS,IAAI,YAAY,EAAE,CAAC;gBACnC,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;gBACzC,IAAI,CAAC,SAAS,CAAC,OAAO,GAAG,OAAO,CAAC;YACnC,CAAC;QACH,CAAC,CAAC;IAyBJ,CAAC;IAhHC,gBAAgB;QACd,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,IAAI,CAAC;QAC5C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,mBAAmB,CAAC;YAC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AC3D,CAAC;QAED,QAAQ,CAAC,WAAW,GAAG,IAAI,CAAC;IAC9B,CAAC;IAaD,EAAE;IACF,gBAAgB;IAChB,EAAE;IAEF,aAAa,CAAC,IAAW,EAAE,IAAS,EAAE,QAAgB;QACpD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAE1B,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;YAC1D,OAAO;QACT,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;QAC9B,OAAO,CAAC,QAAQ,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC;QAC/B,OAAO,CAAC,UAAU,GAAG,cAAc,CAAC;QACpC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;QACrB,IAAI,IAAI,CAAC,OAAO,KAAK,WAAW,CAAC,MAAM;YACrC,OAAO,CAAC,MAAM,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAEvC,IAAI,CAAC,SAAS,CAAC,GAAG,GAAG,OAAO,CAAC;QAC7B,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PlaneGeometry } from "three";
|
|
2
|
+
import { PPlaneGeometry as PPlaneGeometryBase } from "@p100-web/core";
|
|
3
|
+
export default class PPlaneGeometry extends PPlaneGeometryBase {
|
|
4
|
+
el: PlaneGeometry | null;
|
|
5
|
+
unrender(): void;
|
|
6
|
+
render(): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=PPlaneGeometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PPlaneGeometry.d.ts","sourceRoot":"","sources":["../../src/pcomponents/PPlaneGeometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,aAAa,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,kBAAkB;IAC5D,EAAE,EAAE,aAAa,GAAG,IAAI,CAAQ;IAEhC,QAAQ;IAOR,MAAM;CAaP"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Mesh, PlaneGeometry } from "three";
|
|
2
|
+
import { PPlaneGeometry as PPlaneGeometryBase } from "@p100-web/core";
|
|
3
|
+
export default class PPlaneGeometry extends PPlaneGeometryBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.el = null;
|
|
7
|
+
}
|
|
8
|
+
unrender() {
|
|
9
|
+
if (this.el) {
|
|
10
|
+
this.el.dispose();
|
|
11
|
+
this.el = null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
render() {
|
|
15
|
+
const geometry = new PlaneGeometry(this.size.x, this.size.y, this.segments.x, this.segments.y);
|
|
16
|
+
const mesh = new Mesh(geometry);
|
|
17
|
+
mesh.castShadow = this.castShadow;
|
|
18
|
+
mesh.receiveShadow = this.receiveShadow;
|
|
19
|
+
this.node.set_el(mesh, false);
|
|
20
|
+
this.el = geometry;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=PPlaneGeometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PPlaneGeometry.js","sourceRoot":"","sources":["../../src/pcomponents/PPlaneGeometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,kBAAkB;IAA9D;;QACE,OAAE,GAAyB,IAAI,CAAC;IAsBlC,CAAC;IApBC,QAAQ;QACN,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QACjB,CAAC;IACH,CAAC;IAED,MAAM;QACJ,MAAM,QAAQ,GAAG,IAAI,aAAa,CAChC,IAAI,CAAC,IAAI,CAAC,CAAC,EACX,IAAI,CAAC,IAAI,CAAC,CAAC,EACX,IAAI,CAAC,QAAQ,CAAC,CAAC,EACf,IAAI,CAAC,QAAQ,CAAC,CAAC,CAChB,CAAC;QACF,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9B,IAAI,CAAC,EAAE,GAAG,QAAQ,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PProjectRoot.d.ts","sourceRoot":"","sources":["../../src/pcomponents/PProjectRoot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIlE,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,gBAAgB;IACxD,MAAM,IAAI,IAAI;IAOd,QAAQ,IAAI,IAAI;IAEhB,IAAI;IAYJ,IAAI;CAIL"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PProjectRoot as PProjectRootBase } from "@p100-web/core";
|
|
2
|
+
export default class PProjectRoot extends PProjectRootBase {
|
|
3
|
+
render() {
|
|
4
|
+
if (!this.node.hasEl()) {
|
|
5
|
+
const rootNode = this.context.getPCanvas().getThreeRootNode();
|
|
6
|
+
this.node.set_el(rootNode, true);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
unrender() { }
|
|
10
|
+
play() {
|
|
11
|
+
const camera = this.context.getPCanvas().getThreeCamera();
|
|
12
|
+
// Audio
|
|
13
|
+
const audioListener = this.context.getAudioListener();
|
|
14
|
+
camera.add(audioListener);
|
|
15
|
+
if (this.enabled) {
|
|
16
|
+
this.context.enableInput();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
stop() {
|
|
20
|
+
const audioListener = this.context.getAudioListener();
|
|
21
|
+
audioListener.removeFromParent();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=PProjectRoot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PProjectRoot.js","sourceRoot":"","sources":["../../src/pcomponents/PProjectRoot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIlE,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,gBAAgB;IACxD,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAW,CAAC,gBAAgB,EAAE,CAAC;YACvE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,QAAQ,KAAU,CAAC;IAEnB,IAAI;QACF,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAW,CAAC,cAAc,EAAE,CAAC;QAEnE,QAAQ;QACR,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAmB,CAAC;QACvE,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAE1B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,IAAI;QACF,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAmB,CAAC;QACvE,aAAa,CAAC,gBAAgB,EAAE,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Mesh, Vector3 } from "three";
|
|
2
|
+
import { PSlider as PSliderBase, type IColliderComponent, type IColliderObject } from "@p100-web/core";
|
|
3
|
+
export default class PSlider extends PSliderBase implements IColliderComponent {
|
|
4
|
+
el: Mesh | null;
|
|
5
|
+
_width: number;
|
|
6
|
+
render(): void;
|
|
7
|
+
addColliderNode(): void;
|
|
8
|
+
getColliderObject(): IColliderObject | null;
|
|
9
|
+
unrender(): void;
|
|
10
|
+
computeBounds(): void;
|
|
11
|
+
private getPercent;
|
|
12
|
+
native_onHoverEnter: (point: Vector3) => void;
|
|
13
|
+
native_onHoverExit: () => void;
|
|
14
|
+
native_onClick: () => void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=PSlider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PSlider.d.ts","sourceRoot":"","sources":["../../src/pcomponents/PSlider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,OAAO,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EACL,OAAO,IAAI,WAAW,EACtB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,WAAY,YAAW,kBAAkB;IAC5E,EAAE,EAAE,IAAI,GAAG,IAAI,CAAQ;IACvB,MAAM,SAAO;IAEb,MAAM;IAWN,eAAe;IAcf,iBAAiB,IAAI,eAAe,GAAG,IAAI;IAI3C,QAAQ;IAUR,aAAa;IAcb,OAAO,CAAC,UAAU;IAKlB,mBAAmB,GAAI,OAAO,OAAO,UAInC;IAEF,kBAAkB,aAGhB;IAEF,cAAc,aAGZ;CACH"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { PSlider as PSliderBase, } from "@p100-web/core";
|
|
2
|
+
export default class PSlider extends PSliderBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.el = null;
|
|
6
|
+
this._width = 0.0;
|
|
7
|
+
this.native_onHoverEnter = (point) => {
|
|
8
|
+
const percent = this.getPercent(point);
|
|
9
|
+
console.log("native_onHoverEnter: ", percent);
|
|
10
|
+
this.outevent_onHoverEnter?.emit(this.node.id, this);
|
|
11
|
+
};
|
|
12
|
+
this.native_onHoverExit = () => {
|
|
13
|
+
console.log("native_onHoverExit: ");
|
|
14
|
+
this.outevent_onHoverExit?.emit(this.node.id, this);
|
|
15
|
+
};
|
|
16
|
+
this.native_onClick = () => {
|
|
17
|
+
console.log("native_onClick: ");
|
|
18
|
+
this.outevent_onClick?.emit(this.node.id, this);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
render() {
|
|
22
|
+
this.el = this.node.getEl();
|
|
23
|
+
this.node.collider = this;
|
|
24
|
+
// If we have a parent, add us directly
|
|
25
|
+
if (this.node.hasEl()) {
|
|
26
|
+
this.addColliderNode();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
addColliderNode() {
|
|
30
|
+
if (!this.node.hasEl()) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.computeBounds();
|
|
34
|
+
const mesh = this.node.getEl();
|
|
35
|
+
// Add to the raycaster
|
|
36
|
+
mesh.layers.mask = 3;
|
|
37
|
+
mesh.userData.collider = this;
|
|
38
|
+
this.context.getPCanvas().addCollider(mesh);
|
|
39
|
+
}
|
|
40
|
+
getColliderObject() {
|
|
41
|
+
throw new Error("Method not implemented.");
|
|
42
|
+
}
|
|
43
|
+
unrender() {
|
|
44
|
+
if (!this.node.hasEl()) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const nodeEl = this.node.getEl();
|
|
48
|
+
nodeEl.layers.mask = 1;
|
|
49
|
+
nodeEl.userData.collider = null;
|
|
50
|
+
this.context.getPCanvas().removeCollider(nodeEl);
|
|
51
|
+
}
|
|
52
|
+
computeBounds() {
|
|
53
|
+
const mesh = this.node.getEl();
|
|
54
|
+
if (mesh) {
|
|
55
|
+
mesh.geometry.computeBoundingSphere();
|
|
56
|
+
mesh.geometry.computeBoundingBox();
|
|
57
|
+
this._width =
|
|
58
|
+
mesh.geometry.boundingBox.max.x - mesh.geometry.boundingBox.min.x;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//
|
|
62
|
+
// EVENTS
|
|
63
|
+
//
|
|
64
|
+
getPercent(point) {
|
|
65
|
+
const localPoint = this.el.worldToLocal(point.clone());
|
|
66
|
+
return localPoint.x / this._width + 0.5;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=PSlider.js.map
|