Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vapory with mesh #28

Open
mpkuse opened this issue Jul 26, 2016 · 2 comments
Open

vapory with mesh #28

mpkuse opened this issue Jul 26, 2016 · 2 comments

Comments

@mpkuse
Copy link

mpkuse commented Jul 26, 2016

I am trying to render a scene from mesh. I have a textured mesh which I am loading with assimp. Could you give me an hint as how to render a mesh scene with vapory.

@JBlaschke
Copy link

JBlaschke commented Jun 5, 2017

That's actually already possible with two (fairly small) extension classes. Let's look at a Mesh consisting of smooth triangles. Then you need to create the following two (empty) extensions of the
POVRayElement class:

class SmoothTriangle(POVRayElement):
   """SmoothTriangle([x,y,z], [nx, ny, nz])"""

and

class Mesh(POVRayElement):
    """Mesh( ... smooth triangles ..., texture )"""

You can then call Mesh(*args) where args is an array of smooth triangles and the Texture (for example: Texture(Pigment('color', [1, 0, 0])))

For instance you can construct args as follows:

mesh_elements = list()
for tri in self.mesh:
    mesh_elements.append(tri.as_vapory())

mesh_elements.append(Texture(Pigment('color', [1, 0, 0])))
Mesh(*mesh_elements)

That's all folks

@yoyolin
Copy link

yoyolin commented Jun 17, 2019

I didn't use the two empty class ; instead I used Triangle class provided in vapory and it works like a charm. Here's the code:

def load_3d_model(model_vertices, model_faces):
   """load meshes into a list of vapory Triangle object.
      :param model_vertices: a list of list; each list provides coordinates of one vertex in 3d space. For example, it might look like this: [[-0.282614,-0.0720009,-0.170291], [-0.282874,-0.0745509,-0.1703], [-0.281393,-0.0725343,-0.170298]]
      :param model_faces: a list that contains 6 float [vertex_index1, vertex_index2, vertex_index3, r, g, b]  and r,g,b here is in a 0-1 scale.
   """
   mesh_elements = []
   for face in model_faces:
       tri = Triangle(model_vertices[  face[0]  ],
                      model_vertices[  face[1]  ],
                      model_vertices[  face[2]  ],
                      Texture(Pigment('rgb', face[3:]) ))
       mesh_elements.append(tri)
   return mesh_elements

Rendering is easy too:

object_model = load_3d_model(model_vertices, model_faces)
light = LightSource([0, 0, 1], 'color', 1)
camera = Camera('location',  [0, 0, 1],
                       'direction', [0, 0, -1],
                       'look_at',  [0, 0, 0])
scene = Scene(camera, objects = [light] +  object_model)
scene.render('rendered.png', remove_temp = False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants