Beispiel #1
0
    def drawSelf(self):
        point = self.sceneNode.point
        if point is None:
            return

        r, g, b, a = self.sceneNode.color
        box = BoundingBox(point, (1, 1, 1))

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT | GL.GL_POLYGON_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glPolygonOffset(DepthOffsets.SelectionCursor, DepthOffsets.SelectionCursor)

            # Highlighted face

            GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)

            GL.glColor(r, g, b, a)
            cubes.drawFace(box, self.sceneNode.face)

            # Wire box
            GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)

            GL.glLineWidth(3.0)
            GL.glColor(1., 1., 1., a)

            cubes.drawBox(box)

            GL.glLineWidth(1.0)
            GL.glColor(0.2, 0.2, 0.2, a)

            cubes.drawBox(box)
Beispiel #2
0
    def drawSelf(self):
        box = self.sceneNode.selectionBox
        if box is None:
            return

        r, g, b, alpha = self.sceneNode.color
        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT | GL.GL_POLYGON_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glPolygonOffset(self.sceneNode.depth, self.sceneNode.depth)

            if self.sceneNode.filled:
                # Filled box
                GL.glColor(r, g, b, alpha)
                cubes.drawBox(box)

            if self.sceneNode.wire:
                # Wire box, thinner behind terrain
                r, g, b, alpha = self.sceneNode.wireColor
                GL.glColor(r, g, b, alpha)
                GL.glLineWidth(2.0)
                cubes.drawBox(box, cubeType=GL.GL_LINES)
                GL.glDisable(GL.GL_DEPTH_TEST)
                GL.glLineWidth(1.0)
                cubes.drawBox(box, cubeType=GL.GL_LINES)
Beispiel #3
0
    def drawSelf(self):
        box = self.sceneNode.selectionBox
        if box is None:
            return

        r, g, b, alpha = self.sceneNode.color
        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT
                             | GL.GL_POLYGON_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glEnable(GL.GL_POLYGON_OFFSET_LINE)
            GL.glPolygonOffset(self.sceneNode.depth, self.sceneNode.depth)

            GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)

            if self.sceneNode.filled:
                # Filled box
                GL.glColor(r, g, b, alpha)
                cubes.drawBox(box)

            if self.sceneNode.wire:
                # Wire box, in front of terrain
                r, g, b, alpha = self.sceneNode.wireColor
                GL.glColor(r, g, b, alpha)
                GL.glLineWidth(3.0)
                cubes.drawBox(box)
                # Wire box, behind terrain, thinner
                GL.glDisable(GL.GL_DEPTH_TEST)
                GL.glColor(r, g, b, alpha * 0.5)
                GL.glLineWidth(1.0)
                cubes.drawBox(box)
Beispiel #4
0
    def drawSelf(self):
        with gl.glPushMatrix(GL.GL_MODELVIEW):
            GL.glLoadIdentity()
            with gl.glPushMatrix(GL.GL_PROJECTION):
                GL.glLoadIdentity()
                with gl.glPushClientAttrib(GL.GL_CLIENT_VERTEX_ARRAY_BIT):
                    GL.glClear(GL.GL_COLOR_BUFFER_BIT)
                    GL.glEnableClientState(GL.GL_COLOR_ARRAY)
                    quad = numpy.array([-1, -1, -1, 1, 1, 1, 1, -1],
                                       dtype='float32')
                    colors = numpy.array([
                        0x48,
                        0x49,
                        0xBA,
                        0xff,
                        0x8a,
                        0xaf,
                        0xff,
                        0xff,
                        0x8a,
                        0xaf,
                        0xff,
                        0xff,
                        0x48,
                        0x49,
                        0xBA,
                        0xff,
                    ],
                                         dtype='uint8')

                    with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT):
                        GL.glDepthMask(False)
                        GL.glVertexPointer(2, GL.GL_FLOAT, 0, quad)
                        GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, 0, colors)
                        GL.glDrawArrays(GL.GL_QUADS, 0, 4)
Beispiel #5
0
    def drawSelf(self):
        self.didDraw = True
        bare = []
        withTex = []
        withLights = []
        for array in self.sceneNode.vertexArrays:
            if array.lights:
                withLights.append(array)
            elif array.textures:
                withTex.append(array)
            else:
                bare.append(array)

        with gl.glPushAttrib(GL.GL_ENABLE_BIT):
            if len(bare):
                glutils.glActiveTexture(GL.GL_TEXTURE0)
                GL.glDisable(GL.GL_TEXTURE_2D)
                glutils.glActiveTexture(GL.GL_TEXTURE1)
                GL.glDisable(GL.GL_TEXTURE_2D)
                glutils.glActiveTexture(GL.GL_TEXTURE0)
                self.drawArrays(bare, False, False)

            if len(withTex) or len(withLights):
                glutils.glActiveTexture(GL.GL_TEXTURE0)
                GL.glEnable(GL.GL_TEXTURE_2D)

            if len(withTex):
                self.drawArrays(withTex, True, False)

            if len(withLights):
                glutils.glActiveTexture(GL.GL_TEXTURE1)
                GL.glEnable(GL.GL_TEXTURE_2D)
                glutils.glActiveTexture(GL.GL_TEXTURE0)
                self.drawArrays(withLights, True, True)
