MikaFil commited on
Commit
37f9451
·
verified ·
1 Parent(s): 9531b00

Update orbit-camera.js

Browse files
Files changed (1) hide show
  1. orbit-camera.js +19 -30
orbit-camera.js CHANGED
@@ -1,4 +1,5 @@
1
  // orbit-camera.js
 
2
 
3
  var OrbitCamera = pc.createScript('orbitCamera');
4
 
@@ -166,43 +167,31 @@ OrbitCamera.prototype._updatePosition = function () {
166
  this.entity.setPosition(position);
167
  };
168
 
169
- OrbitCamera.prototype._removeInertia = function () {
170
- this._yaw = this._targetYaw;
171
- this._pitch = this._targetPitch;
172
- this._distance = this._targetDistance;
173
- };
174
-
175
- OrbitCamera.prototype._checkAspectRatio = function () {
176
- var height = this.app.graphicsDevice.height;
177
- var width = this.app.graphicsDevice.width;
178
- this.entity.camera.horizontalFov = (height > width);
179
- };
180
-
181
  OrbitCamera.prototype._buildAabb = function (entity) {
182
- var i, m, meshInstances = [];
 
183
  var renders = entity.findComponents('render');
184
- for (i = 0; i < renders.length; i++) {
185
- var render = renders[i];
186
- for (m = 0; m < render.meshInstances.length; m++) {
187
- meshInstances.push(render.meshInstances[m]);
188
- }
189
  }
 
190
  var models = entity.findComponents('model');
191
- for (i = 0; i < models.length; i++) {
192
- var model = models[i];
193
- for (m = 0; m < model.meshInstances.length; m++) {
194
- meshInstances.push(model.meshInstances[m]);
195
- }
196
  }
 
197
  var gsplats = entity.findComponents('gsplat');
198
- for (i = 0; i < gsplats.length; i++) {
199
- var gsplat = gsplats[i];
200
- var instance = gsplat.instance;
201
- if (instance?.meshInstance) {
202
- meshInstances.push(instance.meshInstance);
 
 
203
  }
204
  }
205
- for (i = 0; i < meshInstances.length; i++) {
206
  if (i === 0) {
207
  this._modelsAabb.copy(meshInstances[i].aabb);
208
  } else {
@@ -245,6 +234,7 @@ OrbitCamera.prototype._calcPitch = function (quat, yaw) {
245
  return Math.atan2(-transformedForward.y, -transformedForward.z) * pc.math.RAD_TO_DEG;
246
  };
247
 
 
248
  // ===================== Orbit Camera Input Mouse Script ========================
249
  var OrbitCameraInputMouse = pc.createScript('orbitCameraInputMouse');
250
  OrbitCameraInputMouse.attributes.add('orbitSensitivity', { type: 'number', default: 0.3, title: 'Orbit Sensitivity' });
@@ -490,4 +480,3 @@ OrbitCameraInputTouch.prototype.onTouchMove = function (event) {
490
  this.lastPinchMidPoint.copy(pinchMidPoint);
491
  }
492
  };
493
-
 
1
  // orbit-camera.js
2
+ // ========================================
3
 
4
  var OrbitCamera = pc.createScript('orbitCamera');
5
 
 
167
  this.entity.setPosition(position);
168
  };
169
 
170
+ // ---- Modernized SOGS/GSplat AABB support
 
 
 
 
 
 
 
 
 
 
 
171
  OrbitCamera.prototype._buildAabb = function (entity) {
172
+ var meshInstances = [];
173
+ // Standard renders
174
  var renders = entity.findComponents('render');
175
+ for (let render of renders) {
176
+ for (let m of render.meshInstances) meshInstances.push(m);
 
 
 
177
  }
178
+ // Old model components
179
  var models = entity.findComponents('model');
180
+ for (let model of models) {
181
+ for (let m of model.meshInstances) meshInstances.push(m);
 
 
 
182
  }
183
+ // GSplat SOGS support (PlayCanvas 2.8+)
184
  var gsplats = entity.findComponents('gsplat');
185
+ for (let gsplat of gsplats) {
186
+ if (gsplat.instance) {
187
+ if (gsplat.instance.meshInstance) meshInstances.push(gsplat.instance.meshInstance);
188
+ // For SOGS: meshInstances is an array (for multi-SOGS objects)
189
+ if (gsplat.instance.meshInstances) {
190
+ for (let mi of gsplat.instance.meshInstances) meshInstances.push(mi);
191
+ }
192
  }
193
  }
194
+ for (let i = 0; i < meshInstances.length; i++) {
195
  if (i === 0) {
196
  this._modelsAabb.copy(meshInstances[i].aabb);
197
  } else {
 
234
  return Math.atan2(-transformedForward.y, -transformedForward.z) * pc.math.RAD_TO_DEG;
235
  };
236
 
237
+
238
  // ===================== Orbit Camera Input Mouse Script ========================
239
  var OrbitCameraInputMouse = pc.createScript('orbitCameraInputMouse');
240
  OrbitCameraInputMouse.attributes.add('orbitSensitivity', { type: 'number', default: 0.3, title: 'Orbit Sensitivity' });
 
480
  this.lastPinchMidPoint.copy(pinchMidPoint);
481
  }
482
  };