Exemplo n.º 1
0
    def _setMeshAttributes(self, mesh: MeshData) -> None:
        self._shader.enableAttribute("a_vertex", "vector3f", 0)
        vertex_count = mesh.getVertexCount()
        offset = vertex_count * 3 * 4

        if mesh.hasNormals():
            self._shader.enableAttribute("a_normal", "vector3f", offset)
            offset += vertex_count * 3 * 4

        if mesh.hasColors():
            self._shader.enableAttribute("a_color", "vector4f", offset)
            offset += vertex_count * 4 * 4

        if mesh.hasUVCoordinates():
            self._shader.enableAttribute("a_uvs", "vector2f", offset)
            offset += vertex_count * 2 * 4

        for attribute_name in mesh.attributeNames():
            attribute = mesh.getAttribute(attribute_name)
            self._shader.enableAttribute(attribute["opengl_name"],
                                         attribute["opengl_type"], offset)
            if attribute["opengl_type"] == "vector2f":
                offset += mesh.getVertexCount() * 2 * 4
            elif attribute["opengl_type"] == "vector4f":
                offset += mesh.getVertexCount() * 4 * 4
            elif attribute["opengl_type"] == "int":
                offset += mesh.getVertexCount() * 4
            elif attribute["opengl_type"] == "float":
                offset += mesh.getVertexCount() * 4
            else:
                Logger.log(
                    "e",
                    "Attribute with name [%s] uses non implemented type [%s]."
                    % (attribute["opengl_name"], attribute["opengl_type"]))
                self._shader.disableAttribute(attribute["opengl_name"])
Exemplo n.º 2
0
def test_attributes():
    attributes = {"test": {"value": [10], "derp": "OMG"}}
    mesh_data = MeshData(attributes=attributes)

    assert mesh_data.hasAttribute("test")
    assert mesh_data.getAttribute("test") == {"value": [10], "derp": "OMG"}

    assert mesh_data.attributeNames() == ["test"]
Exemplo n.º 3
0
def test_attributes():
    attributes = { "test": {
                "value": [10],
                "derp": "OMG"
                }}
    mesh_data = MeshData(attributes = attributes)

    assert mesh_data.hasAttribute("test")
    assert mesh_data.getAttribute("test") == { "value": [10], "derp": "OMG" }

    assert mesh_data.attributeNames() == ["test"]