Beispiel #6
0
    def drawSelf(self):
        point = self.sceneNode.point
        if point is None:
            return

        r, g, b, a = self.sceneNode.color
        box = BoundingBox(point, (1, 1, 1))

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT
                             | GL.GL_POLYGON_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glPolygonOffset(DepthOffsets.SelectionCursor,
                               DepthOffsets.SelectionCursor)

            # Highlighted face

            GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)

            GL.glColor(r, g, b, a)
            cubes.drawFace(box, self.sceneNode.face)

            # Wire box
            GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)

            GL.glLineWidth(3.0)
            GL.glColor(1., 1., 1., a)

            cubes.drawBox(box)

            GL.glLineWidth(1.0)
            GL.glColor(0.2, 0.2, 0.2, a)

            cubes.drawBox(box)
Beispiel #7
0
    def drawSelf(self):
        box = self.sceneNode.selectionBox
        if box is None:
            return

        r, g, b, alpha = self.sceneNode.color
        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT | GL.GL_POLYGON_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glPolygonOffset(self.sceneNode.depth, self.sceneNode.depth)

            if self.sceneNode.filled:
                # Filled box
                GL.glColor(r, g, b, alpha)
                cubes.drawBox(box)

            if self.sceneNode.wire:
                # Wire box, thinner behind terrain
                r, g, b, alpha = self.sceneNode.wireColor
                GL.glColor(r, g, b, alpha)
                GL.glLineWidth(2.0)
                cubes.drawBox(box, cubeType=GL.GL_LINES)
                GL.glDisable(GL.GL_DEPTH_TEST)
                GL.glLineWidth(1.0)
                cubes.drawBox(box, cubeType=GL.GL_LINES)
Beispiel #8
0
def drawConstructionCube(box, color, texture=None):
    #if texture == None:
    #    texture = self.sixteenBlockTex
    with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT):
        GL.glEnable(GL.GL_BLEND)
        GL.glEnable(GL.GL_DEPTH_TEST)
        GL.glDepthMask(False)

        # edges within terrain
        GL.glDepthFunc(GL.GL_GREATER)
        GL.glColor(color[0], color[1], color[2], max(color[3], 0.35))
        GL.glLineWidth(1.0)
        drawBox(box, cubeType=GL.GL_LINE_STRIP)

        # edges on or outside terrain
        GL.glDepthFunc(GL.GL_LEQUAL)
        GL.glColor(color[0], color[1], color[2], max(color[3] * 2, 0.75))
        GL.glLineWidth(2.0)
        drawBox(box, cubeType=GL.GL_LINE_STRIP)

        # faces
        GL.glDepthFunc(GL.GL_LESS)
        GL.glColor(color[0], color[1], color[2], color[3])
        GL.glDepthFunc(GL.GL_LEQUAL)
        drawBox(box, texture=texture, selectionBox=True)
Beispiel #9
0
    def drawSelf(self):
        box = self.sceneNode.selectionBox
        if box is None:
            return

        r, g, b, alpha = self.sceneNode.color
        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT | GL.GL_POLYGON_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glEnable(GL.GL_POLYGON_OFFSET_LINE)
            GL.glPolygonOffset(self.sceneNode.depth, self.sceneNode.depth)

            GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)

            if self.sceneNode.filled:
                # Filled box
                GL.glColor(r, g, b, alpha)
                cubes.drawBox(box)

            if self.sceneNode.wire:
                # Wire box, in front of terrain
                r, g, b, alpha = self.sceneNode.wireColor
                GL.glColor(r, g, b, alpha)
                GL.glLineWidth(3.0)
                cubes.drawBox(box)
                # Wire box, behind terrain, thinner
                GL.glDisable(GL.GL_DEPTH_TEST)
                GL.glColor(r, g, b, alpha * 0.5)
                GL.glLineWidth(1.0)
                cubes.drawBox(box)
