@playcanvas/web-components 0.10.1 → 0.11.0
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 +103 -32
- package/dist/components/camera-component.d.ts +13 -13
- package/dist/components/screen-component.d.ts +25 -4
- package/dist/components/scrollview-component.d.ts +6 -4
- package/dist/custom-elements.json +239 -96
- package/dist/entity.d.ts +13 -0
- package/dist/parse.d.ts +4 -2
- package/dist/pwc.cjs +308 -156
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +308 -156
- package/dist/pwc.js.map +1 -1
- package/dist/pwc.min.js +1 -1
- package/dist/pwc.min.js.map +1 -1
- package/dist/pwc.min.mjs +1 -1
- package/dist/pwc.min.mjs.map +1 -1
- package/dist/pwc.mjs +309 -157
- package/dist/pwc.mjs.map +1 -1
- package/dist/sky.d.ts +12 -11
- package/dist/vscode.html-custom-data.json +40 -20
- package/dist/web-types.json +67 -48
- package/package.json +1 -1
- package/src/app.ts +189 -79
- package/src/components/camera-component.ts +31 -26
- package/src/components/screen-component.ts +42 -12
- package/src/components/scrollview-component.ts +6 -4
- package/src/entity.ts +35 -17
- package/src/parse.ts +5 -3
- package/src/sky.ts +26 -25
package/dist/pwc.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { basisInitialize, WasmModule, Vec3, Color, Vec4, Quat, Vec2, createGraphicsDevice, AppOptions, Keyboard, Mouse, ElementInput, AnimComponentSystem, AnimationComponentSystem, AudioListenerComponentSystem, ButtonComponentSystem, CameraComponentSystem, CollisionComponentSystem, ElementComponentSystem, GSplatComponentSystem, JointComponentSystem, LayoutChildComponentSystem, LayoutGroupComponentSystem, LightComponentSystem, ModelComponentSystem, ParticleSystemComponentSystem, RenderComponentSystem, RigidBodyComponentSystem, ScreenComponentSystem, ScriptComponentSystem, ScrollbarComponentSystem, ScrollViewComponentSystem, SoundComponentSystem, SpriteComponentSystem, ZoneComponentSystem, AnimClipHandler, AnimationHandler, AnimStateGraphHandler, AudioHandler, BinaryHandler, CssHandler, ContainerHandler, CubemapHandler, FolderHandler, FontHandler, GSplatHandler, HierarchyHandler, HtmlHandler, JsonHandler, MaterialHandler, ModelHandler, RenderHandler, ScriptHandler, SceneHandler, ShaderHandler, SpriteHandler, TemplateHandler, TextHandler, TextureAtlasHandler, TextureHandler, SoundManager, Lightmapper, BatchManager, XrManager, AppBase, FILLMODE_FILL_WINDOW, RESOLUTION_AUTO, Picker, MeshInstance, Entity, Asset, SPRITE_RENDERMODE_SIMPLE, SPRITE_RENDERMODE_SLICED, SPRITE_RENDERMODE_TILED, BUTTON_TRANSITION_MODE_TINT, BUTTON_TRANSITION_MODE_SPRITE_CHANGE,
|
|
1
|
+
import { basisInitialize, WasmModule, Vec3, Color, Vec4, Quat, Vec2, createGraphicsDevice, AppOptions, Keyboard, Mouse, ElementInput, AnimComponentSystem, AnimationComponentSystem, AudioListenerComponentSystem, ButtonComponentSystem, CameraComponentSystem, CollisionComponentSystem, ElementComponentSystem, GSplatComponentSystem, JointComponentSystem, LayoutChildComponentSystem, LayoutGroupComponentSystem, LightComponentSystem, ModelComponentSystem, ParticleSystemComponentSystem, RenderComponentSystem, RigidBodyComponentSystem, ScreenComponentSystem, ScriptComponentSystem, ScrollbarComponentSystem, ScrollViewComponentSystem, SoundComponentSystem, SpriteComponentSystem, ZoneComponentSystem, AnimClipHandler, AnimationHandler, AnimStateGraphHandler, AudioHandler, BinaryHandler, CssHandler, ContainerHandler, CubemapHandler, FolderHandler, FontHandler, GSplatHandler, HierarchyHandler, HtmlHandler, JsonHandler, MaterialHandler, ModelHandler, RenderHandler, ScriptHandler, SceneHandler, ShaderHandler, SpriteHandler, TemplateHandler, TextHandler, TextureAtlasHandler, TextureHandler, SoundManager, Lightmapper, BatchManager, XrManager, AppBase, FILLMODE_FILL_WINDOW, RESOLUTION_AUTO, Picker, MeshInstance, Entity, Asset, SPRITE_RENDERMODE_SIMPLE, SPRITE_RENDERMODE_SLICED, SPRITE_RENDERMODE_TILED, BUTTON_TRANSITION_MODE_TINT, BUTTON_TRANSITION_MODE_SPRITE_CHANGE, TONEMAP_NONE, PROJECTION_PERSPECTIVE, GAMMA_SRGB, GAMMA_NONE, XRTYPE_VR, TONEMAP_LINEAR, TONEMAP_FILMIC, TONEMAP_HEJL, TONEMAP_ACES, TONEMAP_ACES2, TONEMAP_NEUTRAL, PROJECTION_ORTHOGRAPHIC, ORIENTATION_HORIZONTAL, FITTING_NONE, FITTING_STRETCH, FITTING_SHRINK, FITTING_BOTH, ORIENTATION_VERTICAL, SHADOW_PCF3_32F, SHADOW_PCF1_16F, SHADOW_PCF1_32F, SHADOW_PCF3_16F, SHADOW_PCF5_16F, SHADOW_PCF5_32F, SHADOW_VSM_16F, SHADOW_VSM_32F, SHADOW_PCSS_32F, StandardMaterial, BLEND_NONE, CULLFACE_BACK, FRESNEL_SCHLICK, SPECOCC_AO, BLEND_NORMAL, BLEND_ADDITIVE, BLEND_ADDITIVEALPHA, BLEND_PREMULTIPLIED, BLEND_MULTIPLICATIVE, BLEND_MULTIPLICATIVE2X, BLEND_SCREEN, BLEND_MIN, BLEND_MAX, BLEND_SUBTRACTIVE, CULLFACE_NONE, CULLFACE_FRONT, CULLFACE_FRONTANDBACK, FRESNEL_NONE, SPECOCC_NONE, SPECOCC_GLOSSDEPENDENT, SCALEMODE_NONE, SCALEMODE_BLEND, SCROLL_MODE_BOUNCE, SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED, SCROLLBAR_VISIBILITY_SHOW_ALWAYS, SCROLL_MODE_CLAMP, SCROLL_MODE_INFINITE, EnvLighting, LAYERID_SKYBOX } from 'playcanvas';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Base class for all PlayCanvas Web Components that initialize asynchronously.
|
|
@@ -487,7 +487,9 @@ const parseColor = (value, defaultValue, attribute) => {
|
|
|
487
487
|
* the value is invalid — the latter also logs a warning listing the valid names.
|
|
488
488
|
*
|
|
489
489
|
* @param value - The attribute value to parse (`null` when the attribute is absent).
|
|
490
|
-
* @param valid - The valid names: an array, or a map whose keys are the valid names.
|
|
490
|
+
* @param valid - The valid names: an array, or a map whose keys are the valid names. Only the keys
|
|
491
|
+
* are read, so the map's value type is unconstrained - engine enums are mostly numeric constants,
|
|
492
|
+
* but some (e.g. `SCALEMODE_BLEND`) are strings.
|
|
491
493
|
* @param defaultValue - The value to use when the attribute is absent or invalid.
|
|
492
494
|
* @param attribute - The attribute name, used in the warning message.
|
|
493
495
|
* @returns The resolved enum name.
|
|
@@ -675,12 +677,24 @@ class AppElement extends AsyncElement {
|
|
|
675
677
|
_alpha = true;
|
|
676
678
|
_backend = 'webgpu';
|
|
677
679
|
_antialias = true;
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
680
|
+
_depthBuffer = true;
|
|
681
|
+
_stencilBuffer = true;
|
|
682
|
+
_maxPixelRatio = Infinity;
|
|
681
683
|
_loadingBar = true;
|
|
684
|
+
/**
|
|
685
|
+
* Set once the graphics options above have been handed to `createGraphicsDevice`, after which
|
|
686
|
+
* writing any of them changes nothing. Guards the warning in {@link _warnIfBooted}, and is
|
|
687
|
+
* cleared on disconnect so a re-connected element boots from its current attributes.
|
|
688
|
+
*/
|
|
689
|
+
_optionsLocked = false;
|
|
682
690
|
_bar = null;
|
|
683
691
|
_hierarchyReady = false;
|
|
692
|
+
/**
|
|
693
|
+
* The elements backing this application's entities, keyed by the entity itself. Registered
|
|
694
|
+
* by EntityElement at creation and removed when an entity is destroyed, this joins engine
|
|
695
|
+
* scene nodes back to their owning elements by identity - never by name.
|
|
696
|
+
*/
|
|
697
|
+
_entityElements = new Map();
|
|
684
698
|
_picker = null;
|
|
685
699
|
_hasPointerListeners = {
|
|
686
700
|
pointerenter: false,
|
|
@@ -748,15 +762,19 @@ class AppElement extends AsyncElement {
|
|
|
748
762
|
null: ['null']
|
|
749
763
|
};
|
|
750
764
|
const deviceTypes = backendToDeviceTypes[this._backend] || [];
|
|
765
|
+
this._optionsLocked = true;
|
|
751
766
|
const device = await createGraphicsDevice(this._canvas, {
|
|
752
767
|
// @ts-ignore - alpha needs to be documented
|
|
753
768
|
alpha: this._alpha,
|
|
754
769
|
antialias: this._antialias,
|
|
755
|
-
depth: this.
|
|
770
|
+
depth: this._depthBuffer,
|
|
756
771
|
deviceTypes: deviceTypes,
|
|
757
|
-
stencil: this.
|
|
772
|
+
stencil: this._stencilBuffer
|
|
758
773
|
});
|
|
759
|
-
|
|
774
|
+
// Assigned rather than resolved to a number here: the engine caps against the live
|
|
775
|
+
// window.devicePixelRatio on every resize, so an uncapped Infinity keeps following the
|
|
776
|
+
// display when a window moves between monitors of differing density.
|
|
777
|
+
device.maxPixelRatio = this._maxPixelRatio;
|
|
760
778
|
const createOptions = new AppOptions();
|
|
761
779
|
createOptions.graphicsDevice = device;
|
|
762
780
|
createOptions.keyboard = new Keyboard(window);
|
|
@@ -883,12 +901,15 @@ class AppElement extends AsyncElement {
|
|
|
883
901
|
});
|
|
884
902
|
}
|
|
885
903
|
disconnectedCallback() {
|
|
904
|
+
this._optionsLocked = false;
|
|
886
905
|
this._pickerDestroy();
|
|
887
|
-
// Clean up the application
|
|
906
|
+
// Clean up the application. Destroying it destroys every entity, whose destroy hooks
|
|
907
|
+
// unregister them - clear() covers any entity the engine no longer reached.
|
|
888
908
|
if (this._app) {
|
|
889
909
|
this._app.destroy();
|
|
890
910
|
this._app = null;
|
|
891
911
|
}
|
|
912
|
+
this._entityElements.clear();
|
|
892
913
|
this._loadProgress = 0;
|
|
893
914
|
this._bar?.destroy();
|
|
894
915
|
this._bar = null;
|
|
@@ -954,6 +975,74 @@ class AppElement extends AsyncElement {
|
|
|
954
975
|
pointermove: false
|
|
955
976
|
};
|
|
956
977
|
}
|
|
978
|
+
/**
|
|
979
|
+
* Registers the element that created an entity. Called by EntityElement when it creates its
|
|
980
|
+
* entity.
|
|
981
|
+
*
|
|
982
|
+
* @param entity - The entity.
|
|
983
|
+
* @param element - The element that created it.
|
|
984
|
+
* @ignore
|
|
985
|
+
*/
|
|
986
|
+
_registerEntityElement(entity, element) {
|
|
987
|
+
this._entityElements.set(entity, element);
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Removes the registration for a destroyed entity. Called by EntityElement.
|
|
991
|
+
*
|
|
992
|
+
* @param entity - The entity.
|
|
993
|
+
* @ignore
|
|
994
|
+
*/
|
|
995
|
+
_unregisterEntityElement(entity) {
|
|
996
|
+
this._entityElements.delete(entity);
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Returns the `<pc-entity>` element whose backing entity is `entity`, or `null` if the
|
|
1000
|
+
* entity was not created by an element of this application - for example, a node inside a
|
|
1001
|
+
* model's instantiated hierarchy, or an entity created through the engine API.
|
|
1002
|
+
*
|
|
1003
|
+
* @param entity - The entity to look up.
|
|
1004
|
+
* @returns The element backing the entity, or `null`.
|
|
1005
|
+
*/
|
|
1006
|
+
elementFromEntity(entity) {
|
|
1007
|
+
return this._entityElements.get(entity) ?? null;
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Resolves the element that owns a picked node: the nearest node up the parent chain -
|
|
1011
|
+
* starting with the node itself - that was created by a `<pc-entity>` of this application.
|
|
1012
|
+
* A hit inside a model's instantiated hierarchy therefore resolves to the element hosting
|
|
1013
|
+
* the model.
|
|
1014
|
+
*
|
|
1015
|
+
* @param node - The picked node, or `null`.
|
|
1016
|
+
* @returns The owning element, or `null`.
|
|
1017
|
+
*/
|
|
1018
|
+
_elementFromNode(node) {
|
|
1019
|
+
while (node !== null) {
|
|
1020
|
+
const element = this._entityElements.get(node);
|
|
1021
|
+
if (element) {
|
|
1022
|
+
return element;
|
|
1023
|
+
}
|
|
1024
|
+
node = node.parent;
|
|
1025
|
+
}
|
|
1026
|
+
return null;
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Like {@link _elementFromNode}, but skips elements without a listener for `type`, so a hit
|
|
1030
|
+
* on an unlistened child still reaches a listening ancestor.
|
|
1031
|
+
*
|
|
1032
|
+
* @param node - The picked node, or `null`.
|
|
1033
|
+
* @param type - The pointer event type a listener is required for.
|
|
1034
|
+
* @returns The nearest listening element, or `null`.
|
|
1035
|
+
*/
|
|
1036
|
+
_elementWithListener(node, type) {
|
|
1037
|
+
while (node !== null) {
|
|
1038
|
+
const element = this._entityElements.get(node);
|
|
1039
|
+
if (element?.hasListeners(type)) {
|
|
1040
|
+
return element;
|
|
1041
|
+
}
|
|
1042
|
+
node = node.parent;
|
|
1043
|
+
}
|
|
1044
|
+
return null;
|
|
1045
|
+
}
|
|
957
1046
|
// New helper to convert CSS coordinates to canvas (picker) coordinates
|
|
958
1047
|
_getPickerCoordinates(event) {
|
|
959
1048
|
// Get the canvas' bounding rectangle in CSS pixels.
|
|
@@ -999,17 +1088,9 @@ class AppElement extends AsyncElement {
|
|
|
999
1088
|
const node = await this._pickNode(event);
|
|
1000
1089
|
if (token !== this._pickToken || !this._picker)
|
|
1001
1090
|
return;
|
|
1002
|
-
//
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
while (currentNode !== null) {
|
|
1006
|
-
const entityElement = this.querySelector(`pc-entity[name="${currentNode.name}"]`);
|
|
1007
|
-
if (entityElement) {
|
|
1008
|
-
newHoverEntity = entityElement;
|
|
1009
|
-
break;
|
|
1010
|
-
}
|
|
1011
|
-
currentNode = currentNode.parent;
|
|
1012
|
-
}
|
|
1091
|
+
// The hovered element is the nearest one up the node's parent chain, listening or not -
|
|
1092
|
+
// dispatch is gated per event type below
|
|
1093
|
+
const newHoverEntity = this._elementFromNode(node);
|
|
1013
1094
|
// Handle enter/leave events
|
|
1014
1095
|
if (this._hoveredEntity !== newHoverEntity) {
|
|
1015
1096
|
if (this._hoveredEntity && this._hoveredEntity.hasListeners('pointerleave')) {
|
|
@@ -1029,26 +1110,22 @@ class AppElement extends AsyncElement {
|
|
|
1029
1110
|
async _onPointerDown(event) {
|
|
1030
1111
|
if (!this._picker || !this.app)
|
|
1031
1112
|
return;
|
|
1032
|
-
|
|
1113
|
+
const node = await this._pickNode(event);
|
|
1033
1114
|
if (!this._picker)
|
|
1034
1115
|
return; // the element disconnected while the pick was in flight
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
entityElement.dispatchEvent(new PointerEvent('pointerdown', event));
|
|
1039
|
-
break;
|
|
1040
|
-
}
|
|
1041
|
-
currentNode = currentNode.parent;
|
|
1116
|
+
const entityElement = this._elementWithListener(node, 'pointerdown');
|
|
1117
|
+
if (entityElement) {
|
|
1118
|
+
entityElement.dispatchEvent(new PointerEvent('pointerdown', event));
|
|
1042
1119
|
}
|
|
1043
1120
|
}
|
|
1044
1121
|
async _onPointerUp(event) {
|
|
1045
1122
|
if (!this._picker || !this.app)
|
|
1046
1123
|
return;
|
|
1047
1124
|
const node = await this._pickNode(event);
|
|
1048
|
-
if (!
|
|
1049
|
-
return;
|
|
1050
|
-
const entityElement = this.
|
|
1051
|
-
if (entityElement
|
|
1125
|
+
if (!this._picker)
|
|
1126
|
+
return; // the element disconnected while the pick was in flight
|
|
1127
|
+
const entityElement = this._elementWithListener(node, 'pointerup');
|
|
1128
|
+
if (entityElement) {
|
|
1052
1129
|
entityElement.dispatchEvent(new PointerEvent('pointerup', event));
|
|
1053
1130
|
}
|
|
1054
1131
|
}
|
|
@@ -1078,28 +1155,43 @@ class AppElement extends AsyncElement {
|
|
|
1078
1155
|
}
|
|
1079
1156
|
}
|
|
1080
1157
|
/**
|
|
1081
|
-
*
|
|
1158
|
+
* Warns that a graphics option was written too late to have any effect. These options are read
|
|
1159
|
+
* once, when the element connects and creates its graphics device, so a later write updates
|
|
1160
|
+
* only the element's own property - silently, without this.
|
|
1161
|
+
*
|
|
1162
|
+
* @param name - The name of the option, as its attribute.
|
|
1163
|
+
*/
|
|
1164
|
+
_warnIfBooted(name) {
|
|
1165
|
+
if (this._optionsLocked) {
|
|
1166
|
+
console.warn(`Attribute '${name}' on <pc-app> is only read when the application boots, so this change has no effect. Set it before the element is connected, or remove and re-insert the element to reboot with the new value.`);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Sets whether the frame buffer has an alpha channel, which is what lets the page show through
|
|
1171
|
+
* wherever the scene has not drawn. Read only when the application boots.
|
|
1082
1172
|
* @param value - The alpha flag.
|
|
1083
1173
|
*/
|
|
1084
1174
|
set alpha(value) {
|
|
1175
|
+
this._warnIfBooted('alpha');
|
|
1085
1176
|
this._alpha = value;
|
|
1086
1177
|
}
|
|
1087
1178
|
/**
|
|
1088
|
-
* Gets the alpha
|
|
1179
|
+
* Gets whether the frame buffer has an alpha channel.
|
|
1089
1180
|
* @returns The alpha flag.
|
|
1090
1181
|
*/
|
|
1091
1182
|
get alpha() {
|
|
1092
1183
|
return this._alpha;
|
|
1093
1184
|
}
|
|
1094
1185
|
/**
|
|
1095
|
-
* Sets the
|
|
1186
|
+
* Sets whether the frame buffer is anti-aliased. Read only when the application boots.
|
|
1096
1187
|
* @param value - The antialias flag.
|
|
1097
1188
|
*/
|
|
1098
1189
|
set antialias(value) {
|
|
1190
|
+
this._warnIfBooted('antialias');
|
|
1099
1191
|
this._antialias = value;
|
|
1100
1192
|
}
|
|
1101
1193
|
/**
|
|
1102
|
-
* Gets the
|
|
1194
|
+
* Gets whether the frame buffer is anti-aliased.
|
|
1103
1195
|
* @returns The antialias flag.
|
|
1104
1196
|
*/
|
|
1105
1197
|
get antialias() {
|
|
@@ -1107,10 +1199,11 @@ class AppElement extends AsyncElement {
|
|
|
1107
1199
|
}
|
|
1108
1200
|
/**
|
|
1109
1201
|
* Sets the graphics backend. Defaults to 'webgpu', which falls back to 'webgl2' if WebGPU
|
|
1110
|
-
* is not supported by the browser.
|
|
1202
|
+
* is not supported by the browser. Read only when the application boots.
|
|
1111
1203
|
* @param value - The graphics backend ('webgpu', 'webgl2', or 'null').
|
|
1112
1204
|
*/
|
|
1113
1205
|
set backend(value) {
|
|
1206
|
+
this._warnIfBooted('backend');
|
|
1114
1207
|
this._backend = value;
|
|
1115
1208
|
}
|
|
1116
1209
|
/**
|
|
@@ -1121,18 +1214,20 @@ class AppElement extends AsyncElement {
|
|
|
1121
1214
|
return this._backend;
|
|
1122
1215
|
}
|
|
1123
1216
|
/**
|
|
1124
|
-
* Sets the depth
|
|
1125
|
-
*
|
|
1217
|
+
* Sets whether the frame buffer has a depth buffer, which the renderer needs to resolve which
|
|
1218
|
+
* surface is nearest the camera. Read only when the application boots.
|
|
1219
|
+
* @param value - The depth buffer flag.
|
|
1126
1220
|
*/
|
|
1127
|
-
set
|
|
1128
|
-
this.
|
|
1221
|
+
set depthBuffer(value) {
|
|
1222
|
+
this._warnIfBooted('depth-buffer');
|
|
1223
|
+
this._depthBuffer = value;
|
|
1129
1224
|
}
|
|
1130
1225
|
/**
|
|
1131
|
-
* Gets the depth
|
|
1132
|
-
* @returns The depth flag.
|
|
1226
|
+
* Gets whether the frame buffer has a depth buffer.
|
|
1227
|
+
* @returns The depth buffer flag.
|
|
1133
1228
|
*/
|
|
1134
|
-
get
|
|
1135
|
-
return this.
|
|
1229
|
+
get depthBuffer() {
|
|
1230
|
+
return this._depthBuffer;
|
|
1136
1231
|
}
|
|
1137
1232
|
/**
|
|
1138
1233
|
* Gets the hierarchy ready flag.
|
|
@@ -1142,24 +1237,6 @@ class AppElement extends AsyncElement {
|
|
|
1142
1237
|
get hierarchyReady() {
|
|
1143
1238
|
return this._hierarchyReady;
|
|
1144
1239
|
}
|
|
1145
|
-
/**
|
|
1146
|
-
* Sets the high resolution flag. When true, the application will render at the device's
|
|
1147
|
-
* physical resolution. When false, the application will render at CSS resolution.
|
|
1148
|
-
* @param value - The high resolution flag.
|
|
1149
|
-
*/
|
|
1150
|
-
set highResolution(value) {
|
|
1151
|
-
this._highResolution = value;
|
|
1152
|
-
if (this.app) {
|
|
1153
|
-
this.app.graphicsDevice.maxPixelRatio = value ? window.devicePixelRatio : 1;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
/**
|
|
1157
|
-
* Gets the high resolution flag.
|
|
1158
|
-
* @returns The high resolution flag.
|
|
1159
|
-
*/
|
|
1160
|
-
get highResolution() {
|
|
1161
|
-
return this._highResolution;
|
|
1162
|
-
}
|
|
1163
1240
|
/**
|
|
1164
1241
|
* Sets whether the application shows its built-in loading bar while it boots and preloads its
|
|
1165
1242
|
* assets. Enabled by default; setting `false` removes the bar immediately, while setting
|
|
@@ -1184,21 +1261,45 @@ class AppElement extends AsyncElement {
|
|
|
1184
1261
|
return this._loadingBar;
|
|
1185
1262
|
}
|
|
1186
1263
|
/**
|
|
1187
|
-
* Sets the
|
|
1188
|
-
*
|
|
1264
|
+
* Sets the cap on the pixel ratio the application renders at. The canvas is sized by the
|
|
1265
|
+
* smaller of this value and the display's own device pixel ratio, so the default of `Infinity`
|
|
1266
|
+
* renders at full physical resolution, `1` renders at CSS resolution, and an intermediate
|
|
1267
|
+
* value such as `2` keeps a dense display sharp without paying for every one of its pixels.
|
|
1268
|
+
* Must be greater than 0. Unlike the other graphics options, this applies immediately.
|
|
1269
|
+
* @param value - The maximum pixel ratio.
|
|
1270
|
+
*/
|
|
1271
|
+
set maxPixelRatio(value) {
|
|
1272
|
+
this._maxPixelRatio = value;
|
|
1273
|
+
if (this.app) {
|
|
1274
|
+
this.app.graphicsDevice.maxPixelRatio = value;
|
|
1275
|
+
this.app.resizeCanvas();
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Gets the cap on the pixel ratio the application renders at.
|
|
1280
|
+
* @returns The maximum pixel ratio.
|
|
1281
|
+
*/
|
|
1282
|
+
get maxPixelRatio() {
|
|
1283
|
+
return this._maxPixelRatio;
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Sets whether the frame buffer has a stencil buffer, which stencil-based effects and UI
|
|
1287
|
+
* masking need. Read only when the application boots.
|
|
1288
|
+
* @param value - The stencil buffer flag.
|
|
1189
1289
|
*/
|
|
1190
|
-
set
|
|
1191
|
-
this.
|
|
1290
|
+
set stencilBuffer(value) {
|
|
1291
|
+
this._warnIfBooted('stencil-buffer');
|
|
1292
|
+
this._stencilBuffer = value;
|
|
1192
1293
|
}
|
|
1193
1294
|
/**
|
|
1194
|
-
* Gets the stencil
|
|
1195
|
-
* @returns The stencil flag.
|
|
1295
|
+
* Gets whether the frame buffer has a stencil buffer.
|
|
1296
|
+
* @returns The stencil buffer flag.
|
|
1196
1297
|
*/
|
|
1197
|
-
get
|
|
1198
|
-
return this.
|
|
1298
|
+
get stencilBuffer() {
|
|
1299
|
+
return this._stencilBuffer;
|
|
1199
1300
|
}
|
|
1200
1301
|
static get observedAttributes() {
|
|
1201
|
-
return ['alpha', 'antialias', 'backend', 'depth', '
|
|
1302
|
+
return ['alpha', 'antialias', 'backend', 'depth-buffer', 'loading-bar', 'max-pixel-ratio', 'stencil-buffer'];
|
|
1202
1303
|
}
|
|
1203
1304
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
1204
1305
|
switch (name) {
|
|
@@ -1211,17 +1312,17 @@ class AppElement extends AsyncElement {
|
|
|
1211
1312
|
case 'backend':
|
|
1212
1313
|
this.backend = parseEnum(newValue, ['webgpu', 'webgl2', 'null'], 'webgpu', name);
|
|
1213
1314
|
break;
|
|
1214
|
-
case 'depth':
|
|
1215
|
-
this.
|
|
1216
|
-
break;
|
|
1217
|
-
case 'high-resolution':
|
|
1218
|
-
this.highResolution = parseBool(newValue, true);
|
|
1315
|
+
case 'depth-buffer':
|
|
1316
|
+
this.depthBuffer = parseBool(newValue, true);
|
|
1219
1317
|
break;
|
|
1220
1318
|
case 'loading-bar':
|
|
1221
1319
|
this.loadingBar = parseBool(newValue, true);
|
|
1222
1320
|
break;
|
|
1223
|
-
case '
|
|
1224
|
-
this.
|
|
1321
|
+
case 'max-pixel-ratio':
|
|
1322
|
+
this.maxPixelRatio = parseNumber(newValue, Infinity, name);
|
|
1323
|
+
break;
|
|
1324
|
+
case 'stencil-buffer':
|
|
1325
|
+
this.stencilBuffer = parseBool(newValue, true);
|
|
1225
1326
|
break;
|
|
1226
1327
|
}
|
|
1227
1328
|
}
|
|
@@ -1290,6 +1391,11 @@ class EntityElement extends AsyncElement {
|
|
|
1290
1391
|
*/
|
|
1291
1392
|
_built = false;
|
|
1292
1393
|
_entity = null;
|
|
1394
|
+
/**
|
|
1395
|
+
* The application element this entity is registered with, cached at creation time so the
|
|
1396
|
+
* entity can be unregistered even once this element has left the DOM.
|
|
1397
|
+
*/
|
|
1398
|
+
_appElement = null;
|
|
1293
1399
|
/**
|
|
1294
1400
|
* The PlayCanvas entity instance. `null` until the element is ready, and again once it has
|
|
1295
1401
|
* been removed from the document — await {@link whenReady} or the element's `ready()`
|
|
@@ -1319,6 +1425,27 @@ class EntityElement extends AsyncElement {
|
|
|
1319
1425
|
if (this._tags.length > 0) {
|
|
1320
1426
|
entity.tags.add(this._tags);
|
|
1321
1427
|
}
|
|
1428
|
+
// Register with the owning application, which joins engine nodes back to elements by
|
|
1429
|
+
// identity (never by name), and hook the entity's destruction. The engine fires 'destroy'
|
|
1430
|
+
// for every entity in a destroyed subtree, so the element learns of its entity's death no
|
|
1431
|
+
// matter who causes it: this element, an ancestor, the whole application, or a user
|
|
1432
|
+
// script calling entity.destroy().
|
|
1433
|
+
this._appElement = this.closestApp;
|
|
1434
|
+
this._appElement?._registerEntityElement(entity, this);
|
|
1435
|
+
entity.once('destroy', this._onEntityDestroy, this);
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Handles the destruction of the backing entity. Resets the element so a later re-insertion
|
|
1439
|
+
* starts clean: `_built` must be cleared alongside `_entity`, or buildHierarchy would bail
|
|
1440
|
+
* and a re-created entity would never be parented.
|
|
1441
|
+
*
|
|
1442
|
+
* @param entity - The entity that was destroyed.
|
|
1443
|
+
*/
|
|
1444
|
+
_onEntityDestroy(entity) {
|
|
1445
|
+
this._appElement?._unregisterEntityElement(entity);
|
|
1446
|
+
this._appElement = null;
|
|
1447
|
+
this._entity = null;
|
|
1448
|
+
this._built = false;
|
|
1322
1449
|
}
|
|
1323
1450
|
buildHierarchy(app) {
|
|
1324
1451
|
if (!this.entity || this._built)
|
|
@@ -1361,22 +1488,11 @@ class EntityElement extends AsyncElement {
|
|
|
1361
1488
|
}
|
|
1362
1489
|
}
|
|
1363
1490
|
disconnectedCallback() {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
// on re-insertion, so the descendant would get a fresh entity that is never parented.
|
|
1370
|
-
const children = this.querySelectorAll('pc-entity');
|
|
1371
|
-
children.forEach((child) => {
|
|
1372
|
-
child._entity = null;
|
|
1373
|
-
child._built = false;
|
|
1374
|
-
});
|
|
1375
|
-
// Destroy the entity
|
|
1376
|
-
this.entity.destroy();
|
|
1377
|
-
this._entity = null;
|
|
1378
|
-
this._built = false;
|
|
1379
|
-
}
|
|
1491
|
+
// Destroying the entity destroys its whole subtree, and the engine fires 'destroy' for
|
|
1492
|
+
// every entity in it - so _onEntityDestroy resets this element AND every descendant
|
|
1493
|
+
// element before the descendants' own disconnectedCallbacks run. Their entities are null
|
|
1494
|
+
// by then, making this call a no-op for them.
|
|
1495
|
+
this._entity?.destroy();
|
|
1380
1496
|
}
|
|
1381
1497
|
/**
|
|
1382
1498
|
* Sets the enabled state of the entity.
|
|
@@ -2523,6 +2639,10 @@ class ButtonComponentElement extends ComponentElement {
|
|
|
2523
2639
|
}
|
|
2524
2640
|
customElements.define('pc-button', ButtonComponentElement);
|
|
2525
2641
|
|
|
2642
|
+
const projections = new Map([
|
|
2643
|
+
['perspective', PROJECTION_PERSPECTIVE],
|
|
2644
|
+
['orthographic', PROJECTION_ORTHOGRAPHIC]
|
|
2645
|
+
]);
|
|
2526
2646
|
const tonemaps = new Map([
|
|
2527
2647
|
['none', TONEMAP_NONE],
|
|
2528
2648
|
['linear', TONEMAP_LINEAR],
|
|
@@ -2553,7 +2673,7 @@ class CameraComponentElement extends ComponentElement {
|
|
|
2553
2673
|
_gamma = 'srgb';
|
|
2554
2674
|
_horizontalFov = false;
|
|
2555
2675
|
_nearClip = 0.1;
|
|
2556
|
-
|
|
2676
|
+
_projection = 'perspective';
|
|
2557
2677
|
_orthoHeight = 10;
|
|
2558
2678
|
_priority = 0;
|
|
2559
2679
|
_rect = new Vec4(0, 0, 1, 1);
|
|
@@ -2577,12 +2697,12 @@ class CameraComponentElement extends ComponentElement {
|
|
|
2577
2697
|
gammaCorrection: this._gamma === 'srgb' ? GAMMA_SRGB : GAMMA_NONE,
|
|
2578
2698
|
horizontalFov: this._horizontalFov,
|
|
2579
2699
|
nearClip: this._nearClip,
|
|
2580
|
-
projection: this.
|
|
2700
|
+
projection: projections.get(this._projection) ?? PROJECTION_PERSPECTIVE,
|
|
2581
2701
|
orthoHeight: this._orthoHeight,
|
|
2582
2702
|
priority: this._priority,
|
|
2583
2703
|
rect: this._rect,
|
|
2584
2704
|
scissorRect: this._scissorRect,
|
|
2585
|
-
toneMapping: tonemaps.get(this._tonemap)
|
|
2705
|
+
toneMapping: tonemaps.get(this._tonemap) ?? TONEMAP_NONE
|
|
2586
2706
|
};
|
|
2587
2707
|
}
|
|
2588
2708
|
get xrAvailable() {
|
|
@@ -2824,23 +2944,6 @@ class CameraComponentElement extends ComponentElement {
|
|
|
2824
2944
|
get nearClip() {
|
|
2825
2945
|
return this._nearClip;
|
|
2826
2946
|
}
|
|
2827
|
-
/**
|
|
2828
|
-
* Sets the orthographic projection of the camera.
|
|
2829
|
-
* @param value - The orthographic projection.
|
|
2830
|
-
*/
|
|
2831
|
-
set orthographic(value) {
|
|
2832
|
-
this._orthographic = value;
|
|
2833
|
-
if (this.component) {
|
|
2834
|
-
this.component.projection = value ? PROJECTION_ORTHOGRAPHIC : PROJECTION_PERSPECTIVE;
|
|
2835
|
-
}
|
|
2836
|
-
}
|
|
2837
|
-
/**
|
|
2838
|
-
* Gets the orthographic projection of the camera.
|
|
2839
|
-
* @returns The orthographic projection.
|
|
2840
|
-
*/
|
|
2841
|
-
get orthographic() {
|
|
2842
|
-
return this._orthographic;
|
|
2843
|
-
}
|
|
2844
2947
|
/**
|
|
2845
2948
|
* Sets the orthographic height of the camera.
|
|
2846
2949
|
* @param value - The orthographic height.
|
|
@@ -2875,6 +2978,23 @@ class CameraComponentElement extends ComponentElement {
|
|
|
2875
2978
|
get priority() {
|
|
2876
2979
|
return this._priority;
|
|
2877
2980
|
}
|
|
2981
|
+
/**
|
|
2982
|
+
* Sets the projection of the camera. Use `orthoHeight` to size an orthographic projection.
|
|
2983
|
+
* @param value - The projection ('perspective' or 'orthographic').
|
|
2984
|
+
*/
|
|
2985
|
+
set projection(value) {
|
|
2986
|
+
this._projection = value;
|
|
2987
|
+
if (this.component) {
|
|
2988
|
+
this.component.projection = projections.get(value) ?? PROJECTION_PERSPECTIVE;
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
/**
|
|
2992
|
+
* Gets the projection of the camera.
|
|
2993
|
+
* @returns The projection.
|
|
2994
|
+
*/
|
|
2995
|
+
get projection() {
|
|
2996
|
+
return this._projection;
|
|
2997
|
+
}
|
|
2878
2998
|
/**
|
|
2879
2999
|
* Sets the rect of the camera.
|
|
2880
3000
|
* @param value - The rect.
|
|
@@ -2941,9 +3061,9 @@ class CameraComponentElement extends ComponentElement {
|
|
|
2941
3061
|
'gamma',
|
|
2942
3062
|
'horizontal-fov',
|
|
2943
3063
|
'near-clip',
|
|
2944
|
-
'orthographic',
|
|
2945
3064
|
'ortho-height',
|
|
2946
3065
|
'priority',
|
|
3066
|
+
'projection',
|
|
2947
3067
|
'rect',
|
|
2948
3068
|
'scissor-rect',
|
|
2949
3069
|
'tonemap'
|
|
@@ -2988,15 +3108,15 @@ class CameraComponentElement extends ComponentElement {
|
|
|
2988
3108
|
case 'near-clip':
|
|
2989
3109
|
this.nearClip = parseNumber(newValue, 0.1, name);
|
|
2990
3110
|
break;
|
|
2991
|
-
case 'orthographic':
|
|
2992
|
-
this.orthographic = parseBool(newValue, false);
|
|
2993
|
-
break;
|
|
2994
3111
|
case 'ortho-height':
|
|
2995
3112
|
this.orthoHeight = parseNumber(newValue, 10, name);
|
|
2996
3113
|
break;
|
|
2997
3114
|
case 'priority':
|
|
2998
3115
|
this.priority = parseNumber(newValue, 0, name);
|
|
2999
3116
|
break;
|
|
3117
|
+
case 'projection':
|
|
3118
|
+
this.projection = parseEnum(newValue, projections, 'perspective', name);
|
|
3119
|
+
break;
|
|
3000
3120
|
case 'rect':
|
|
3001
3121
|
this.rect = parseVec4(newValue, new Vec4(0, 0, 1, 1), name);
|
|
3002
3122
|
break;
|
|
@@ -7414,6 +7534,14 @@ class RigidBodyComponentElement extends ComponentElement {
|
|
|
7414
7534
|
}
|
|
7415
7535
|
customElements.define('pc-rigidbody', RigidBodyComponentElement);
|
|
7416
7536
|
|
|
7537
|
+
// The engine's SCALEMODE_* constants are the strings 'none' and 'blend', so this map happens to be
|
|
7538
|
+
// an identity. It is still the right shape: it supplies parseEnum's valid-name list, it is what the
|
|
7539
|
+
// manifest generator reads the enum values from, and it keeps the attribute vocabulary independent
|
|
7540
|
+
// of constants the engine is free to change.
|
|
7541
|
+
const scaleModes = new Map([
|
|
7542
|
+
['none', SCALEMODE_NONE],
|
|
7543
|
+
['blend', SCALEMODE_BLEND]
|
|
7544
|
+
]);
|
|
7417
7545
|
/**
|
|
7418
7546
|
* The ScreenComponentElement interface provides properties and methods for manipulating
|
|
7419
7547
|
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-screen/ | `<pc-screen>`} elements.
|
|
@@ -7427,7 +7555,7 @@ class ScreenComponentElement extends ComponentElement {
|
|
|
7427
7555
|
_resolution = new Vec2(640, 320);
|
|
7428
7556
|
_referenceResolution = new Vec2(640, 320);
|
|
7429
7557
|
_priority = 0;
|
|
7430
|
-
|
|
7558
|
+
_scaleMode = 'none';
|
|
7431
7559
|
_scaleBlend = 0.5;
|
|
7432
7560
|
/** @ignore */
|
|
7433
7561
|
constructor() {
|
|
@@ -7439,7 +7567,7 @@ class ScreenComponentElement extends ComponentElement {
|
|
|
7439
7567
|
referenceResolution: this._referenceResolution,
|
|
7440
7568
|
resolution: this._resolution,
|
|
7441
7569
|
scaleBlend: this._scaleBlend,
|
|
7442
|
-
scaleMode: this.
|
|
7570
|
+
scaleMode: scaleModes.get(this._scaleMode) ?? SCALEMODE_NONE,
|
|
7443
7571
|
screenSpace: this._screenSpace
|
|
7444
7572
|
};
|
|
7445
7573
|
}
|
|
@@ -7477,23 +7605,44 @@ class ScreenComponentElement extends ComponentElement {
|
|
|
7477
7605
|
get resolution() {
|
|
7478
7606
|
return this._resolution;
|
|
7479
7607
|
}
|
|
7608
|
+
/**
|
|
7609
|
+
* Sets how the screen's `resolution` and `referenceResolution` are weighted against each other
|
|
7610
|
+
* when `scaleMode` is `blend`, from 0 (follow the resolution) to 1 (follow the reference
|
|
7611
|
+
* resolution). Ignored while `scaleMode` is `none`.
|
|
7612
|
+
* @param value - The scale blend factor.
|
|
7613
|
+
*/
|
|
7480
7614
|
set scaleBlend(value) {
|
|
7481
7615
|
this._scaleBlend = value;
|
|
7482
7616
|
if (this.component) {
|
|
7483
7617
|
this.component.scaleBlend = this._scaleBlend;
|
|
7484
7618
|
}
|
|
7485
7619
|
}
|
|
7620
|
+
/**
|
|
7621
|
+
* Gets how the screen's resolutions are weighted against each other.
|
|
7622
|
+
* @returns The scale blend factor.
|
|
7623
|
+
*/
|
|
7486
7624
|
get scaleBlend() {
|
|
7487
7625
|
return this._scaleBlend;
|
|
7488
7626
|
}
|
|
7489
|
-
|
|
7490
|
-
|
|
7627
|
+
/**
|
|
7628
|
+
* Sets how the screen scales its contents. `none` renders at `resolution` and ignores
|
|
7629
|
+
* `referenceResolution`; `blend` scales between the two, weighted by `scaleBlend`, which is what
|
|
7630
|
+
* keeps a UI laid out at one resolution usable at another. Requires `screenSpace` - the engine
|
|
7631
|
+
* forces `none` on a world-space screen, which does not support scaling.
|
|
7632
|
+
* @param value - The scale mode ('none' or 'blend').
|
|
7633
|
+
*/
|
|
7634
|
+
set scaleMode(value) {
|
|
7635
|
+
this._scaleMode = value;
|
|
7491
7636
|
if (this.component) {
|
|
7492
|
-
this.component.scaleMode =
|
|
7637
|
+
this.component.scaleMode = scaleModes.get(value) ?? SCALEMODE_NONE;
|
|
7493
7638
|
}
|
|
7494
7639
|
}
|
|
7495
|
-
|
|
7496
|
-
|
|
7640
|
+
/**
|
|
7641
|
+
* Gets how the screen scales its contents.
|
|
7642
|
+
* @returns The scale mode.
|
|
7643
|
+
*/
|
|
7644
|
+
get scaleMode() {
|
|
7645
|
+
return this._scaleMode;
|
|
7497
7646
|
}
|
|
7498
7647
|
set screenSpace(value) {
|
|
7499
7648
|
this._screenSpace = value;
|
|
@@ -7507,12 +7656,12 @@ class ScreenComponentElement extends ComponentElement {
|
|
|
7507
7656
|
static get observedAttributes() {
|
|
7508
7657
|
return [
|
|
7509
7658
|
...super.observedAttributes,
|
|
7510
|
-
'blend',
|
|
7511
7659
|
'screen-space',
|
|
7512
7660
|
'resolution',
|
|
7513
7661
|
'reference-resolution',
|
|
7514
7662
|
'priority',
|
|
7515
|
-
'scale-blend'
|
|
7663
|
+
'scale-blend',
|
|
7664
|
+
'scale-mode'
|
|
7516
7665
|
];
|
|
7517
7666
|
}
|
|
7518
7667
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
@@ -7530,8 +7679,8 @@ class ScreenComponentElement extends ComponentElement {
|
|
|
7530
7679
|
case 'scale-blend':
|
|
7531
7680
|
this.scaleBlend = parseNumber(newValue, 0.5, name);
|
|
7532
7681
|
break;
|
|
7533
|
-
case '
|
|
7534
|
-
this.
|
|
7682
|
+
case 'scale-mode':
|
|
7683
|
+
this.scaleMode = parseEnum(newValue, scaleModes, 'none', name);
|
|
7535
7684
|
break;
|
|
7536
7685
|
case 'screen-space':
|
|
7537
7686
|
this.screenSpace = parseBool(newValue, false);
|
|
@@ -7754,7 +7903,8 @@ class ScrollViewComponentElement extends ComponentElement {
|
|
|
7754
7903
|
return super.component;
|
|
7755
7904
|
}
|
|
7756
7905
|
/**
|
|
7757
|
-
* Sets whether horizontal
|
|
7906
|
+
* Sets whether scrolling along the horizontal axis is enabled. This is a toggle, unlike the
|
|
7907
|
+
* `orientation` of a `<pc-scrollbar>`, for which `horizontal` is one of the accepted values.
|
|
7758
7908
|
* @param value - Whether horizontal scrolling is enabled.
|
|
7759
7909
|
*/
|
|
7760
7910
|
set horizontal(value) {
|
|
@@ -7764,14 +7914,15 @@ class ScrollViewComponentElement extends ComponentElement {
|
|
|
7764
7914
|
}
|
|
7765
7915
|
}
|
|
7766
7916
|
/**
|
|
7767
|
-
* Gets whether horizontal
|
|
7917
|
+
* Gets whether scrolling along the horizontal axis is enabled.
|
|
7768
7918
|
* @returns Whether horizontal scrolling is enabled.
|
|
7769
7919
|
*/
|
|
7770
7920
|
get horizontal() {
|
|
7771
7921
|
return this._horizontal;
|
|
7772
7922
|
}
|
|
7773
7923
|
/**
|
|
7774
|
-
* Sets whether vertical
|
|
7924
|
+
* Sets whether scrolling along the vertical axis is enabled. This is a toggle, unlike the
|
|
7925
|
+
* `orientation` of a `<pc-scrollbar>`, for which `vertical` is one of the accepted values.
|
|
7775
7926
|
* @param value - Whether vertical scrolling is enabled.
|
|
7776
7927
|
*/
|
|
7777
7928
|
set vertical(value) {
|
|
@@ -7781,7 +7932,7 @@ class ScrollViewComponentElement extends ComponentElement {
|
|
|
7781
7932
|
}
|
|
7782
7933
|
}
|
|
7783
7934
|
/**
|
|
7784
|
-
* Gets whether vertical
|
|
7935
|
+
* Gets whether scrolling along the vertical axis is enabled.
|
|
7785
7936
|
* @returns Whether vertical scrolling is enabled.
|
|
7786
7937
|
*/
|
|
7787
7938
|
get vertical() {
|
|
@@ -9771,7 +9922,7 @@ class SkyElement extends AsyncElement {
|
|
|
9771
9922
|
_center = new Vec3(0, 0.01, 0);
|
|
9772
9923
|
_intensity = 1;
|
|
9773
9924
|
_rotation = new Vec3();
|
|
9774
|
-
|
|
9925
|
+
_mipLevel = 0;
|
|
9775
9926
|
_lighting = false;
|
|
9776
9927
|
_scale = new Vec3(100, 100, 100);
|
|
9777
9928
|
_type = 'infinite';
|
|
@@ -9805,7 +9956,7 @@ class SkyElement extends AsyncElement {
|
|
|
9805
9956
|
this._scene.sky.node.setLocalScale(this._scale);
|
|
9806
9957
|
this._scene.sky.center = this._center;
|
|
9807
9958
|
this._scene.skyboxIntensity = this._intensity;
|
|
9808
|
-
this._scene.skyboxMip = this.
|
|
9959
|
+
this._scene.skyboxMip = this._mipLevel;
|
|
9809
9960
|
}
|
|
9810
9961
|
async _loadSkybox() {
|
|
9811
9962
|
const appElement = await this.closestApp?.ready();
|
|
@@ -9897,23 +10048,6 @@ class SkyElement extends AsyncElement {
|
|
|
9897
10048
|
get intensity() {
|
|
9898
10049
|
return this._intensity;
|
|
9899
10050
|
}
|
|
9900
|
-
/**
|
|
9901
|
-
* Sets the mip level of the skybox.
|
|
9902
|
-
* @param value - The mip level.
|
|
9903
|
-
*/
|
|
9904
|
-
set level(value) {
|
|
9905
|
-
this._level = value;
|
|
9906
|
-
if (this._scene) {
|
|
9907
|
-
this._scene.skyboxMip = this._level;
|
|
9908
|
-
}
|
|
9909
|
-
}
|
|
9910
|
-
/**
|
|
9911
|
-
* Gets the mip level of the skybox.
|
|
9912
|
-
* @returns The mip level.
|
|
9913
|
-
*/
|
|
9914
|
-
get level() {
|
|
9915
|
-
return this._level;
|
|
9916
|
-
}
|
|
9917
10051
|
/**
|
|
9918
10052
|
* Sets whether the skybox is used as a light source.
|
|
9919
10053
|
* @param value - Whether to use lighting.
|
|
@@ -9928,6 +10062,24 @@ class SkyElement extends AsyncElement {
|
|
|
9928
10062
|
get lighting() {
|
|
9929
10063
|
return this._lighting;
|
|
9930
10064
|
}
|
|
10065
|
+
/**
|
|
10066
|
+
* Sets the mip level of the skybox, where 0 is the sharpest. Raising it selects a blurrier mip,
|
|
10067
|
+
* which is how a skybox is softened without blurring the texture itself.
|
|
10068
|
+
* @param value - The mip level.
|
|
10069
|
+
*/
|
|
10070
|
+
set mipLevel(value) {
|
|
10071
|
+
this._mipLevel = value;
|
|
10072
|
+
if (this._scene) {
|
|
10073
|
+
this._scene.skyboxMip = this._mipLevel;
|
|
10074
|
+
}
|
|
10075
|
+
}
|
|
10076
|
+
/**
|
|
10077
|
+
* Gets the mip level of the skybox.
|
|
10078
|
+
* @returns The mip level.
|
|
10079
|
+
*/
|
|
10080
|
+
get mipLevel() {
|
|
10081
|
+
return this._mipLevel;
|
|
10082
|
+
}
|
|
9931
10083
|
/**
|
|
9932
10084
|
* Sets the Euler rotation of the skybox.
|
|
9933
10085
|
* @param value - The rotation.
|
|
@@ -9984,7 +10136,7 @@ class SkyElement extends AsyncElement {
|
|
|
9984
10136
|
return this._type;
|
|
9985
10137
|
}
|
|
9986
10138
|
static get observedAttributes() {
|
|
9987
|
-
return ['asset', 'center', 'intensity', '
|
|
10139
|
+
return ['asset', 'center', 'intensity', 'lighting', 'mip-level', 'rotation', 'scale', 'type'];
|
|
9988
10140
|
}
|
|
9989
10141
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
9990
10142
|
switch (name) {
|
|
@@ -9997,12 +10149,12 @@ class SkyElement extends AsyncElement {
|
|
|
9997
10149
|
case 'intensity':
|
|
9998
10150
|
this.intensity = parseNumber(newValue, 1, name);
|
|
9999
10151
|
break;
|
|
10000
|
-
case 'level':
|
|
10001
|
-
this.level = parseNumber(newValue, 0, name);
|
|
10002
|
-
break;
|
|
10003
10152
|
case 'lighting':
|
|
10004
10153
|
this.lighting = parseBool(newValue, false);
|
|
10005
10154
|
break;
|
|
10155
|
+
case 'mip-level':
|
|
10156
|
+
this.mipLevel = parseNumber(newValue, 0, name);
|
|
10157
|
+
break;
|
|
10006
10158
|
case 'rotation':
|
|
10007
10159
|
this.rotation = parseVec3(newValue, Vec3.ZERO, name);
|
|
10008
10160
|
break;
|