@mml-io/mml-web-client 0.19.2 → 0.19.4

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/build/index.js CHANGED
@@ -985,6 +985,8 @@
985
985
  case "changeHiddenFrom":
986
986
  this.handleChangeHiddenFrom(message);
987
987
  break;
988
+ case "changeVisibleTo":
989
+ break;
988
990
  case "childrenRemoved":
989
991
  this.handleChildrenRemoved(message);
990
992
  break;
@@ -1895,6 +1897,7 @@
1895
1897
  constructor() {
1896
1898
  super();
1897
1899
  this.mElementGraphics = null;
1900
+ this.isMElement = true;
1898
1901
  }
1899
1902
  // This allows switching which document this HTMLElement subclass extends so that it can be placed into iframes
1900
1903
  static overwriteSuperclass(newSuperclass) {
@@ -1903,6 +1906,9 @@
1903
1906
  static get observedAttributes() {
1904
1907
  return [];
1905
1908
  }
1909
+ static isMElement(element) {
1910
+ return element.isMElement;
1911
+ }
1906
1912
  static getMElementFromObject(object) {
1907
1913
  return object[MELEMENT_PROPERTY_NAME] || null;
1908
1914
  }
@@ -2076,7 +2082,7 @@
2076
2082
  getMElementParent() {
2077
2083
  let parentNode = this.parentNode;
2078
2084
  while (parentNode != null) {
2079
- if (parentNode instanceof _MElement) {
2085
+ if (_MElement.isMElement(parentNode)) {
2080
2086
  return parentNode;
2081
2087
  }
2082
2088
  parentNode = parentNode.parentNode;
@@ -2123,6 +2129,10 @@
2123
2129
  animDuration: defaultAnimDuration
2124
2130
  };
2125
2131
  this.registeredParentAttachment = null;
2132
+ this.isAttributeAnimation = true;
2133
+ }
2134
+ static isAttributeAnimation(element) {
2135
+ return element.isAttributeAnimation;
2126
2136
  }
2127
2137
  static get observedAttributes() {
2128
2138
  return [..._AttributeAnimation2.attributeHandler.getAttributes()];
@@ -2148,7 +2158,7 @@
2148
2158
  }
2149
2159
  connectedCallback() {
2150
2160
  super.connectedCallback();
2151
- if (this.parentElement && this.parentElement instanceof MElement) {
2161
+ if (this.parentElement && MElement.isMElement(this.parentElement)) {
2152
2162
  this.registeredParentAttachment = this.parentElement;
2153
2163
  if (this.props.attr) {
2154
2164
  this.registeredParentAttachment.addSideEffectChild(this);
@@ -2259,6 +2269,10 @@
2259
2269
  lerpDuration: defaultLerpDuration
2260
2270
  };
2261
2271
  this.registeredParentAttachment = null;
2272
+ this.isAttributeLerp = true;
2273
+ }
2274
+ static isAttributeLerp(element) {
2275
+ return element.isAttributeLerp;
2262
2276
  }
2263
2277
  static get observedAttributes() {
2264
2278
  return [..._AttributeLerp2.attributeHandler.getAttributes()];
@@ -2284,7 +2298,7 @@
2284
2298
  }
2285
2299
  connectedCallback() {
2286
2300
  super.connectedCallback();
2287
- if (this.parentElement && this.parentElement instanceof MElement) {
2301
+ if (this.parentElement && MElement.isMElement(this.parentElement)) {
2288
2302
  this.registeredParentAttachment = this.parentElement;
2289
2303
  this.registeredParentAttachment.addSideEffectChild(this);
2290
2304
  }
@@ -2303,13 +2317,20 @@
2303
2317
  }
2304
2318
  return lerpHSL(previousValue, elementValue, ratio);
2305
2319
  }
2306
- getFloatValueForTime(windowTime, elementValueSetTime, elementValue, previousValue) {
2307
- const from = previousValue;
2320
+ getFloatValueForTime(windowTime, elementValueSetTime, elementValue, previousValue, isDegrees) {
2321
+ let from = previousValue;
2308
2322
  const to = elementValue;
2309
2323
  const ratio = this.getLerpRatio(windowTime, elementValueSetTime);
2310
2324
  if (ratio >= 1) {
2311
2325
  return to;
2312
2326
  }
2327
+ if (isDegrees) {
2328
+ if (to - from > 180) {
2329
+ from += 360;
2330
+ } else if (from - to > 180) {
2331
+ from -= 360;
2332
+ }
2333
+ }
2313
2334
  return from + (to - from) * ratio;
2314
2335
  }
2315
2336
  getLerpRatio(windowTime, elementValueSetTime) {
@@ -2367,6 +2388,9 @@
2367
2388
  }
2368
2389
  }
2369
2390
  function isColorAttribute(attributeState) {
2391
+ return attributeState.type === 2;
2392
+ }
2393
+ function isDegreesAttribute(attributeState) {
2370
2394
  return attributeState.type === 1;
2371
2395
  }
2372
2396
  function isNumberAttribute(attributeState) {
@@ -2385,12 +2409,12 @@
2385
2409
  this.reset();
2386
2410
  }
2387
2411
  addSideEffectChild(child) {
2388
- if (child instanceof AttributeAnimation) {
2412
+ if (AttributeAnimation.isAttributeAnimation(child)) {
2389
2413
  const attr = child.getAnimatedAttributeName();
2390
2414
  if (attr) {
2391
2415
  this.addAnimation(child, attr);
2392
2416
  }
2393
- } else if (child instanceof AttributeLerp) {
2417
+ } else if (AttributeLerp.isAttributeLerp(child)) {
2394
2418
  const attr = child.getAnimatedAttributeName();
2395
2419
  if (attr) {
2396
2420
  this.addLerp(child, attr);
@@ -2398,12 +2422,12 @@
2398
2422
  }
2399
2423
  }
2400
2424
  removeSideEffectChild(child) {
2401
- if (child instanceof AttributeAnimation) {
2425
+ if (AttributeAnimation.isAttributeAnimation(child)) {
2402
2426
  const attr = child.getAnimatedAttributeName();
2403
2427
  if (attr) {
2404
2428
  this.removeAnimation(child, attr);
2405
2429
  }
2406
- } else if (child instanceof AttributeLerp) {
2430
+ } else if (AttributeLerp.isAttributeLerp(child)) {
2407
2431
  const attr = child.getAnimatedAttributeName();
2408
2432
  if (attr) {
2409
2433
  this.removeLerp(child, attr);
@@ -2525,7 +2549,7 @@
2525
2549
  let stale = null;
2526
2550
  const state = this.stateByAttribute[key];
2527
2551
  for (const animation of state.animationsInOrder) {
2528
- const [newValue, active] = state.attributeState.type === 1 ? animation.getColorValueForTime(documentTime) : animation.getFloatValueForTime(documentTime);
2552
+ const [newValue, active] = state.attributeState.type === 2 ? animation.getColorValueForTime(documentTime) : animation.getFloatValueForTime(documentTime);
2529
2553
  if (active === 0) {
2530
2554
  updateIfChangedValue(state, newValue);
2531
2555
  stale = null;
@@ -2561,6 +2585,17 @@
2561
2585
  config.previousValue
2562
2586
  )
2563
2587
  );
2588
+ } else if (isDegreesAttribute(config)) {
2589
+ updateIfChangedValue(
2590
+ state,
2591
+ lerp2.getFloatValueForTime(
2592
+ this.element.getWindowTime(),
2593
+ config.elementValueSetTime,
2594
+ config.elementValue,
2595
+ config.previousValue,
2596
+ true
2597
+ )
2598
+ );
2564
2599
  } else if (isNumberAttribute(config)) {
2565
2600
  updateIfChangedValue(
2566
2601
  state,
@@ -2568,7 +2603,8 @@
2568
2603
  this.element.getWindowTime(),
2569
2604
  config.elementValueSetTime,
2570
2605
  config.elementValue,
2571
- config.previousValue
2606
+ config.previousValue,
2607
+ false
2572
2608
  )
2573
2609
  );
2574
2610
  }
@@ -3530,6 +3566,7 @@
3530
3566
  var _TransformableElement = class _TransformableElement2 extends MElement {
3531
3567
  constructor() {
3532
3568
  super(...arguments);
3569
+ this.isTransformableElement = true;
3533
3570
  this.transformableElementProps = {
3534
3571
  socket: null,
3535
3572
  x: 0,
@@ -3579,7 +3616,7 @@
3579
3616
  }
3580
3617
  ],
3581
3618
  rx: [
3582
- 0,
3619
+ 1,
3583
3620
  0,
3584
3621
  (newValue) => {
3585
3622
  var _a2;
@@ -3589,7 +3626,7 @@
3589
3626
  }
3590
3627
  ],
3591
3628
  ry: [
3592
- 0,
3629
+ 1,
3593
3630
  0,
3594
3631
  (newValue) => {
3595
3632
  var _a2;
@@ -3599,7 +3636,7 @@
3599
3636
  }
3600
3637
  ],
3601
3638
  rz: [
3602
- 0,
3639
+ 1,
3603
3640
  0,
3604
3641
  (newValue) => {
3605
3642
  var _a2;
@@ -3650,10 +3687,13 @@
3650
3687
  });
3651
3688
  this.debugHelper = new DebugHelper(this);
3652
3689
  }
3690
+ static isTransformableElement(element) {
3691
+ return element.isTransformableElement;
3692
+ }
3653
3693
  getTransformableElementParent() {
3654
3694
  let parentNode = this.parentNode;
3655
3695
  while (parentNode != null) {
3656
- if (parentNode instanceof _TransformableElement2) {
3696
+ if (_TransformableElement2.isTransformableElement(parentNode)) {
3657
3697
  return parentNode;
3658
3698
  }
3659
3699
  parentNode = parentNode.parentNode;
@@ -3906,7 +3946,7 @@
3906
3946
  var TransformableElement = _TransformableElement;
3907
3947
  function traverseImmediateTransformableElementChildren(element, callback) {
3908
3948
  element.childNodes.forEach((child) => {
3909
- if (child instanceof TransformableElement) {
3949
+ if (TransformableElement.isTransformableElement(child)) {
3910
3950
  callback(child);
3911
3951
  } else {
3912
3952
  traverseImmediateTransformableElementChildren(child, callback);
@@ -4116,9 +4156,12 @@
4116
4156
  castShadows: defaultModelCastShadows,
4117
4157
  debug: defaultModelDebug
4118
4158
  };
4119
- this.isModel = true;
4120
4159
  this.collideableHelper = new CollideableHelper(this);
4121
4160
  this.modelGraphics = null;
4161
+ this.isModel = true;
4162
+ }
4163
+ static isModel(element) {
4164
+ return element.isModel;
4122
4165
  }
4123
4166
  enable() {
4124
4167
  this.collideableHelper.enable();
@@ -4269,7 +4312,7 @@
4269
4312
  tempContainerMatrix.identity();
4270
4313
  const tempMatr4 = new Matr4();
4271
4314
  for (let obj = container; obj; obj = obj.parentNode) {
4272
- if (obj instanceof TransformableElement) {
4315
+ if (TransformableElement.isTransformableElement(obj)) {
4273
4316
  obj.calculateLocalMatrix(tempMatr4);
4274
4317
  tempContainerMatrix.premultiply(tempMatr4);
4275
4318
  }
@@ -4455,7 +4498,7 @@
4455
4498
  };
4456
4499
  this.cubeAnimatedAttributeHelper = new AnimatedAttributeHelper(this, {
4457
4500
  color: [
4458
- 1,
4501
+ 2,
4459
4502
  defaultCubeColor,
4460
4503
  (newValue) => {
4461
4504
  var _a2;
@@ -4634,7 +4677,7 @@
4634
4677
  };
4635
4678
  this.cylinderAnimatedAttributeHelper = new AnimatedAttributeHelper(this, {
4636
4679
  color: [
4637
- 1,
4680
+ 2,
4638
4681
  defaultCylinderColor,
4639
4682
  (newValue) => {
4640
4683
  var _a2;
@@ -6005,7 +6048,7 @@
6005
6048
  this.collideableHelper = new CollideableHelper(this);
6006
6049
  this.labelAnimatedAttributeHelper = new AnimatedAttributeHelper(this, {
6007
6050
  color: [
6008
- 1,
6051
+ 2,
6009
6052
  defaultLabelColor,
6010
6053
  (newValue) => {
6011
6054
  var _a2;
@@ -6014,7 +6057,7 @@
6014
6057
  }
6015
6058
  ],
6016
6059
  "font-color": [
6017
- 1,
6060
+ 2,
6018
6061
  defaultFontColor,
6019
6062
  (newValue) => {
6020
6063
  var _a2;
@@ -6217,7 +6260,7 @@
6217
6260
  super();
6218
6261
  this.lightAnimatedAttributeHelper = new AnimatedAttributeHelper(this, {
6219
6262
  color: [
6220
- 1,
6263
+ 2,
6221
6264
  defaultLightColor,
6222
6265
  (newValue) => {
6223
6266
  var _a2;
@@ -6278,7 +6321,7 @@
6278
6321
  return OrientedBoundingBox.fromMatrixWorld(this.transformableElementGraphics.getWorldMatrix());
6279
6322
  }
6280
6323
  addSideEffectChild(child) {
6281
- if (child instanceof AttributeAnimation) {
6324
+ if (AttributeAnimation.isAttributeAnimation(child)) {
6282
6325
  const attr = child.getAnimatedAttributeName();
6283
6326
  if (attr) {
6284
6327
  this.lightAnimatedAttributeHelper.addAnimation(child, attr);
@@ -6287,7 +6330,7 @@
6287
6330
  super.addSideEffectChild(child);
6288
6331
  }
6289
6332
  removeSideEffectChild(child) {
6290
- if (child instanceof AttributeAnimation) {
6333
+ if (AttributeAnimation.isAttributeAnimation(child)) {
6291
6334
  const attr = child.getAnimatedAttributeName();
6292
6335
  if (attr) {
6293
6336
  this.lightAnimatedAttributeHelper.removeAnimation(child, attr);
@@ -6490,7 +6533,7 @@
6490
6533
  };
6491
6534
  this.planeAnimatedAttributeHelper = new AnimatedAttributeHelper(this, {
6492
6535
  color: [
6493
- 1,
6536
+ 2,
6494
6537
  defaultPlaneColor,
6495
6538
  (newValue) => {
6496
6539
  var _a2;
@@ -7072,7 +7115,7 @@
7072
7115
  };
7073
7116
  this.sphereAnimatedAttributeHelper = new AnimatedAttributeHelper(this, {
7074
7117
  color: [
7075
- 1,
7118
+ 2,
7076
7119
  defaultSphereColor,
7077
7120
  (newValue) => {
7078
7121
  var _a2;
@@ -8186,7 +8229,7 @@
8186
8229
  var _a2;
8187
8230
  for (const i in element.children) {
8188
8231
  const child = element.children[i];
8189
- if (child instanceof MElement) {
8232
+ if (MElement.isMElement(child)) {
8190
8233
  (_a2 = child.connectedCallback) == null ? void 0 : _a2.call(child);
8191
8234
  }
8192
8235
  traverse(child);
@@ -63477,7 +63520,7 @@ ${DracoWorker.toString()}
63477
63520
  break;
63478
63521
  }
63479
63522
  }
63480
- if (mElement && mElement instanceof TransformableElement && mElement.isClickable()) {
63523
+ if (mElement && TransformableElement.isTransformableElement(mElement) && mElement.isClickable()) {
63481
63524
  const elementRelative = getRelativePositionAndRotationRelativeToObject(
63482
63525
  {
63483
63526
  position: result.point,
@@ -64914,7 +64957,7 @@ ${DracoWorker.toString()}
64914
64957
  this.latestAnimPromise = null;
64915
64958
  if (this.loadedState && !this.registeredParentAttachment) {
64916
64959
  const parent = this.model.parentElement;
64917
- if (parent instanceof Model) {
64960
+ if (parent && Model.isModel(parent)) {
64918
64961
  this.registeredParentAttachment = parent;
64919
64962
  parent.modelGraphics.registerAttachment(this.model);
64920
64963
  }
@@ -65111,7 +65154,7 @@ ${DracoWorker.toString()}
65111
65154
  this.connectAnimationToModel();
65112
65155
  this.updateMeshCallback();
65113
65156
  const parent = this.model.parentElement;
65114
- if (parent instanceof Model) {
65157
+ if (parent && Model.isModel(parent)) {
65115
65158
  if (!this.latestAnimPromise && !this.animState) {
65116
65159
  this.registeredParentAttachment = parent;
65117
65160
  parent.modelGraphics.registerAttachment(this.model);
@@ -65210,7 +65253,7 @@ ${DracoWorker.toString()}
65210
65253
  triggerSocketedChildrenTransformed() {
65211
65254
  this.socketChildrenByBone.forEach((children) => {
65212
65255
  children.forEach((child) => {
65213
- if (child instanceof TransformableElement) {
65256
+ if (TransformableElement.isTransformableElement(child)) {
65214
65257
  child.didUpdateTransformation();
65215
65258
  }
65216
65259
  });
@@ -66534,7 +66577,7 @@ ${DracoWorker.toString()}
66534
66577
  return this.playcanvasApp.root;
66535
66578
  }
66536
66579
  getBoundingBoxForElement(element) {
66537
- if (!(element instanceof TransformableElement)) {
66580
+ if (!TransformableElement.isTransformableElement(element)) {
66538
66581
  return null;
66539
66582
  }
66540
66583
  const bounds = element.getContentBounds();
@@ -97212,10 +97255,13 @@ void main() {
97212
97255
  this.mesh.castShadow = castShadows;
97213
97256
  }
97214
97257
  setOpacity(opacity) {
97215
- const needsUpdate = this.material.transparent === (opacity === 1);
97216
- this.material.transparent = opacity !== 1;
97217
- this.material.needsUpdate = needsUpdate;
97258
+ const shouldBeTransparent = opacity !== 1 || this.loadedImageHasTransparency;
97259
+ const needsUpdate = this.material.transparent !== shouldBeTransparent;
97260
+ this.material.transparent = shouldBeTransparent;
97218
97261
  this.material.opacity = opacity;
97262
+ if (needsUpdate) {
97263
+ this.material.needsUpdate = true;
97264
+ }
97219
97265
  }
97220
97266
  setEmissive() {
97221
97267
  this.updateMaterialEmissiveIntensity();
@@ -97308,15 +97354,9 @@ void main() {
97308
97354
  if (!this.material) {
97309
97355
  return;
97310
97356
  }
97311
- if (this.loadedImageHasTransparency) {
97312
- this.material.alphaMap = new CanvasTexture(this.loadedImage);
97313
- this.material.alphaTest = 0.01;
97314
- } else {
97315
- this.material.alphaMap = null;
97316
- this.material.alphaTest = 0;
97317
- }
97318
- this.material.transparent = this.image.props.opacity !== 1 || this.loadedImageHasTransparency;
97319
97357
  this.material.map = new CanvasTexture(this.loadedImage);
97358
+ this.material.transparent = this.image.props.opacity !== 1 || this.loadedImageHasTransparency;
97359
+ this.material.alphaTest = 0.01;
97320
97360
  this.material.needsUpdate = true;
97321
97361
  this.updateMaterialEmissiveIntensity();
97322
97362
  this.updateWidthAndHeight();
@@ -97610,7 +97650,7 @@ void main() {
97610
97650
  this.threeLight.castShadow = this.light.props.castShadows;
97611
97651
  this.threeLight.shadow.mapSize.width = 512;
97612
97652
  this.threeLight.shadow.mapSize.height = 512;
97613
- if (this.threeLight.shadow.camera instanceof PerspectiveCamera) {
97653
+ if (this.threeLight.shadow.camera.isPerspectiveCamera) {
97614
97654
  this.threeLight.shadow.camera.near = 0.5;
97615
97655
  this.threeLight.shadow.camera.far = 500;
97616
97656
  }
@@ -97665,7 +97705,7 @@ void main() {
97665
97705
  this.threeLight.castShadow = castShadows;
97666
97706
  }
97667
97707
  setAngle(angle) {
97668
- if (this.threeLight instanceof SpotLight) {
97708
+ if (this.threeLight.isSpotLight) {
97669
97709
  this.threeLight.angle = MathUtils.degToRad(angle);
97670
97710
  }
97671
97711
  }
@@ -97816,7 +97856,7 @@ void main() {
97816
97856
  this.animLoadingInstanceManager.abortIfLoading();
97817
97857
  if (this.loadedState && !this.registeredParentAttachment) {
97818
97858
  const parent = this.model.parentElement;
97819
- if (parent instanceof Model) {
97859
+ if (parent && Model.isModel(parent)) {
97820
97860
  this.registeredParentAttachment = parent;
97821
97861
  parent.modelGraphics.registerAttachment(this.model);
97822
97862
  }
@@ -97933,7 +97973,7 @@ void main() {
97933
97973
  }
97934
97974
  this.updateMeshCallback();
97935
97975
  const parent = this.model.parentElement;
97936
- if (parent instanceof Model) {
97976
+ if (parent && Model.isModel(parent)) {
97937
97977
  if (!this.latestAnimPromise && !this.animState) {
97938
97978
  this.registeredParentAttachment = parent;
97939
97979
  parent.modelGraphics.registerAttachment(this.model);
@@ -98053,7 +98093,7 @@ void main() {
98053
98093
  triggerSocketedChildrenTransformed() {
98054
98094
  this.socketChildrenByBone.forEach((children) => {
98055
98095
  children.forEach((child) => {
98056
- if (child instanceof TransformableElement) {
98096
+ if (TransformableElement.isTransformableElement(child)) {
98057
98097
  child.didUpdateTransformation();
98058
98098
  }
98059
98099
  });
@@ -98764,7 +98804,7 @@ void main() {
98764
98804
  break;
98765
98805
  }
98766
98806
  const mElement = MElement.getMElementFromObject(obj);
98767
- if (mElement && mElement instanceof TransformableElement && mElement.isClickable()) {
98807
+ if (mElement && TransformableElement.isTransformableElement(mElement) && mElement.isClickable()) {
98768
98808
  const elementRelative = getRelativePositionAndRotationRelativeToObject(
98769
98809
  {
98770
98810
  position: intersection.point,
@@ -99395,7 +99435,7 @@ void main() {
99395
99435
  getBoundingBoxForElement(element) {
99396
99436
  const camera = this.camera;
99397
99437
  const renderer = this.renderer;
99398
- if (!(element instanceof MElement)) {
99438
+ if (!MElement.isMElement(element)) {
99399
99439
  return null;
99400
99440
  }
99401
99441
  const object = element.getContainer();