예제 #1
0
    def __init__(self, pos=Vector3(0,0,0), radius=150.0, density=16): #6.328
        Node.__init__(self)
        
        self._name = "planet_root"

        self.transform.position = pos

        # The mesh density
        self._density = density
        
        # The camera position in sphere-space coordinates
        self._camera_pos = pos
        self._camera_pos_sc = None
        self._radius = radius
        self._horizon = 0.0
        
        self._max_depth = 8
        
        #self._camera_gizmo = WireSphere(radius=0.1)
        #self.transform.add_child(self._camera_gizmo.transform)
        
        self._camera_gizmo = GizmoManager.draw_sphere(Vector3(), radius=0.2)
        
        # The maximum height of the sphere surface (above the radius)
        self._max_height = (radius * 0.05) #0.02
        self._split_factor = 1.1  #16
        self._split_power = 1.1 #1.25
        
        self._horizon = 0
        
        self._ui = PlanetSphereDebugWindow()
        
        # Number splits this frame
        self._num_splits = 0
        # Max number of splits per frame
        self._max_splits = 8
        
#        pos = self.transform.position
#        pos.y += 0.1
#        self.transform.position.y = 1.0
#        self._line = Line(Vector3(0,1,0), Vector3(0, 0, 0), 5.0)
#        self.transform.add_child(self._line.transform)

        self._line = GizmoManager.draw_line(Vector3(-1,0,0), Vector3(0,0,0), 5.0)
        
#        self._cube_pos = Line(self.transform.position, Vector3(0, 0, 0), 5.0)
#        self.transform.add_child(self._cube_pos.transform)
        
        self._camera = None
        self._last_camera_pos = None
        self._last_time = datetime.now()
        
        self._generator = SphereSurface(self._density, self._radius, self._max_height)

        # Create the faces of the planet
        self._gen_faces()
예제 #2
0
    def _vis_frustum(self, show):

        if show:
            if self._gizmos is None:
                # Create gizmos
                # Frustum Plane Gizmos
                self._gizmos = []

                self._topg = GizmoManager.draw_plane(Vector3(), size=15.0, colour=Preset.blue)
                self._bottomg = GizmoManager.draw_plane(Vector3(), size=15.0, colour=Preset.red)
                self._leftg = GizmoManager.draw_plane(Vector3(), size=15.0, colour=Preset.orange)
                self._rightg = GizmoManager.draw_plane(Vector3(), size=15.0, colour=Preset.purple)

                self._gizmos.append(self._topg)
                self._gizmos.append(self._bottomg)
                self._gizmos.append(self._rightg)
                self._gizmos.append(self._leftg)

                # Lines
                self._tl = GizmoManager.draw_line(Vector3(), colour=Preset.red)
                self._tr = GizmoManager.draw_line(Vector3(), colour=Preset.red)
                self._bl = GizmoManager.draw_line(Vector3(), colour=Preset.red)
                self._br = GizmoManager.draw_line(Vector3(), colour=Preset.red)

                self._gizmos.append(self._tl)
                self._gizmos.append(self._tr)
                self._gizmos.append(self._bl)
                self._gizmos.append(self._br)
                
                self._oforward = GizmoManager.draw_line(Vector3(), colour=Preset.blue)
                self._oup = GizmoManager.draw_line(Vector3(), colour=Preset.green)
                self._oright = GizmoManager.draw_line(Vector3(), colour=Preset.red)
                self._gizmos.append(self._oforward)
                self._gizmos.append(self._oup)
                self._gizmos.append(self._oright)

                #self._cam_pos = GizmoManager.draw_cube(Vector3(), 1.0, 1.0, 1.0)
            
                self._tl.transform.position = self._verts[self.NTL]
                self._tl.line_to(self._verts[self.FTL])
                
                self._tr.transform.position = self._verts[self.NTR]
                self._tr.line_to(self._verts[self.FTR])
                
                self._bl.transform.position = self._verts[self.NBL]
                self._bl.line_to(self._verts[self.FBL])
                
                self._br.transform.position = self._verts[self.NBR]
                self._br.line_to(self._verts[self.FBR])

                # Transform orientation
                self._oforward.transform.position = self._transform.position.copy()
                self._oforward.direction = self._transform.forward
                self._oforward.length = 3.0
                
                self._oup.transform.position = self._transform.position.copy()
                self._oup.direction = self._transform.up
                self._oup.length = 3.0
                
                self._oright.transform.position = self._transform.position.copy()
                self._oright.direction = self._transform.right
                self._oright.length = 3.0

                # Frustum plane visualisation
                self._topg.transform.position = self._transform.position
                self._topg.normal = self._top.n

                self._bottomg.transform.position = self._transform.position
                self._bottomg.normal = self._bottom.n

                self._leftg.transform.position = self._transform.position
                self._leftg.normal = self._left.n

                self._rightg.transform.position = self._transform.position
                self._rightg.normal = self._right.n
        else:
            if not self._gizmos is None:
                for giz in self._gizmos:
                    GizmoManager.remove_gizmo(giz)
                self._gizmos = None