예제 #1
0
def test_getAndSet(data):
    color = Color(*data["data_to_set"])

    assert color == Color(*data["expected"])

    assert color.r == data["expected"][0]
    assert color.g == data["expected"][1]
    assert color.b == data["expected"][2]
    assert color.a == data["expected"][3]

    # And flip the data around to set the values one by one
    reversed_data = data["data_to_set"][::-1]
    color.setR(reversed_data[0])
    color.setG(reversed_data[1])
    color.setB(reversed_data[2])
    color.setA(reversed_data[3])

    assert color.r == data["expected"][3]
    assert color.g == data["expected"][2]
    assert color.b == data["expected"][1]
    assert color.a == data["expected"][0]
예제 #2
0
def test_getAndSet(data):
    color = Color(*data["data_to_set"])

    assert color == Color(*data["expected"])

    assert color.r == data["expected"][0]
    assert color.g == data["expected"][1]
    assert color.b == data["expected"][2]
    assert color.a == data["expected"][3]

    # And flip the data around to set the values one by one
    reversed_data = data["data_to_set"][::-1]
    color.setR(reversed_data[0])
    color.setG(reversed_data[1])
    color.setB(reversed_data[2])
    color.setA(reversed_data[3])

    assert color.r == data["expected"][3]
    assert color.g == data["expected"][2]
    assert color.b == data["expected"][1]
    assert color.a == data["expected"][0]
예제 #3
0
class ConvexHullNode(SceneNode):
    def __init__(self, node, hull, parent = None):
        super().__init__(parent)

        self.setCalculateBoundingBox(False)

        self._shader = None

        self._original_parent = parent

        self._inherit_orientation = False
        self._inherit_scale = False

        self._color = Color(35, 35, 35, 128)

        self._node = node
        self._node.transformationChanged.connect(self._onNodePositionChanged)
        self._node.parentChanged.connect(self._onNodeParentChanged)
        self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged)
        self._onNodeDecoratorsChanged(self._node)
        self._convex_hull_head_mesh = None
        self._hull = hull

        hull_points = self._hull.getPoints()
        hull_mesh = self.createHullMesh(self._hull.getPoints())
        if hull_mesh:
            self.setMeshData(hull_mesh)
        convex_hull_head = self._node.callDecoration("getConvexHullHead")
        if convex_hull_head:
            self._convex_hull_head_mesh = self.createHullMesh(convex_hull_head.getPoints())

    def createHullMesh(self, hull_points):
        mesh = MeshData()
        if len(hull_points) > 3:
            center = (hull_points.min(0) + hull_points.max(0)) / 2.0
            mesh.addVertex(center[0], -0.1, center[1])
        else:
            return None
        for point in hull_points:
            mesh.addVertex(point[0], -0.1, point[1])
        indices = []
        for i in range(len(hull_points) - 1):
            indices.append([0, i + 1, i + 2])

        indices.append([0, mesh.getVertexCount() - 1, 1])

        mesh.addIndices(numpy.array(indices, numpy.int32))
        return mesh

    def getWatchedNode(self):
        return self._node

    def render(self, renderer):
        if not self._shader:
            self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
            self._shader.setUniformValue("u_color", self._color)

        if self.getParent():
            renderer.queueNode(self, transparent = True, shader = self._shader, backface_cull = True, sort = -8)
            if self._convex_hull_head_mesh:
                renderer.queueNode(self, shader = self._shader, transparent = True, mesh = self._convex_hull_head_mesh, backface_cull = True, sort = -8)

        return True

    def _onNodePositionChanged(self, node):
        if node.callDecoration("getConvexHull"): 
            node.callDecoration("setConvexHull", None)
            node.callDecoration("setConvexHullNode", None)
            self.setParent(None)

    def _onNodeParentChanged(self, node):
        if node.getParent():
            self.setParent(self._original_parent)
        else:
            self.setParent(None)

    def _onNodeDecoratorsChanged(self, node):
        self._color = Color(35, 35, 35, 0.5)

        if not node:
            return

        if node.hasDecoration("getProfile"):
            self._color.setR(0.75)

        if node.hasDecoration("getSetting"):
            self._color.setG(0.75)
