def velocity_transform(dr, dq, dt):
    linvel = dr * dt

    rotvel_z = ScalarTransform4f.rotate([0, 0, 1], dq[2] * dt)
    rotvel_y = ScalarTransform4f.rotate([0, 1, 0], dq[1] * dt)
    rotvel_x = ScalarTransform4f.rotate([1, 0, 0], dq[0] * dt)
    rotvel = rotvel_x * rotvel_y * rotvel_z

    return ScalarTransform4f.translate(linvel) * rotvel
def position_transform(r, q):
    pos = r

    rot_z = ScalarTransform4f.rotate([0, 0, 1], q[2])
    rot_y = ScalarTransform4f.rotate([0, 1, 0], q[1])
    rot_x = ScalarTransform4f.rotate([1, 0, 0], q[0])
    rot = rot_x * rot_y * rot_z

    return ScalarTransform4f.translate(pos) * rot
def test01_create(variant_scalar_rgb):
    from mitsuba.core import xml, ScalarTransform4f

    s = xml.load_dict({"type": "sphere"})
    assert s is not None
    assert s.primitive_count() == 1
    assert ek.allclose(s.surface_area(), 4 * ek.pi)

    # Test transforms order in constructor

    rot = ScalarTransform4f.rotate([1.0, 0.0, 0.0], 35)

    s1 = xml.load_dict({
        "type": "sphere",
        "radius": 2.0,
        "center": [1, 0, 0],
        "to_world": rot
    })

    s2 = xml.load_dict({
        "type":
        "sphere",
        "to_world":
        rot * ScalarTransform4f.translate([1, 0, 0]) *
        ScalarTransform4f.scale(2)
    })

    assert str(s1) == str(s2)
Example #4
0
def example_scene(shape, scale=1.0, translate=[0, 0, 0], angle=0.0):
    from mitsuba.core import xml, ScalarTransform4f as T

    to_world = T.translate(translate) * T.rotate([0, 1, 0],
                                                 angle) * T.scale(scale)

    shape2 = shape.copy()
    shape2['to_world'] = to_world

    s = xml.load_dict({'type': 'scene', 'shape': shape2})

    s_inst = xml.load_dict({
        'type': 'scene',
        'group_0': {
            'type': 'shapegroup',
            'shape': shape
        },
        'instance': {
            'type': 'instance',
            "group": {
                "type": "ref",
                "id": "group_0"
            },
            'to_world': to_world
        }
    })

    return s, s_inst
Example #5
0
    def add_object(self, scene_dict):
        """
        Add registered meshes to given scene file format
        """

        if len(self.bssrdf) != len(self.mesh):
            exit("The number of registerd mesh and bssrdf are different!")

        num_mesh = len(self.bssrdf)
        num_obj = len(self.bssrdf_obj)

        for i in range(num_obj):
            i += 1

            scene_dict["obj_" + str(i)] = {
                "type": "shapegroup"
            }

        for i in range(num_mesh):
            i += 1
            bssrdf = self.bssrdf[i]
            mesh = self.mesh[i]

            axis = None
            if(mesh["rotate"]["axis"] == "x"):
                axis = [1, 0, 0]
            elif(mesh["rotate"]["axis"] == "y"):
                axis = [0, 1, 0]
            elif(mesh["rotate"]["axis"] == "z"):
                axis = [0, 0, 1]
            angle = mesh["rotate"]["angle"]


            if mesh["type"] == "rectangle":
                shape = {
                    "type": mesh["type"],
                    "to_world": ScalarTransform4f.translate(mesh["translate"])
                                * ScalarTransform4f.rotate(axis, angle)
                                * ScalarTransform4f.scale(mesh["scale"]),
                }
        
            else:
                shape = {
                    "type": mesh["type"],
                    "filename": mesh["filename"],
                    "to_world": ScalarTransform4f.translate(mesh["translate"])
                                * ScalarTransform4f.rotate(axis, angle)
                                * ScalarTransform4f.scale(mesh["scale"]),
                }

            bssrdf["trans"] = mesh["translate"]
            if(mesh["rotate"]["axis"] == "x"):
                bssrdf["rotate_x"] = angle
            elif(mesh["rotate"]["axis"] == "y"):
                bssrdf["rotate_y"] = angle
            elif(mesh["rotate"]["axis"] == "z"):
                bssrdf["rotate_z"] = angle

            bssrdf["height_max"] = mesh["height_max"]

            bsdf = {
                "bsdf_" + str(i): bssrdf
            }

            shape.update(bsdf)
            
            for j in range(num_obj):
                j += 1

                if i in self.bssrdf_obj[j]:
                    scene_dict["obj_" + str(j)][str(i)] = shape

        for i in range(num_obj):
            i += 1
            scene_dict["instance_" + str(i)] = {
                "type": "instance",
                "group":{
                    "type": "ref",
                    "id": "obj_" + str(i)
                }
            }

        return scene_dict
Example #6
0
        },

        "film": {
            "type": "hdrfilm",
            "width": config.film_width,
            "height": config.film_height,
            "rfilter": {
                "type": "gaussian"
            }
        }
    },

    "emitter": {
        "type": "envmap",
        "filename": "C:/Users/mineg/mitsuba2/myscripts/render/dict/envmap.exr",
        "to_world": ScalarTransform4f.rotate([1,0,0], angle=90)
    },

    "checker": {
        "type": "checkerboard",
        "color0": 0.4,
        "color1": 0.2,
        "to_uv": ScalarTransform4f.scale(2)
    },

    "planemat": {
        "type": "diffuse",
        "reflectance": {
            "type": "ref",
            "id": "checker"
        }