Bläddra i källkod

Merge pull request #9531 from bghgary/sandbox-autorotate

Add option for auto rotate to sandbox
David Catuhe 4 år sedan
förälder
incheckning
6725bdc25c
2 ändrade filer med 11 tillägg och 0 borttagningar
  1. 5 0
      sandbox/src/components/renderingZone.tsx
  2. 6 0
      sandbox/src/sandbox.tsx

+ 5 - 0
sandbox/src/components/renderingZone.tsx

@@ -35,6 +35,7 @@ function isTextureAsset(name: string): boolean {
 interface IRenderingZoneProps {
     globalState: GlobalState;
     assetUrl?: string;
+    autoRotate?: boolean;
     cameraPosition?: Vector3;
     expanded: boolean;
 }
@@ -170,6 +171,10 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
                 framingBehavior.zoomOnBoundingInfo(worldExtends.min, worldExtends.max);
             }
 
+            if (this.props.autoRotate) {
+                camera.useAutoRotationBehavior = true;
+            }
+
             if (this.props.cameraPosition) {
                 camera.setPosition(this.props.cameraPosition);
             }

+ 6 - 0
sandbox/src/sandbox.tsx

@@ -15,6 +15,7 @@ interface ISandboxProps {
 export class Sandbox extends React.Component<ISandboxProps, { isFooterVisible: boolean, errorMessage: string }> {
     private _globalState: GlobalState;
     private _assetUrl?: string;
+    private _autoRotate?: boolean;
     private _cameraPosition?: Vector3;
     private _logoRef: React.RefObject<HTMLImageElement>;
     private _dropTextRef: React.RefObject<HTMLDivElement>;
@@ -90,6 +91,10 @@ export class Sandbox extends React.Component<ISandboxProps, { isFooterVisible: b
                         this._assetUrl = value;
                         break;
                     }
+                    case "autoRotate": {
+                        this._autoRotate = !!value;
+                        break;
+                    }
                     case "cameraPosition": {
                         this._cameraPosition = Vector3.FromArray(value.split(",").map(function (component) { return +component; }));
                         break;
@@ -115,6 +120,7 @@ export class Sandbox extends React.Component<ISandboxProps, { isFooterVisible: b
                 <p id="droptext" ref={this._dropTextRef}>Drag and drop gltf, glb, obj or babylon files to view them</p>
                 <RenderingZone globalState={this._globalState}
                     assetUrl={this._assetUrl}
+                    autoRotate={this._autoRotate}
                     cameraPosition={this._cameraPosition}
                     expanded={!this.state.isFooterVisible} />
                 <div ref={this._clickInterceptorRef}