Beispiel #10
0
    def drawSelf(self):
        if self.sceneNode.corners is None or self.sceneNode.dimension is None:
            return
        corners = self.sceneNode.corners
        dimension = self.sceneNode.dimension
        corners = corners[:2], corners[2:4], corners[6:8], corners[4:6]

        def rayCastCorner(near, far):
            ray = Ray.fromPoints(near, far)
            if not any(ray.vector):
                return far
            try:
                #point = rayCastInBounds(ray, dimension, 50)[0]
                #return point or far
                return near + (near - far) / 4
            except raycast.MaxDistanceError:
                return ray.atHeight(0)

        # Average nearby height values or something to suppress jitter??
        corners = [rayCastCorner(near, far) for near, far in corners]
        corners.append(corners[0])

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT, GL.GL_COLOR_BUFFER_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glVertexPointer(3, GL.GL_FLOAT, 0, numpy.array(corners).ravel())

            GL.glLineWidth(3.0)

            GL.glColor(1, 1, .1, 0.5)
            GL.glDisable(GL.GL_DEPTH_TEST)
            GL.glDrawArrays(GL.GL_LINE_STRIP, 0, 5)
Beispiel #11
0
def drawConstructionCube(box, color, texture=None):
    #if texture == None:
    #    texture = self.sixteenBlockTex
    with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT):
        GL.glEnable(GL.GL_BLEND)
        GL.glEnable(GL.GL_DEPTH_TEST)
        GL.glDepthMask(False)

        # edges within terrain
        GL.glDepthFunc(GL.GL_GREATER)
        GL.glColor(color[0], color[1], color[2], max(color[3], 0.35))
        GL.glLineWidth(1.0)
        drawBox(box, cubeType=GL.GL_LINE_STRIP)

        # edges on or outside terrain
        GL.glDepthFunc(GL.GL_LEQUAL)
        GL.glColor(color[0], color[1], color[2], max(color[3] * 2, 0.75))
        GL.glLineWidth(2.0)
        drawBox(box, cubeType=GL.GL_LINE_STRIP)

        # faces
        GL.glDepthFunc(GL.GL_LESS)
        GL.glColor(color[0], color[1], color[2], color[3])
        GL.glDepthFunc(GL.GL_LEQUAL)
        drawBox(box, texture=texture, selectionBox=True)
Beispiel #12
0
    def drawSelf(self):
        if self.sceneNode.corners is None or self.sceneNode.dimension is None:
            return
        corners = self.sceneNode.corners
        dimension = self.sceneNode.dimension
        corners = corners[:2], corners[2:4], corners[6:8], corners[4:6]

        def rayCastCorner(near, far):
            ray = Ray.fromPoints(near, far)
            if not any(ray.vector):
                return far
            try:
                #point = rayCastInBounds(ray, dimension, 50)[0]
                #return point or far
                return near + (near - far) / 4
            except raycast.MaxDistanceError:
                return ray.atHeight(0)

        # Average nearby height values or something to suppress jitter??
        corners = [rayCastCorner(near, far) for near, far in corners]
        corners.append(corners[0])

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT, GL.GL_COLOR_BUFFER_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glVertexPointer(3, GL.GL_FLOAT, 0, numpy.array(corners).ravel())

            GL.glLineWidth(3.0)

            GL.glColor(1, 1, .1, 0.5)
            GL.glDisable(GL.GL_DEPTH_TEST)
            GL.glDrawArrays(GL.GL_LINE_STRIP, 0, 5)
Beispiel #13
0
    def drawSelf(self):
        box = self.sceneNode.selectionBox
        if box is None:
            return

        alpha = 0.3
        r, g, b = self.sceneNode.color
        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT):
            GL.glDisable(GL.GL_DEPTH_TEST)
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glPolygonOffset(self.sceneNode.depth, self.sceneNode.depth)

            GL.glColor(r, g, b, alpha)
            cubes.drawFace(box, self.sceneNode.face)
Beispiel #14
0
    def drawSelf(self):
        if self.sceneNode.corners is None or self.sceneNode.dimension is None:
            return
        corners = self.sceneNode.corners

        outwardSegments = [
            LineSegment(corners[i], corners[j]) for i, j in self.outwardIndices
        ]
        verticalSegments = [
            LineSegment(corners[i], corners[j])
            for i, j in self.verticalIndices
        ]
        points = []

        for segment in outwardSegments:
            p = segment.atHeight(self.sceneNode.planeHeight)
            if p is not None:
                points.append(p)

        if len(points) < 4:
            # only intersected two outward segments. check the far verticals.
            for segment in verticalSegments[:2]:
                r = Ray.fromPoints(*segment)
                points.append(r.atHeight(self.sceneNode.planeHeight))

        if len(points) < 4:
            # intersected zero outward segments!
            # rarely occurs, the near verticals are 1/10 of a block tall
            for segment in verticalSegments[2:]:
                r = Ray.fromPoints(*segment)
                points.append(r.atHeight(self.sceneNode.planeHeight))

        if len(points) < 4:
            return

        p1, p2, p3, p4 = points[:4]
        points = [p1, p2, p4, p3, p1]

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT, GL.GL_COLOR_BUFFER_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glVertexPointer(3, GL.GL_FLOAT, 0, numpy.array(points).ravel())

            GL.glLineWidth(3.0)

            GL.glColor(1, 1, .1, 0.5)
            GL.glDisable(GL.GL_DEPTH_TEST)
            GL.glDrawArrays(GL.GL_LINE_STRIP, 0, len(points))
