// Ready function, called once at the beginning of the scene when all children are ready
    public override void _Ready()
    {
        // Assign required nodes
        objectBody      = GetNode <StaticBody>("ViewportContainer/Viewport/ObjectRoot/Object1");
        ray             = GetNode <RayCast>("ViewportContainer/Viewport/ObjectRoot/HiddenLineRay");
        freeCameraRoot  = GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/CameraRoot");
        orthoCameraRoot = GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/OrthoCameraRoot");

        // Populate the list of planes with the nodes of each BoxPlaneControl object
        planes = new Spatial[PLANE_COUNT] {
            GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/FrontPlaneControl"), GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/RightPlaneControl"), GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/BackPlaneControl"), GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/LeftPlaneControl"), GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/TopPlaneControl"), GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/BottomPlaneControl")
        };

        // All faces are hidden at first
        isFaceShown = new bool[PLANE_COUNT] {
            false, false, false, false, false, false
        };

        // Initialize the required static variables in the PlaneControl class
        PlaneControl.Initialize(objectBody.GetChild <MeshInstance>(0), ray, PlaneControl.ORTHOGRAPHIC);

        // Set the display size
        PlaneControl.SetScreenSize(PLANE_X_SCALE, PLANE_Y_SCALE, MAX_FOCUS);

        // Set the zoom of the PlaneControl class
        // A zoom value of 1 is set because this scene requires orthographic projection (without scaling to screen size)
        PlaneControl.SetZoom(MAX_FOCUS);

        // Set the projection colours
        ProjectionRoot.SetColours(true, false);
    }
コード例 #2
0
    // Function to change (refresh) display when any of the controls have been changed
    // Controls are connected to this function through the editor
    // Note that the newValue parameter (given by slider signals) is not used
    public static void ChangeDisplay(float newValue = 0)
    {
        // Rotate the object according to sliders
        objectBody.RotationDegrees = new Vector3((float)ObjectXDegSlider.Value, (float)ObjectYDegSlider.Value, (float)ObjectZDegSlider.Value);

        // Force the body to transform (so calculations can be done) rather than waiting for the next frame
        objectBody.ForceUpdateTransform();

        // Set the zoom value
        PlaneControl.SetZoom((float)FocusZoomSlider.Value);

        // Display 2D screens
        Display();
    }
コード例 #3
0
    // Ready function, called once at the beginning of the scene when all children are ready
    public override void _Ready()
    {
        // Assignment of required nodes
        // ObjectRoot (root of all 3D nodes)
        objectRoot = GetNode <Spatial>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot");

        // PlaneControl Objects
        topViewPlane       = GetNode <Spatial>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot/TopViewPlane");
        frontViewPlane     = GetNode <Spatial>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot/FrontViewPlane");
        sideViewPlane      = GetNode <Spatial>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot/RightViewPlane");
        auxiliaryViewPlane = GetNode <Spatial>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot/AuxiliaryViewPlane");

        // ProjectionRoot Objects
        mainDisplayRoot   = GetNode <Node2D>("HorizontalViewContainer/MainProjectionDisplayContainer/MainProjectionViewport/ProjectionRoot");
        topViewRoot       = GetNode <Node2D>("HorizontalViewContainer/MainProjectionDisplayContainer/ViewGridContainer/TopViewportContainer/TopViewport/TopViewRoot");
        frontViewRoot     = GetNode <Node2D>("HorizontalViewContainer/MainProjectionDisplayContainer/ViewGridContainer/FrontViewportContainer/FrontViewport/FrontViewRoot");
        sideViewRoot      = GetNode <Node2D>("HorizontalViewContainer/MainProjectionDisplayContainer/ViewGridContainer/SideViewportContainer/SideViewport/SideViewRoot");
        auxiliaryViewRoot = GetNode <Node2D>("HorizontalViewContainer/MainProjectionDisplayContainer/ViewGridContainer/AuxiliaryViewportContainer/AuxiliaryViewport/AuxiliaryViewRoot");

        // UI Control Nodes
        ControlsNode     = GetNode <Control>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls");
        FocusZoomSlider  = GetNode <HSlider>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls/ControlsPanel/ViewControl/FocusZoomSlider");
        ObjectXDegSlider = GetNode <HSlider>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls/ControlsPanel/ObjectControl/HBoxContainer/SlidersVBoxContainer/ObjectXDegSlider");
        ObjectYDegSlider = GetNode <HSlider>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls/ControlsPanel/ObjectControl/HBoxContainer/SlidersVBoxContainer/ObjectYDegSlider");
        ObjectZDegSlider = GetNode <HSlider>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls/ControlsPanel/ObjectControl/HBoxContainer/SlidersVBoxContainer/ObjectZDegSlider");
        viewList         = GetNode <OptionButton>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls/ControlsPanel/ViewControl/ViewSelectList");
        viewGrid         = GetNode <GridContainer>("HorizontalViewContainer/MainProjectionDisplayContainer/ViewGridContainer");

        // RayCast Node
        ray = GetNode <RayCast>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot/HiddenLineRayCast");

        // Populate the objects array with the required NodePaths
        for (int index = 0; index < OBJECT_COUNT; index++)
        {
            objects[index] = objectRoot.GetChild <StaticBody>(index + FIRST_OBJECT_INDEX).GetPath();
        }

        // The second object is initially selected
        currentObjectIndex = 1;

        // Get the object's static body from the selected NodePath in the objects array
        objectBody = GetNode <StaticBody>(objects[currentObjectIndex]);

        // Initialize the required static variables in the PlaneControl class
        PlaneControl.Initialize(objectBody.GetChild <MeshInstance>(0), ray, PlaneControl.ORTHOGRAPHIC);

        // Set the screen size so that the projection is properly scaled
        PlaneControl.SetScreenSize(LARGE_PLANE_X_SCALE, LARGE_PLANE_Y_SCALE, MAX_FOCUS);

        // Set the zoom value of the PlaneControl class according to the focus/zoom slider's value
        PlaneControl.SetZoom((float)FocusZoomSlider.Value);

        // Set the colours that the projection is to be displayed in, by specifying whether the projection is on the cube, and whether the colours have been switched
        ProjectionRoot.SetColours(false, false);

        // Auxiliary view is disabled at first
        isAuxEnabled = false;

        // Set the display nodes and display onto the screen
        SetDisplay();
        Display();
    }