// Use this for initialization
    public override void Awake()
    {
        // if we need to auto-configure Rift vs Vive vs (?) VR, we need
        // to do this before any other F3 setup, because MainCamera will change
        // and we are caching that in a lot of places...
        if (AutoConfigVR)
        {
            VRCameraRig = gs.VRPlatform.AutoConfigureVR();
        }

        // restore any settings
        SceneGraphConfig.RestorePreferences();

        // set up some defaults
        // this will move the ground plane down, but the bunnies will be floating...
        //SceneGraphConfig.InitialSceneTranslate = -4.0f * Vector3f.AxisY;
        SceneGraphConfig.DefaultSceneCurveVisualDegrees = 0.5f;
        SceneGraphConfig.DefaultPivotVisualDegrees      = 1.5f;
        SceneGraphConfig.DefaultAxisGizmoVisualDegrees  = 10.0f;


        SceneOptions options = new SceneOptions();

        options.UseSystemMouseCursor = false;
        options.Use2DCockpit         = false;
        options.EnableTransforms     = true;
        options.EnableCockpit        = true;
        options.CockpitInitializer   = new SetupBasicVRCockpit();

        options.MouseCameraControls = new MayaCameraHotkeys();
        options.SpatialCameraRig    = VRCameraRig;

        // very verbose
        options.LogLevel = 2;

        context = new FContext();
        context.Start(options);

        // if you had other gizmos, you would register them here
        //context.TransformManager.RegisterGizmoType("snap_drag", new SnapDragGizmoBuilder());
        //controller.TransformManager.SetActiveGizmoType("snap_drag");

        // if you had other tools, you would register them here.
        context.ToolManager.RegisterToolType(DrawPrimitivesTool.Identifier, new DrawPrimitivesToolBuilder());
        context.ToolManager.RegisterToolType(DrawSurfaceCurveTool.Identifier, new DrawSurfaceCurveToolBuilder()
        {
            AttachCurveToSurface = false,
            DefaultSamplingRateS = 0.0025f, DefaultSurfaceOffsetS = 0.0025f,
            CurveMaterialF       = () => { var mat = context.Scene.DefaultCurveSOMaterial.Clone(); mat.RGBColor = Colorf.VideoRed; return(mat); }
        });
        context.ToolManager.RegisterToolType(DrawSpaceCurveTool.Identifier, new DrawSpaceCurveToolBuilder()
        {
            AttachCurveToTarget  = false,
            DefaultSamplingRateS = 0.01f,
            CurveMaterialF       = () => { var mat = context.Scene.DefaultCurveSOMaterial.Clone(); mat.RGBColor = Colorf.VideoBlue; return(mat); }
        });
        context.ToolManager.SetActiveToolType(DrawPrimitivesTool.Identifier, ToolSide.Right);

        // Set up standard scene lighting if requested
        if (options.EnableDefaultLighting)
        {
            GameObject lighting = GameObject.Find("SceneLighting");
            if (lighting == null)
            {
                lighting = new GameObject("SceneLighting");
            }
            SceneLightingSetup setup = lighting.AddComponent <SceneLightingSetup>();
            setup.Context       = context;
            setup.LightDistance = 30.0f; // related to total scene scale...
        }



        /*
         * Import elements of Unity scene that already exist into the FScene
         */

        // set up ground plane geometry (optional)
        GameObject groundPlane = GameObject.Find("GroundPlane");

        context.Scene.AddWorldBoundsObject(groundPlane);

        SceneObject focusSO = null;

        // wrap existing complex GameObject named capsule1 as a SceneObject
        GameObject capsuleGO = GameObject.Find("capsule1");

        if (capsuleGO != null)
        {
            SceneObject capsuleSO = UnitySceneUtil.WrapAnyGameObject(capsuleGO, context, true);
            focusSO = capsuleSO;
        }

        // wrap a prefab as a GOWrapperSO
        GameObject prefabGO = GameObject.Find("bunny_prefab");

        if (prefabGO != null)
        {
            UnitySceneUtil.WrapAnyGameObject(prefabGO, context, false);
        }

        // convert a mesh GameObject to our DMeshSO
        // Note: any child GameObjects will be lost
        GameObject meshGO = GameObject.Find("bunny_mesh");

        if (meshGO != null)
        {
            //DMeshSO meshSO = UnitySceneUtil.WrapMeshGameObject(meshGO, context, true) as DMeshSO;
            UnitySceneUtil.WrapMeshGameObject(meshGO, context, true);
        }

        GameObject meshGO2 = GameObject.Find("bunny_mesh2");

        if (meshGO2 != null)
        {
            //DMeshSO meshSO = UnitySceneUtil.WrapMeshGameObject(meshGO, context, true) as DMeshSO;
            UnitySceneUtil.WrapMeshGameObject(meshGO2, context, true);
        }

        // center the camera on the capsule assembly
        if (focusSO != null)
        {
            Vector3f centerPt = focusSO.GetLocalFrame(CoordSpace.WorldCoords).Origin;
            context.ActiveCamera.Animator().AnimatePanFocus(centerPt, CoordSpace.WorldCoords, 0.3f);
        }
    }
    // Use this for initialization
    public override void Awake()
    {
        base.Awake();

        // if we need to auto-configure Rift vs Vive vs (?) VR, we need
        // to do this before any other F3 setup, because MainCamera will change
        // and we are caching that in a lot of places...
        if (AutoConfigVR)
        {
            VRCameraRig = gs.VRPlatform.AutoConfigureVR();
        }

        // add splash screen
        CCActions.ShowSplashScreen();

        // restore any settings
        SceneGraphConfig.RestorePreferences();
        CCPreferences.RestorePreferences();
        if (CCPreferences.CameraMode == CCPreferences.CameraModes.Orthographic)
        {
            Camera.main.orthographic = true;
        }

        // set up some defaults
        // this will move the ground plane down, but the bunnies will be floating...
        //SceneGraphConfig.InitialSceneTranslate = -4.0f * Vector3f.AxisY;
        SceneGraphConfig.InitialSceneTranslate          = Vector3f.Zero;
        SceneGraphConfig.DefaultSceneCurveVisualDegrees = 0.5f;
        SceneGraphConfig.DefaultPivotVisualDegrees      = 0.5f;
        SceneGraphConfig.DefaultAxisGizmoVisualDegrees  = 7.5f;
        SceneGraphConfig.CameraPivotVisualDegrees       = 0.3f;

        if (FPlatform.InUnityEditor())
        {
            Util.DebugBreakOnDevAssert = false;     // throw exception on gDevAssert
        }
        SceneOptions options = new SceneOptions();

        options.UseSystemMouseCursor  = true;
        options.Use2DCockpit          = true;
        options.ConstantSize2DCockpit = true;
        options.EnableTransforms      = true;
        options.EnableCockpit         = true;
        options.CockpitInitializer    = new SetupPrintCockpit();

        options.EnableDefaultLighting = true;

        options.MouseCameraControls = new MayaExtCameraHotkeys()
        {
            MouseOrbitSpeed = 5.0f, MousePanSpeed = 0.01f, MouseZoomSpeed = 0.1f, UseAdaptive = true
        };
        options.SpatialCameraRig = VRCameraRig;

        options.DefaultGizmoBuilder = new AxisTransformGizmoBuilder()
        {
            ScaleSpeed = 0.03f, TranslateSpeed = 1.0f
        };

        // very verbose
        options.LogLevel = 4;

        CCMaterials.InitializeMaterials();

        context = new FContext();
        CotangentUI.Initialize(context);   // have to do this before cockpit is configured, which currently
                                           // happens automatically on .Start() (which is dumb...)
        context.Start(options);

        CCMaterials.SetupSceneMaterials(context);

        // if you had other gizmos, you would register them here
        //context.TransformManager.RegisterGizmoType("snap_drag", new SnapDragGizmoBuilder());
        //controller.TransformManager.SetActiveGizmoType("snap_drag");
        //context.TransformManager.RegisterGizmoType(CotangentTypes.SlicePlaneHeightGizmoType, new SlicePlaneHeightGizmoBuilder() {
        //    Factory = new SlicePlaneHeightGizmoBuilder.WidgetFactory(), GizmoVisualDegrees = 4.0f, GizmoLayer = FPlatform.GeometryLayer
        //});
        //context.TransformManager.AddTypeFilter(SlicePlaneHeightGizmoBuilder.MakeTypeFilter());

        // if you had other tools, you would register them here.
        context.ToolManager.RegisterToolType(DrawPrimitivesTool.Identifier, new DrawPrimitivesToolBuilder());
        context.ToolManager.RegisterToolType(SetZLayerTool.Identifier, new SetZLayerToolBuilder());
        CCActions.InitializeCotangentScene(context);
        CCActions.InitializePrintTools(context);
        CCActions.InitializeRepairTools(context);
        CCActions.InitializeModelTools(context);
        context.ToolManager.SetActiveToolType(DrawPrimitivesTool.Identifier, ToolSide.Right);

        // Set up standard scene lighting if requested
        if (options.EnableDefaultLighting)
        {
            GameObject lighting = GameObject.Find("SceneLighting");
            if (lighting == null)
            {
                lighting = new GameObject("SceneLighting");
            }
            SceneLightingSetup setup = lighting.AddComponent <SceneLightingSetup>();
            setup.Context          = context;
            setup.LightDistance    = 200; // related to total scene scale...
            setup.LightCount       = 4;
            setup.ShadowLightCount = 1;
        }


        //GameObjectFactory.CurveRendererSource = new VectrosityCurveRendererFactory();


        // set up selection material
        context.Scene.SelectedMaterial = CCMaterials.SelectedMaterial;


        /*
         * Import elements of Unity scene that already exist into the FScene
         */

        // set up ground plane geometry (optional)
        GameObject boundsObject = GameObject.Find("PrintBed");

        if (boundsObject != null)
        {
            context.Scene.AddWorldBoundsObject(boundsObject);
            CC.PrinterBed = boundsObject;
        }

        CC.Initialize(context);


        if (StartupPart != null)
        {
            StartupPart.name = "Cylinder";
            DMeshSO startupSO = (DMeshSO)UnitySceneUtil.ImportExistingUnityGO(StartupPart, context.Scene, true, true, false,
                                                                              (mesh, material) => {
                PrintMeshSO so = new PrintMeshSO();
                return(so.Create(mesh, CCMaterials.PrintMeshMaterial));
            }
                                                                              );
            GameObject.Destroy(StartupPart);

            CC.Objects.AddPrintMesh(startupSO as PrintMeshSO);
            CCActions.StartupObjectUUID = CC.Objects.PrintMeshes[0].UUID;
        }


        //if (StartupPrintHead != null) {
        //    SceneObject wrapSO = UnitySceneUtil.WrapAnyGameObject(StartupPrintHead, context, false);
        //    CC.PrintHeadSO = wrapSO;
        //    SceneUtil.SetVisible(wrapSO, false);
        //}

        Context.ActiveCamera.Manipulator().SceneOrbit(Context.Scene, context.ActiveCamera, -25, -25);

        CCActions.SwitchToViewMode(CCPreferences.StartupWorkspace, true);

        // enable drag-drop on windows when not in editor
        StartAnonymousCoroutine(enable_drag_drop());

        // import command-line args
        CCActions.DoArgumentsImport(Environment.GetCommandLineArgs());

        // start auto-update check
        if (FPlatform.InUnityEditor() == false)
        {
            StartAnonymousCoroutine(auto_update_check());
        }

        // set window title
        FPlatform.SetWindowTitle(string.Format("cotangent {0}", CotangentVersion.CurrentVersionString));

        // show privacy dialog soon
        Context.RegisterNthFrameAction(100, CCActions.ShowPrivacyDialogIfRequired);
    }
    // Use this for initialization
    public override void Awake()
    {
        VRPlatform.VREnabled = false;

        // restore any settings
        SceneGraphConfig.RestorePreferences();

        // set up some defaults
        SceneGraphConfig.DefaultSceneCurveVisualDegrees = 0.5f;
        SceneGraphConfig.DefaultPivotVisualDegrees      = 1.5f;
        SceneGraphConfig.DefaultAxisGizmoVisualDegrees  = 10.0f;


        SceneOptions options = new SceneOptions();

        options.UseSystemMouseCursor  = true;
        options.EnableCockpit         = true;
        options.Use2DCockpit          = true;
        options.ConstantSize2DCockpit = true;    // you usually want this
        options.EnableTransforms      = true;
        options.CockpitInitializer    = new SetupObjectsDemoCockpit();

        options.MouseCameraControls = new MayaCameraHotkeys();

        // very verbose
        options.LogLevel = 2;

        context = new FContext();
        context.Start(options);

        // register transformation gizmos
        //context.TransformManager.RegisterGizmoType(AxisTransformGizmo.DefaultName, new AxisTransformGizmoBuilder());
        //context.TransformManager.SetActiveGizmoType(AxisTransformGizmo.DefaultName);

        // if you had other tools, you would register them here.
        context.ToolManager.RegisterToolType(DrawPrimitivesTool.Identifier, new DrawPrimitivesToolBuilder());
        context.ToolManager.SetActiveToolType(DrawPrimitivesTool.Identifier, ToolSide.Right);

        // Set up standard scene lighting if requested
        if (options.EnableDefaultLighting)
        {
            GameObject lighting = GameObject.Find("SceneLighting");
            if (lighting == null)
            {
                lighting = new GameObject("SceneLighting");
            }
            SceneLightingSetup setup = lighting.AddComponent <SceneLightingSetup>();
            setup.Context       = context;
            setup.LightDistance = 30.0f; // related to total scene scale...
        }



        /*
         * Import elements of Unity scene that already exist into the FScene
         */

        // set up ground plane geometry (optional)
        GameObject groundPlane = GameObject.Find("GroundPlane");

        context.Scene.AddWorldBoundsObject(groundPlane);


        Sphere3Generator_NormalizedCube gen = new Sphere3Generator_NormalizedCube()
        {
            Radius = 1.0f
        };
        DMeshSO meshSO = new DMeshSO();

        meshSO.Create(gen.Generate().MakeDMesh(), Context.Scene.DefaultMeshSOMaterial);
        Context.Scene.AddSceneObject(meshSO);

        //SceneObject focusSO = null;

        // convert a mesh GameObject to our DMeshSO
        // Note: any child GameObjects will be lost
        GameObject meshGO = GameObject.Find("bunny_mesh");

        if (meshGO != null)
        {
            //DMeshSO meshSO = UnitySceneUtil.WrapMeshGameObject(meshGO, context, true) as DMeshSO;
            UnitySceneUtil.WrapMeshGameObject(meshGO, context, true);
        }

        GameObject meshGO2 = GameObject.Find("bunny_mesh2");

        if (meshGO2 != null)
        {
            //DMeshSO meshSO = UnitySceneUtil.WrapMeshGameObject(meshGO, context, true) as DMeshSO;
            UnitySceneUtil.WrapMeshGameObject(meshGO2, context, true);
        }

        //// center the camera on the capsule assembly
        //if (focusSO != null) {
        //    Vector3f centerPt = focusSO.GetLocalFrame(CoordSpace.WorldCoords).Origin;
        //    context.ActiveCamera.Manipulator().ScenePanFocus(
        //        context.Scene, context.ActiveCamera, centerPt, true);
        //}
    }