Beispiel #15
0
    def drawSelf(self):
        with gl.glPushMatrix(GL.GL_MODELVIEW):
            GL.glLoadIdentity()
            with gl.glPushMatrix(GL.GL_PROJECTION):
                GL.glLoadIdentity()
                with gl.glPushClientAttrib(GL.GL_CLIENT_VERTEX_ARRAY_BIT):
                    GL.glClear(GL.GL_COLOR_BUFFER_BIT)
                    GL.glEnableClientState(GL.GL_COLOR_ARRAY)
                    quad = numpy.array([-1, -1, -1, 1, 1, 1, 1, -1], dtype='float32')
                    colors = numpy.array([0x48, 0x49, 0xBA, 0xff,
                                          0x8a, 0xaf, 0xff, 0xff,
                                          0x8a, 0xaf, 0xff, 0xff,
                                          0x48, 0x49, 0xBA, 0xff, ], dtype='uint8')

                    with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT):
                        GL.glDepthMask(False)
                        GL.glVertexPointer(2, GL.GL_FLOAT, 0, quad)
                        GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, 0, colors)
                        GL.glDrawArrays(GL.GL_QUADS, 0, 4)
Beispiel #16
0
    def drawSelf(self):
        if self.sceneNode.corners is None or self.sceneNode.dimension is None:
            return
        corners = self.sceneNode.corners

        outwardSegments = [LineSegment(corners[i], corners[j]) for i, j in self.outwardIndices]
        verticalSegments = [LineSegment(corners[i], corners[j]) for i, j in self.verticalIndices]
        points = []

        for segment in outwardSegments:
            p = segment.atHeight(self.sceneNode.planeHeight)
            if p is not None:
                points.append(p)

        if len(points) < 4:
            # only intersected two outward segments. check the far verticals.
            for segment in verticalSegments[:2]:
                r = Ray.fromPoints(*segment)
                points.append(r.atHeight(self.sceneNode.planeHeight))

        if len(points) < 4:
            # intersected zero outward segments!
            # rarely occurs, the near verticals are 1/10 of a block tall
            for segment in verticalSegments[2:]:
                r = Ray.fromPoints(*segment)
                points.append(r.atHeight(self.sceneNode.planeHeight))

        if len(points) < 4:
            return

        p1, p2, p3, p4 = points[:4]
        points = [p1, p2, p4, p3, p1]

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT, GL.GL_COLOR_BUFFER_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glVertexPointer(3, GL.GL_FLOAT, 0, numpy.array(points).ravel())

            GL.glLineWidth(3.0)

            GL.glColor(1, 1, .1, 0.5)
            GL.glDisable(GL.GL_DEPTH_TEST)
            GL.glDrawArrays(GL.GL_LINE_STRIP, 0, len(points))
Beispiel #17
0
    def drawSelf(self):
        box = self.sceneNode.selectionBox
        if box is None:
            return

        alpha = 0.16
        r, g, b = self.sceneNode.color
        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT | GL.GL_LINE_BIT):
            GL.glDisable(GL.GL_DEPTH_TEST)
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glPolygonOffset(self.sceneNode.depth, self.sceneNode.depth)

            GL.glColor(1.0, 1.0, 1.0, 1.0)
            GL.glLineWidth(2.0)
            cubes.drawFace(box, self.sceneNode.face, GL.GL_LINE_STRIP)
            GL.glColor(r, g, b, alpha)
            GL.glEnable(GL.GL_DEPTH_TEST)
            cubes.drawFace(box, self.sceneNode.face)
Beispiel #18
0
    def drawSelf(self):
        self.didDraw = True
        bare = []
        withTex = []
        withLights = []
        for array in self.sceneNode.vertexArrays:
            if array.lights:
                withLights.append(array)
            elif array.textures:
                withTex.append(array)
            else:
                bare.append(array)

        with gl.glPushAttrib(GL.GL_ENABLE_BIT):
            GL.glDisable(GL.GL_TEXTURE_2D)
            self.drawArrays(bare, False, False)
            GL.glEnable(GL.GL_TEXTURE_2D)
            self.drawArrays(withTex, True, False)
            self.drawArrays(withLights, True, True)
