Example #1
0
    def create_cube(self):
        """ create a cube for future use """
        room = concrete_room.ConcreteRoom()
        parent = room.add_child(None, "parent")
        self.assertIsNotNone(parent)
        parent.add_dressing_faces(
            [
            cgtypes.vec3(0,0,0),
            cgtypes.vec3(0,0,1),
            cgtypes.vec3(0,1,1),
            cgtypes.vec3(0,1,0),

            cgtypes.vec3(1,0,0),
            cgtypes.vec3(1,0,1),
            cgtypes.vec3(1,1,1),
            cgtypes.vec3(1,1,0),
            ],
            [
                # X,Y
                [5,6,2,1],
                [0,3,7,4],
             ],
            concrete_room.get_texture_definition(
                "common/basic/wall.jpg",
                axes=[ ["x",],["y"] ],
                scale=1.0 ))

        parent.add_dressing_faces(
            [
            cgtypes.vec3(0,0,0),
            cgtypes.vec3(0,0,1),
            cgtypes.vec3(0,1,1),
            cgtypes.vec3(0,1,0),

            cgtypes.vec3(1,0,0),
            cgtypes.vec3(1,0,1),
            cgtypes.vec3(1,1,1),
            cgtypes.vec3(1,1,0),
            ],
            [
                # Y,Z
                [0,1,2,3],
                [7,6,5,4],

                # X,Z
                [4,5,1,0],
                [6,7,3,2],
             ],
            concrete_room.get_texture_definition(
                "common/basic/ground.jpg",
                axes=[ ["x", "y"],["z"] ],
                scale=1.0 ))
        return room
Example #2
0
 def generate(self, concrete):
     """Instantiate only 1 triangle to pass validity check"""
     parent = concrete.get_node("parent")
     parent.add_dressing_faces(
         [cgtypes.vec3(0),
          cgtypes.vec3(1),
          cgtypes.vec3(2)], [[0, 1, 2]],
         concrete_room.get_texture_definition("../texture.png"))