예제 #4
0
class ConvexHullNode(SceneNode):
    def __init__(self, node, hull, parent=None):
        super().__init__(parent)

        self.setCalculateBoundingBox(False)

        self._shader = None

        self._original_parent = parent

        self._inherit_orientation = False
        self._inherit_scale = False

        self._color = Color(35, 35, 35, 128)

        self._node = node
        self._node.transformationChanged.connect(self._onNodePositionChanged)
        self._node.parentChanged.connect(self._onNodeParentChanged)
        self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged)
        self._onNodeDecoratorsChanged(self._node)
        self._convex_hull_head_mesh = None
        self._hull = hull

        hull_points = self._hull.getPoints()
        hull_mesh = self.createHullMesh(self._hull.getPoints())
        if hull_mesh:
            self.setMeshData(hull_mesh)
        convex_hull_head = self._node.callDecoration("getConvexHullHead")
        if convex_hull_head:
            self._convex_hull_head_mesh = self.createHullMesh(
                convex_hull_head.getPoints())

    def createHullMesh(self, hull_points):
        mesh = MeshData()
        if len(hull_points) > 3:
            center = (hull_points.min(0) + hull_points.max(0)) / 2.0
            mesh.addVertex(center[0], -0.1, center[1])
        else:
            return None
        for point in hull_points:
            mesh.addVertex(point[0], -0.1, point[1])
        indices = []
        for i in range(len(hull_points) - 1):
            indices.append([0, i + 1, i + 2])

        indices.append([0, mesh.getVertexCount() - 1, 1])

        mesh.addIndices(numpy.array(indices, numpy.int32))
        return mesh

    def getWatchedNode(self):
        return self._node

    def render(self, renderer):
        if not self._shader:
            self._shader = OpenGL.getInstance().createShaderProgram(
                Resources.getPath(Resources.Shaders, "default.shader"))
            self._shader.setUniformValue("u_color", self._color)

        if self.getParent():
            renderer.queueNode(self,
                               transparent=True,
                               shader=self._shader,
                               backface_cull=True,
                               sort=-8)
            if self._convex_hull_head_mesh:
                renderer.queueNode(self,
                                   shader=self._shader,
                                   transparent=True,
                                   mesh=self._convex_hull_head_mesh,
                                   backface_cull=True,
                                   sort=-8)

        return True

    def _onNodePositionChanged(self, node):
        if node.callDecoration("getConvexHull"):
            node.callDecoration("setConvexHull", None)
            node.callDecoration("setConvexHullNode", None)
            self.setParent(None)

    def _onNodeParentChanged(self, node):
        if node.getParent():
            self.setParent(self._original_parent)
        else:
            self.setParent(None)

    def _onNodeDecoratorsChanged(self, node):
        self._color = Color(35, 35, 35, 0.5)

        if not node:
            return

        if node.hasDecoration("getProfile"):
            self._color.setR(0.75)

        if node.hasDecoration("getSetting"):
            self._color.setG(0.75)
예제 #5
0
class ConvexHullNode(SceneNode):
    def __init__(self, node, hull, parent = None):
        super().__init__(parent)

        self.setCalculateBoundingBox(False)

        self._shader = None

        self._original_parent = parent

        self._inherit_orientation = False
        self._inherit_scale = False

        self._color = Color(35, 35, 35, 128)
        self._mesh_height = 0.1 #The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting.

        self._node = node
        self._node.transformationChanged.connect(self._onNodePositionChanged)
        self._node.parentChanged.connect(self._onNodeParentChanged)
        self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged)
        self._onNodeDecoratorsChanged(self._node)
        self._convex_hull_head_mesh = None
        self._hull = hull

        hull_points = self._hull.getPoints()
        hull_mesh = self.createHullMesh(self._hull.getPoints())
        if hull_mesh:
            self.setMeshData(hull_mesh)
        convex_hull_head = self._node.callDecoration("getConvexHullHead")
        if convex_hull_head:
            self._convex_hull_head_mesh = self.createHullMesh(convex_hull_head.getPoints())

    def createHullMesh(self, hull_points):
        #Input checking.
        if len(hull_points) < 3:
            return None

        mesh_builder = MeshBuilder()
        point_first = Vector(hull_points[0][0], self._mesh_height, hull_points[0][1])
        point_previous = Vector(hull_points[1][0], self._mesh_height, hull_points[1][1])
        for point in hull_points[2:]: #Add the faces in the order of a triangle fan.
            point_new = Vector(point[0], self._mesh_height, point[1])
            mesh_builder.addFace(point_first, point_previous, point_new, color = self._color)
            point_previous = point_new #Prepare point_previous for the next triangle.

        return mesh_builder.getData()

    def getWatchedNode(self):
        return self._node

    def render(self, renderer):
        if not self._shader:
            self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
            self._shader.setUniformValue("u_color", self._color)

        if self.getParent():
            renderer.queueNode(self, transparent = True, shader = self._shader, backface_cull = True, sort = -8)
            if self._convex_hull_head_mesh:
                renderer.queueNode(self, shader = self._shader, transparent = True, mesh = self._convex_hull_head_mesh, backface_cull = True, sort = -8)

        return True

    def _onNodePositionChanged(self, node):
        if node.callDecoration("getConvexHull"): 
            node.callDecoration("setConvexHull", None)
            node.callDecoration("setConvexHullNode", None)
            self.setParent(None)

    def _onNodeParentChanged(self, node):
        if node.getParent():
            self.setParent(self._original_parent)
        else:
            self.setParent(None)

    def _onNodeDecoratorsChanged(self, node):
        self._color = Color(35, 35, 35, 0.5)

        if not node:
            return

        if node.hasDecoration("getProfile"):
            self._color.setR(0.75)

        if node.hasDecoration("getSetting"):
            self._color.setG(0.75)