Beispiel #19
0
    def drawSelf(self):

        self._tex.bind()

        with gl.glPushMatrix(GL.GL_MODELVIEW):
            GL.glLoadIdentity()
            yaw, pitch = self.sceneNode.yawPitch
            GL.glTranslatef(0.9, 0.1, 0.0)  # position on lower right corner
            GL.glRotatef(pitch, 1., 0., 0.)  # Tilt upward a bit if the view is pitched
            GL.glRotatef(yaw - 180, 0., 0., 1.)  # adjust to north
            GL.glColor4f(1., 1., 1., 1.)

            with gl.glPushAttrib(GL.GL_ENABLE_BIT):
                GL.glDisable(GL.GL_DEPTH_TEST)
                with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY):
                    GL.glVertexPointer(2, GL.GL_FLOAT, 0, makeQuad(-.1, -.1, 0.2, 0.2))
                    GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, makeQuad(0, 0, 1, 1))

                    with gl.glEnable(GL.GL_BLEND, GL.GL_TEXTURE_2D):
                        GL.glDrawArrays(GL.GL_QUADS, 0, 4)
Beispiel #20
0
    def drawSelf(self):
        with gl.glPushMatrix(GL.GL_MODELVIEW):
            GL.glLoadIdentity()
            with gl.glPushMatrix(GL.GL_PROJECTION):
                GL.glLoadIdentity()
                GL.glClear(GL.GL_COLOR_BUFFER_BIT)
                GL.glEnableClientState(GL.GL_COLOR_ARRAY)
                quad = numpy.array([-1, -1, -1, 1, 1, 1, 1, -1], dtype='float32')
                colors = numpy.array([0x48, 0x49, 0xBA, 0xff,
                                      0x8a, 0xaf, 0xff, 0xff,
                                      0x8a, 0xaf, 0xff, 0xff,
                                      0x48, 0x49, 0xBA, 0xff, ], dtype='uint8')
                numpy.multiply(colors, self.sceneNode.dayTime, out=colors, casting='unsafe')

                with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT):
                    GL.glDepthMask(False)
                    GL.glVertexPointer(2, GL.GL_FLOAT, 0, quad)
                    GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, 0, colors)
                    GL.glDrawArrays(GL.GL_QUADS, 0, 4)
                GL.glDisableClientState(GL.GL_COLOR_ARRAY)
Beispiel #21
0
    def drawSelf(self):
        box = self.sceneNode.selectionBox
        if box is None:
            return

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT
                             | GL.GL_LINE_BIT):
            GL.glDisable(GL.GL_DEPTH_TEST)
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glPolygonOffset(self.sceneNode.depth, self.sceneNode.depth)

            r, g, b, a = self.sceneNode.wireColor
            GL.glColor(r, g, b, a)
            GL.glLineWidth(3.0)
            cubes.drawFace(box, self.sceneNode.face, GL.GL_LINE_STRIP)

            r, g, b, a = self.sceneNode.color
            GL.glColor(r, g, b, a)
            GL.glEnable(GL.GL_DEPTH_TEST)
            cubes.drawFace(box, self.sceneNode.face)
Beispiel #22
0
    def drawSelf(self):
        point = self.sceneNode.point
        if point is None:
            return
        selectionColor = map(lambda a: a * a * a * a, self.sceneNode.color)
        r, g, b = selectionColor
        alpha = 0.3
        box = BoundingBox(point, (1, 1, 1))

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glPolygonOffset(DepthOffset.SelectionCursor, DepthOffset.SelectionCursor)

            # Wire box
            GL.glColor(1., 1., 1., alpha)
            cubes.drawBox(box, cubeType=GL.GL_LINES)

            # Highlighted face
            GL.glColor(r, g, b, alpha)
            cubes.drawFace(box, self.sceneNode.face)
Beispiel #23
0
    def drawSelf(self):
        point = self.sceneNode.point
        if point is None:
            return
        selectionColor = map(lambda a: a * a * a * a, self.sceneNode.color)
        r, g, b = selectionColor
        alpha = 0.3
        box = BoundingBox(point, (1, 1, 1))

        with gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT):
            GL.glDepthMask(False)
            GL.glEnable(GL.GL_BLEND)
            GL.glPolygonOffset(DepthOffset.SelectionCursor, DepthOffset.SelectionCursor)

            # Wire box
            GL.glColor(1., 1., 1., alpha)
            cubes.drawBox(box, cubeType=GL.GL_LINES)

            # Highlighted face
            GL.glColor(r, g, b, alpha)
            cubes.drawFace(box, self.sceneNode.face)