Example #3
0
 def generate(self, concrete):
     """Instantiate only 1 triangle to pass validity check"""
     parent = concrete.get_node(self._element.values.gate_id + "_impl")
     parent.add_dressing_faces(
         [cgtypes.vec3(3),
          cgtypes.vec3(4),
          cgtypes.vec3(5)], [[0, 1, 2]],
         concrete_room.get_texture_definition("../texture.png"))
 def test_proj_matrix(self):
     """test proj matrix construction"""
     default_tex = concrete_room.get_texture_definition(
             "texture.png")
     self.assertEqual(default_tex,
     {
         'texture': 'texture.png',
         'proj': cgtypes.mat4(
             1.0, 0.0, 0.0, 0.0,
             0.0, 1.0, 0.0, 0.0,
             0.0, 0.0, 0.0, 0.0,
             1.0, 1.0, 1.0, 0.0)})
     offset_tex = concrete_room.get_texture_definition(
             "texture.png", offset = cgtypes.vec3(1,2,3))
     self.assertEqual(offset_tex,
     {
         'texture': 'texture.png',
         'proj': cgtypes.mat4(
             1.0, 0.0, 0.0, 1.0,
             0.0, 1.0, 0.0, 2.0,
             0.0, 0.0, 0.0, 3.0,
             1.0, 1.0, 1.0, 0.0)})
     scale_tex = concrete_room.get_texture_definition(
             "texture.png", scale = 2.0)
     self.assertEqual(scale_tex,
     {
         'texture': 'texture.png',
         'proj': cgtypes.mat4(
             2.0, 0.0, 0.0, 0.0,
             0.0, 2.0, 0.0, 0.0,
             0.0, 0.0, 0.0, 0.0,
             1.0, 1.0, 1.0, 0.0)})
     axes_tex = concrete_room.get_texture_definition(
             "texture.png", axes=[ ["x","y"], [ "z"] ])
     self.assertEqual(axes_tex,
     {
         'texture': 'texture.png',
         'proj': cgtypes.mat4(
             1.0, 1.0, 0.0, 0.0,
             0.0, 0.0, 1.0, 0.0,
             0.0, 0.0, 0.0, 0.0,
             1.0, 1.0, 1.0, 0.0)})
 def test_dressing_faces(self):
     """Test creating a simple impl with 1 node with multiple points and faces sets
     for dressing. This tests both multi-textures and merging of faces with the same texture"""
     room = concrete_room.ConcreteRoom()
     self.assertIsNotNone(room)
     parent = room.add_child(None, "parent")
     self.assertIsNotNone(parent)
     parent.add_dressing_faces(
         [ cgtypes.vec3(0), cgtypes.vec3(1), cgtypes.vec3(2) , cgtypes.vec3(3) ],
         [ [0,1,2], [1,2,3], [2,3,0] ],
         concrete_room.get_texture_definition("myfilename"))
     parent.add_dressing_faces(
         [  cgtypes.vec3(2) , cgtypes.vec3(3) , cgtypes.vec3(4) ],
         [ [0,1,2] ],
         concrete_room.get_texture_definition("myfilename"))
     parent.add_dressing_faces(
         [ cgtypes.vec3(0), cgtypes.vec3(1), cgtypes.vec3(2) , cgtypes.vec3(3) ],
         [ [0,1,2], [1,2,3], [2,3,0]],
         concrete_room.get_texture_definition("myfilename2"))
     j = json.loads(room.dump_to_json())
     faces = j["objects"][0]["dressing"]
     print(faces)
     self.assertEqual(faces, {
         'myfilename': {
             'points': [
                 {'x': 0.0, 'y': 0.0, 'z': 0.0, 'u': 0.0, 'v': 0.0},
                 {'x': 1.0, 'y': 1.0, 'z': 1.0, 'u': 1.0, 'v': 1.0},
                 {'x': 2.0, 'y': 2.0, 'z': 2.0, 'u': 2.0, 'v': 2.0},
                 {'x': 3.0, 'y': 3.0, 'z': 3.0, 'u': 3.0, 'v': 3.0},
                 {'x': 4.0, 'y': 4.0, 'z': 4.0, 'u': 4.0, 'v': 4.0}],
             'faces': [
                 [0, 1, 2], [1, 2, 3], [2, 3, 0], [2, 3, 4]]},
         'myfilename2': {
             'points': [
                 {'x': 0.0, 'y': 0.0, 'z': 0.0, 'u': 0.0, 'v': 0.0},
                 {'x': 1.0, 'y': 1.0, 'z': 1.0, 'u': 1.0, 'v': 1.0},
                 {'x': 2.0, 'y': 2.0, 'z': 2.0, 'u': 2.0, 'v': 2.0},
                 {'x': 3.0, 'y': 3.0, 'z': 3.0, 'u': 3.0, 'v': 3.0}],
             'faces': [
                 [0, 1, 2], [1, 2, 3], [2, 3, 0]
         ]}}
     )
    def test_merge(self):
        """
        test merging 2 concrete rooms. 2nd structure is linked to first
        by the name of one of its node's parent child.
        """
        default_tex = concrete_room.get_texture_definition(
                "texture.png")
        room1 = concrete_room.ConcreteRoom()
        parent1 = room1.add_child(None, "parent1")
        child1_1 = room1.add_child("parent1", "child1_1")
        child1_2 = room1.add_child("parent1", "child1_2")
        index0 = child1_1.add_structure_points([ cgtypes.vec3(0), cgtypes.vec3(1), cgtypes.vec3(2) ])
        self.assertEqual(0, index0)
        child1_1.add_structure_faces(
            index0,
            [ [0,1,2]],
            [concrete_room.Node.CATEGORY_PHYSICS], [concrete_room.Node.HINT_BUILDING], [ 0 ] )

        room2 = concrete_room.ConcreteRoom()
        parent2 = room2.add_child("child1_1", "parent2") # volontarily linked to previous
        child2_1 = room2.add_child("parent2", "child2_1")
        child2_2 = room2.add_child("parent2", "child1_2")
        index0 = child2_1.add_structure_points([ cgtypes.vec3(4), cgtypes.vec3(5), cgtypes.vec3(6) ])
        self.assertEqual(0, index0)
        child2_1.add_structure_faces(
            index0,
            [ [0,1,2]],
            [concrete_room.Node.CATEGORY_PHYSICS], [concrete_room.Node.HINT_BUILDING], [ 0 ] )

        room1.merge(room2)
        nodes = room1.get_objects()
        node_names = [ n.name for n in nodes]
        self.assertEqual(node_names, ['parent1', 'child1_1', 'child1_2', 'parent2', 'child2_1', 'child1_2'])
        room1.generate_gltf("/tmp/")
        with open("/tmp/room.gltf", "r") as room_file:
            obj = json.load(room_file)
        objects = obj["nodes"]
        print(objects)
        self.assertEqual(objects,
            [{'children': [1]},
            {'name': 'parent1', 'children': [2, 3]},
            {'name': 'child1_1', 'children': [4], 'extras': {'phys_faces': [{'data': [0], 'accessor': 1}], 'points': 0}},
            {'name': 'child1_2'},
            {'name': 'parent2', 'children': [5, 6]},
            {'name': 'child2_1', 'extras': {'phys_faces': [{'data': [0], 'accessor': 3}], 'points': 2}},
            {'name': 'child1_2'}])
 def test_dump_1_face_3_points(self):
     """ test dumping 1 face with 3 points (aka triangle)  """
     room = concrete_room.ConcreteRoom()
     parent = room.add_child(None, "parent")
     self.assertIsNotNone(parent)
     parent.add_dressing_faces(
         [cgtypes.vec3(0,0,0),
         cgtypes.vec3(0,0,1),
         cgtypes.vec3(0,1,0) ],
         [ [0,1,2] ],
         concrete_room.get_texture_definition(
             "texture.png",
             axes=[ ["y"],["z"] ],
             scale=1.0 ))
     room.generate_gltf("/tmp")
     with open("/tmp/room.gltf", "r") as room_file:
         obj = json.load(room_file)
     parent_object = obj["nodes"][1]
     print(parent_object)
 def test_dressing_filter_points(self):
     """test filtering points when adding faces, so that only useful points are kept
     and there is no useless data"""
     room = concrete_room.ConcreteRoom()
     self.assertIsNotNone(room)
     parent = room.add_child(None, "parent")
     self.assertIsNotNone(parent)
     parent.add_dressing_faces(
         [
             cgtypes.vec3(0),
             cgtypes.vec3(1),
             cgtypes.vec3(1),
             cgtypes.vec3(2),
             cgtypes.vec3(3),
             cgtypes.vec3(4),
             cgtypes.vec3(5),
             cgtypes.vec3(6),
             cgtypes.vec3(7),
             cgtypes.vec3(8),
             cgtypes.vec3(9),
             cgtypes.vec3(10)
         ],
         [ [1,2,3], [2,3,4], [6,7,8]],
         concrete_room.get_texture_definition("myfilename"))
     j = json.loads(room.dump_to_json())
     faces = j["objects"][0]["dressing"]
     print(faces)
     self.assertEqual(faces, {
         'myfilename': {
             'points': [
                 {'x': 1.0, 'y': 1.0, 'z': 1.0, 'u': 1.0, 'v': 1.0},
                 {'x': 2.0, 'y': 2.0, 'z': 2.0, 'u': 2.0, 'v': 2.0},
                 {'x': 3.0, 'y': 3.0, 'z': 3.0, 'u': 3.0, 'v': 3.0},
                 {'x': 5.0, 'y': 5.0, 'z': 5.0, 'u': 5.0, 'v': 5.0},
                 {'x': 6.0, 'y': 6.0, 'z': 6.0, 'u': 6.0, 'v': 6.0},
                 {'x': 7.0, 'y': 7.0, 'z': 7.0, 'u': 7.0, 'v': 7.0}],
             'faces': [
                 [0, 0, 1],
                 [0, 1, 2],
                 [3, 4, 5]]}})
    def test_dump_cube(self):
        """ test dumping 1 face with 3 points (aka triangle) . Test preview dump """
        room = concrete_room.ConcreteRoom()
        parent = room.add_child(None, "parent")
        self.assertIsNotNone(parent)
        parent.add_dressing_faces(
            [
            cgtypes.vec3(0,0,0),
            cgtypes.vec3(0,0,1),
            cgtypes.vec3(0,1,1),
            cgtypes.vec3(0,1,0),

            cgtypes.vec3(1,0,0),
            cgtypes.vec3(1,0,1),
            cgtypes.vec3(1,1,1),
            cgtypes.vec3(1,1,0),
            ],
            [
                # X,Y
                [5,6,2,1],
                [0,3,7,4],
             ],
            concrete_room.get_texture_definition(
                "common/basic/wall.jpg",
                axes=[ ["x",],["y"] ],
                scale=1.0 ))

        parent.add_dressing_faces(
            [
            cgtypes.vec3(0,0,0),
            cgtypes.vec3(0,0,1),
            cgtypes.vec3(0,1,1),
            cgtypes.vec3(0,1,0),

            cgtypes.vec3(1,0,0),
            cgtypes.vec3(1,0,1),
            cgtypes.vec3(1,1,1),
            cgtypes.vec3(1,1,0),
            ],
            [
                # Y,Z
                [0,1,2,3],
                [7,6,5,4],

                # X,Z
                [4,5,1,0],
                [6,7,3,2],
             ],
            concrete_room.get_texture_definition(
                "common/basic/ground.jpg",
                axes=[ ["x", "y"],["z"] ],
                scale=1.0 ))

        path_gen = "/tmp/test_cube/output"
        pathlib.Path(path_gen).mkdir(parents=True, exist_ok=True)
        room.generate_gltf(path_gen)
        with open(path_gen + "/room.gltf", "r") as room_file:
            obj = json.load(room_file)
        parent_object = obj["nodes"][1]
        print(parent_object)
        concrete_room.preview(path_gen + "/room.gltf", path_gen + "/room_preview.gltf")