예제 #6
0
class ConvexHullNode(SceneNode):
    def __init__(self, node, hull, parent=None):
        super().__init__(parent)

        self.setCalculateBoundingBox(False)

        self._shader = None

        self._original_parent = parent

        self._inherit_orientation = False
        self._inherit_scale = False

        self._color = Color(35, 35, 35, 128)
        self._mesh_height = 0.1  #The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting.

        self._node = node
        self._node.transformationChanged.connect(self._onNodePositionChanged)
        self._node.parentChanged.connect(self._onNodeParentChanged)
        self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged)
        self._onNodeDecoratorsChanged(self._node)
        self._convex_hull_head_mesh = None
        self._hull = hull

        hull_points = self._hull.getPoints()  # TODO: @UnusedVariable
        hull_mesh = self.createHullMesh(self._hull.getPoints())
        if hull_mesh:
            self.setMeshData(hull_mesh)
        convex_hull_head = self._node.callDecoration("getConvexHullHead")
        if convex_hull_head:
            self._convex_hull_head_mesh = self.createHullMesh(
                convex_hull_head.getPoints())

    def createHullMesh(self, hull_points):
        #Input checking.
        if len(hull_points) < 3:
            return None

        mesh_builder = MeshBuilder()
        point_first = Vector(hull_points[0][0], self._mesh_height,
                             hull_points[0][1])
        point_previous = Vector(hull_points[1][0], self._mesh_height,
                                hull_points[1][1])
        for point in hull_points[
                2:]:  #Add the faces in the order of a triangle fan.
            point_new = Vector(point[0], self._mesh_height, point[1])
            mesh_builder.addFace(point_first,
                                 point_previous,
                                 point_new,
                                 color=self._color)
            point_previous = point_new  #Prepare point_previous for the next triangle.

        return mesh_builder.getData()

    def getWatchedNode(self):
        return self._node

    def render(self, renderer):
        if not self._shader:
            self._shader = OpenGL.getInstance().createShaderProgram(
                Resources.getPath(Resources.Shaders, "default.shader"))
            self._shader.setUniformValue("u_color", self._color)

        if self.getParent():
            renderer.queueNode(self,
                               transparent=True,
                               shader=self._shader,
                               backface_cull=True,
                               sort=-8)
            if self._convex_hull_head_mesh:
                renderer.queueNode(self,
                                   shader=self._shader,
                                   transparent=True,
                                   mesh=self._convex_hull_head_mesh,
                                   backface_cull=True,
                                   sort=-8)

        return True

    def _onNodePositionChanged(self, node):
        if node.callDecoration("getConvexHull"):
            node.callDecoration("setConvexHull", None)
            node.callDecoration("setConvexHullNode", None)
            self.setParent(None)

    def _onNodeParentChanged(self, node):
        if node.getParent():
            self.setParent(self._original_parent)
        else:
            self.setParent(None)

    def _onNodeDecoratorsChanged(self, node):
        self._color = Color(35, 35, 35, 0.5)

        if not node:
            return

        if node.hasDecoration("getProfile"):
            self._color.setR(0.75)

        if node.hasDecoration("getSetting"):
            self._color.setG(0.75)