Beispiel #24
0
    def drawSelf(self):
        with gl.glPushAttrib(GL.GL_FOG_BIT | GL.GL_ENABLE_BIT):
            GL.glDisable(GL.GL_FOG)

            GL.glEnable(GL.GL_BLEND)
            GL.glEnable(GL.GL_POLYGON_OFFSET_FILL)
            GL.glPolygonOffset(DepthOffsets.ChunkMarkers, DepthOffsets.ChunkMarkers)
            GL.glEnable(GL.GL_DEPTH_TEST)

            GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY)
            GL.glEnable(GL.GL_TEXTURE_2D)
            GL.glColor(1.0, 1.0, 1.0, 1.0)

            self.floorTexture.bind()

            for vertexArray in self.sceneNode.createVertexArrays():
                GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArray.ravel())
                # chunkPositions *= 8
                GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, (vertexArray[..., (0, 2)] / 32).ravel())
                GL.glDrawArrays(GL.GL_QUADS, 0, len(vertexArray) * 4)
            GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY)
    def drawSelf(self):
        with gl.glPushAttrib(GL.GL_FOG_BIT | GL.GL_ENABLE_BIT):
            GL.glDisable(GL.GL_FOG)

            GL.glEnable(GL.GL_BLEND)
            GL.glEnable(GL.GL_POLYGON_OFFSET_FILL)
            GL.glPolygonOffset(DepthOffset.ChunkMarkers,
                               DepthOffset.ChunkMarkers)
            GL.glEnable(GL.GL_DEPTH_TEST)

            GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY)
            GL.glEnable(GL.GL_TEXTURE_2D)
            GL.glColor(1.0, 1.0, 1.0, 1.0)

            self.floorTexture.bind()

            for vertexArray in self.sceneNode.createVertexArrays():
                GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArray.ravel())
                # chunkPositions *= 8
                GL.glTexCoordPointer(2, GL.GL_FLOAT, 0,
                                     (vertexArray[..., (0, 2)] / 32).ravel())
                GL.glDrawArrays(GL.GL_QUADS, 0, len(vertexArray) * 4)
            GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY)
Beispiel #26
0
    def drawSelf(self):

        self._tex.bind()

        with gl.glPushMatrix(GL.GL_MODELVIEW):
            GL.glLoadIdentity()
            yaw, pitch = self.sceneNode.yawPitch
            GL.glTranslatef(0.9, 0.1, 0.0)  # position on lower right corner
            GL.glRotatef(pitch, 1., 0.,
                         0.)  # Tilt upward a bit if the view is pitched
            GL.glRotatef(yaw - 180, 0., 0., 1.)  # adjust to north
            GL.glColor4f(1., 1., 1., 1.)

            with gl.glPushAttrib(GL.GL_ENABLE_BIT):
                GL.glDisable(GL.GL_DEPTH_TEST)
                with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY):
                    GL.glVertexPointer(2, GL.GL_FLOAT, 0,
                                       makeQuad(-.1, -.1, 0.2, 0.2))
                    GL.glTexCoordPointer(2, GL.GL_FLOAT, 0,
                                         makeQuad(0, 0, 1, 1))

                    with gl.glEnable(GL.GL_BLEND, GL.GL_TEXTURE_2D):
                        GL.glDrawArrays(GL.GL_QUADS, 0, 4)
Beispiel #27
0
def drawFace(box, face, elementType=GL.GL_QUADS):
    x, y, z, = box.origin
    x2, y2, z2 = box.maximum

    if face == faces.FaceXDecreasing:
        faceVertices = numpy.array((
            x,
            y2,
            z2,
            x,
            y2,
            z,
            x,
            y,
            z,
            x,
            y,
            z2,
        ),
                                   dtype='f4')

    elif face == faces.FaceXIncreasing:
        faceVertices = numpy.array((
            x2,
            y,
            z2,
            x2,
            y,
            z,
            x2,
            y2,
            z,
            x2,
            y2,
            z2,
        ),
                                   dtype='f4')

    elif face == faces.FaceYDecreasing:
        faceVertices = numpy.array((
            x2,
            y,
            z2,
            x,
            y,
            z2,
            x,
            y,
            z,
            x2,
            y,
            z,
        ),
                                   dtype='f4')

    elif face == faces.FaceYIncreasing:
        faceVertices = numpy.array((
            x2,
            y2,
            z,
            x,
            y2,
            z,
            x,
            y2,
            z2,
            x2,
            y2,
            z2,
        ),
                                   dtype='f4')

    elif face == faces.FaceZDecreasing:
        faceVertices = numpy.array((
            x,
            y,
            z,
            x,
            y2,
            z,
            x2,
            y2,
            z,
            x2,
            y,
            z,
        ),
                                   dtype='f4')

    elif face == faces.FaceZIncreasing:
        faceVertices = numpy.array((
            x2,
            y,
            z2,
            x2,
            y2,
            z2,
            x,
            y2,
            z2,
            x,
            y,
            z2,
        ),
                                   dtype='f4')
    else:
        raise ValueError("Unknown face %s" % face)

    faceVertices.shape = (4, 3)
    dim = face >> 1
    dims = [0, 1, 2]
    dims.remove(dim)

    texVertices = numpy.array(faceVertices[:, dims], dtype='f4').flatten()
    faceVertices.shape = (12, )

    texVertices *= 16
    with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY):

        GL.glVertexPointer(3, GL.GL_FLOAT, 0, faceVertices)
        GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, texVertices)

        with gl.glPushAttrib(GL.GL_POLYGON_BIT):
            GL.glEnable(GL.GL_POLYGON_OFFSET_FILL)
            GL.glEnable(GL.GL_POLYGON_OFFSET_LINE)

            if elementType is GL.GL_LINE_STRIP:
                indexes = numpy.array((0, 1, 2, 3, 0), dtype='uint32')
                GL.glDrawElements(elementType, 5, GL.GL_UNSIGNED_INT, indexes)
            else:
                GL.glDrawArrays(elementType, 0, 4)
Beispiel #28
0
def drawBox(box, cubeType=GL.GL_QUADS, texture=None, textureVertices=None, selectionBox=False):
    """ pass a different cubeType e.g. GL_LINE_STRIP for wireframes """
    x, y, z, = box.origin
    x2, y2, z2 = box.maximum
    dx, dy, dz = x2 - x, y2 - y, z2 - z
    cubeVertices = numpy.array(
        (
            x, y, z,
            x, y2, z,
            x2, y2, z,
            x2, y, z,

            x2, y, z2,
            x2, y2, z2,
            x, y2, z2,
            x, y, z2,

            x2, y, z2,
            x, y, z2,
            x, y, z,
            x2, y, z,

            x2, y2, z,
            x, y2, z,
            x, y2, z2,
            x2, y2, z2,

            x, y2, z2,
            x, y2, z,
            x, y, z,
            x, y, z2,

            x2, y, z2,
            x2, y, z,
            x2, y2, z,
            x2, y2, z2,
        ), dtype='f4')
    if textureVertices is None and texture is not None:
        textureVertices = numpy.array(
            (
                0, -dy * 16,
                0, 0,
                dx * 16, 0,
                dx * 16, -dy * 16,

                dx * 16, -dy * 16,
                dx * 16, 0,
                0, 0,
                0, -dy * 16,

                dx * 16, -dz * 16,
                0, -dz * 16,
                0, 0,
                dx * 16, 0,

                dx * 16, 0,
                0, 0,
                0, -dz * 16,
                dx * 16, -dz * 16,

                dz * 16, 0,
                0, 0,
                0, -dy * 16,
                dz * 16, -dy * 16,

                dz * 16, -dy * 16,
                0, -dy * 16,
                0, 0,
                dz * 16, 0,

            ), dtype='f4')

        textureVertices.shape = (6, 4, 2)

        if selectionBox:
            textureVertices[0:2] += (16 * (x & 15), 16 * (y2 & 15))
            textureVertices[2:4] += (16 * (x & 15), -16 * (z & 15))
            textureVertices[4:6] += (16 * (z & 15), 16 * (y2 & 15))
            textureVertices[:] += 0.5

    with gl.glPushAttrib(GL.GL_TEXTURE_BIT):
        GL.glVertexPointer(3, GL.GL_FLOAT, 0, cubeVertices)
        if texture is not None:
            GL.glEnable(GL.GL_TEXTURE_2D)
            GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY)

            texture.bind()
            GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, textureVertices),

        with gl.glPushAttrib(GL.GL_POLYGON_BIT):
            GL.glEnable(GL.GL_POLYGON_OFFSET_FILL)
            GL.glEnable(GL.GL_POLYGON_OFFSET_LINE)

            GL.glDrawArrays(cubeType, 0, 24)
        if texture is not None:
            GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY)
Beispiel #29
0
def drawFace(box, face, elementType=GL.GL_QUADS):
    x, y, z, = box.origin
    x2, y2, z2 = box.maximum

    if face == faces.FaceXDecreasing:
        faceVertices = numpy.array(
            (x, y2, z2,
             x, y2, z,
             x, y, z,
             x, y, z2,
            ), dtype='f4')

    elif face == faces.FaceXIncreasing:
        faceVertices = numpy.array(
            (x2, y, z2,
             x2, y, z,
             x2, y2, z,
             x2, y2, z2,
            ), dtype='f4')

    elif face == faces.FaceYDecreasing:
        faceVertices = numpy.array(
            (x2, y, z2,
             x, y, z2,
             x, y, z,
             x2, y, z,
            ), dtype='f4')

    elif face == faces.FaceYIncreasing:
        faceVertices = numpy.array(
            (x2, y2, z,
             x, y2, z,
             x, y2, z2,
             x2, y2, z2,
            ), dtype='f4')

    elif face == faces.FaceZDecreasing:
        faceVertices = numpy.array(
            (x, y, z,
             x, y2, z,
             x2, y2, z,
             x2, y, z,
            ), dtype='f4')

    elif face == faces.FaceZIncreasing:
        faceVertices = numpy.array(
            (x2, y, z2,
             x2, y2, z2,
             x, y2, z2,
             x, y, z2,
            ), dtype='f4')
    else:
        raise ValueError("Unknown face %s" % face)

    faceVertices.shape = (4, 3)
    dim = face >> 1
    dims = [0, 1, 2]
    dims.remove(dim)

    texVertices = numpy.array(
        faceVertices[:, dims],
        dtype='f4'
    ).flatten()
    faceVertices.shape = (12,)

    texVertices *= 16
    GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY)

    GL.glVertexPointer(3, GL.GL_FLOAT, 0, faceVertices)
    GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, texVertices)

    with gl.glPushAttrib(GL.GL_POLYGON_BIT):
        GL.glEnable(GL.GL_POLYGON_OFFSET_FILL)
        GL.glEnable(GL.GL_POLYGON_OFFSET_LINE)

        if elementType is GL.GL_LINE_STRIP:
            indexes = numpy.array((0, 1, 2, 3, 0), dtype='uint32')
            GL.glDrawElements(elementType, 5, GL.GL_UNSIGNED_INT, indexes)
        else:
            GL.glDrawArrays(elementType, 0, 4)

    GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY)
Beispiel #30
0
def drawBox(box,
            cubeType=GL.GL_QUADS,
            texture=None,
            textureVertices=None,
            selectionBox=False):
    """ pass a different cubeType e.g. GL_LINE_STRIP for wireframes """
    x, y, z, = box.origin
    x2, y2, z2 = box.maximum
    dx, dy, dz = x2 - x, y2 - y, z2 - z
    cubeVertices = numpy.array((
        x,
        y,
        z,
        x,
        y2,
        z,
        x2,
        y2,
        z,
        x2,
        y,
        z,
        x2,
        y,
        z2,
        x2,
        y2,
        z2,
        x,
        y2,
        z2,
        x,
        y,
        z2,
        x2,
        y,
        z2,
        x,
        y,
        z2,
        x,
        y,
        z,
        x2,
        y,
        z,
        x2,
        y2,
        z,
        x,
        y2,
        z,
        x,
        y2,
        z2,
        x2,
        y2,
        z2,
        x,
        y2,
        z2,
        x,
        y2,
        z,
        x,
        y,
        z,
        x,
        y,
        z2,
        x2,
        y,
        z2,
        x2,
        y,
        z,
        x2,
        y2,
        z,
        x2,
        y2,
        z2,
    ),
                               dtype='f4')
    if textureVertices is None and texture is not None:
        textureVertices = numpy.array((
            0,
            -dy * 16,
            0,
            0,
            dx * 16,
            0,
            dx * 16,
            -dy * 16,
            dx * 16,
            -dy * 16,
            dx * 16,
            0,
            0,
            0,
            0,
            -dy * 16,
            dx * 16,
            -dz * 16,
            0,
            -dz * 16,
            0,
            0,
            dx * 16,
            0,
            dx * 16,
            0,
            0,
            0,
            0,
            -dz * 16,
            dx * 16,
            -dz * 16,
            dz * 16,
            0,
            0,
            0,
            0,
            -dy * 16,
            dz * 16,
            -dy * 16,
            dz * 16,
            -dy * 16,
            0,
            -dy * 16,
            0,
            0,
            dz * 16,
            0,
        ),
                                      dtype='f4')

        textureVertices.shape = (6, 4, 2)

        if selectionBox:
            textureVertices[0:2] += (16 * (x & 15), 16 * (y2 & 15))
            textureVertices[2:4] += (16 * (x & 15), -16 * (z & 15))
            textureVertices[4:6] += (16 * (z & 15), 16 * (y2 & 15))
            textureVertices[:] += 0.5

    with gl.glPushAttrib(GL.GL_TEXTURE_BIT):
        GL.glVertexPointer(3, GL.GL_FLOAT, 0, cubeVertices)
        if texture is not None:
            GL.glEnable(GL.GL_TEXTURE_2D)
            GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY)

            texture.bind()
            GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, textureVertices),

        with gl.glPushAttrib(GL.GL_POLYGON_BIT):
            GL.glEnable(GL.GL_POLYGON_OFFSET_FILL)
            GL.glEnable(GL.GL_POLYGON_OFFSET_LINE)

            GL.glDrawArrays(cubeType, 0, 24)
        if texture is not None:
            GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY)