[Addon] Mitsuba Blender Plugin (26-Nov-15)

could it use .bvh like Intel embree? its what cycles uses and its fast.
embree is open source.

I think Mitsuba don’t use GPU. Embree 's code is useless in this case.
BTW anybody knows how to achieve this clothing goodness. Any example file of cloth and pattern?

http://www.mitsuba-renderer.org/download.html the irawan.zip and scarf.zip

awesome news about the new Mitsuba. Now I need to try and use it in a real serious scene. sigh I might do it for a school project along with an octane version >.> - Sucks not having time to do stuff XD

  • Now is SSS dipole working? It says it’s fixed in the notes but it is still listed as a broken feature here for the exporter?

GPU rendering will not be implemented into Mitsuba. I already asked if he had any future plans for it and he basically said no because it’s a waste of time since GPU rendering is too limiting at the moment and will probably loose steam eventually. It’s somewhere on his blog for a more detailed reason he gives.

I haven’t had time to test SSS with new version. Had to work on other things last two days.

@fjuhec: Found another material naming bug. Try adding an emissive material to a particle system and Mitsuba will fail to render.

In Line #540, exportEmission, of init.py in the export folder.

name = translate_id(obj.data.name) + "-mesh_0"

Change to:

name = translate_id(obj.name) + "-mesh_0"

.
.
.
On second thought, it looks like that did not fix it. So there is still a problem with Duplicate ID for materials when emission is used.

translate_id might have to be altered. It is modifying names without actually checking for existing name collision. Say I have three objects named “my.object”, “my-object” and “my object”. While these are three different Blender objects, translate_id will return the same name for each of them “my_object” and then try to serialize them using the same exact name.

embree doesn’t use GPU either… so not sure what your point is…
Building of a .bvh (something that can be rendered) fast is nice…
Mitsuba’s. .serialized and xml version seem alot slower

@fjuhec: Ok, I figured out the Duplicate ID naming problem mentioned above, but it involves altering a few defs inside init.py in the export folder.

Here is what I did, feel free to change or adjust as needed.

At the top of exportMesh we need to create a single name and use it consistently through out all export operations.


      # Generate a name for this object.
      if passedObjectName == None:
         name_to_use = obj.name
      else:
         name_to_use = passedObjectName    
   
      if name_to_use in self.exported_meshes:
         self.exported_meshes[name_to_use]['objects'] += [{'obj' : obj, 'mtx' : passedMatrix, <i>'name': name_to_use</i>}]
         return False
      else:
         self.exported_meshes[name_to_use] = {'meshes' : [], 'objects' : [{'obj' : obj, 'mtx' : passedMatrix, <i>'name': name_to_use</i>}]}

I also extended the dictionary (see underline above) to store this name_to_use so other export defs can find the correct name to operate upon and not have to recreate it blindly from the object given.

Further down in exportMesh we need to make sure we keep using the name_to_use.


# Store a list of exported meshes for later use to export shapes
               self.exported_meshes[name_to_use]['meshes'] += [{
                  'loop' : i,
                  'id' : translate_id(name_to_use),
                  'shapeIndex' : self.mesh_index,
                  'material' : mat}]

Now, when exportShape get’s called it can fetch the correct name_to_use.


   def exportShape(self, scene, object, data):
      obj = object['obj']
      mtx = object['mtx']
     <i> name_to_use = object['name']</i>
      
      self.openElement('shape', { 'id' : translate_id(data['id']) + '-shape_' + str(self.shape_index), 'type' : 'serialized'})
      self.parameter('string', 'filename', {'value' : self.srl_filename})
      self.parameter('integer', 'shapeIndex', {'value' : data['shapeIndex']})
      if mtx == None:
         self.exportWorldTrafo(obj.matrix_world)
      else:
         self.exportWorldTrafo(mtx)
      if data['material'] != None:
         if data['material'].mitsuba_emission.use_emission:
            <b><i>self.exportEmission(obj,name_to_use)</i></b>
         else:
            self.element('ref', {'name' : 'bsdf', 'id' : '%s-material' % translate_id(data['material'].name)})
      if obj.data.mitsuba_mesh.normals == 'facenormals':
         self.parameter('boolean', 'faceNormals', {'value' : 'true'})
      self.closeElement()
      
      self.shape_index += 1

And finally….exportEmission is passed the correct name for it’s material.


   def exportEmission(self, obj, passedName = None):
      if passedName == None:
         name_to_use = obj.name
      else:
         name_to_use = passedName
      lamp = obj.data.materials[0].mitsuba_emission
      if obj.data.users &gt; 1:
         MtsLog("Error: emitters cannot be instantiated!")
         return
      mult = lamp.intensity
      name = translate_id(<i>name_to_use</i>) + "-mesh_0"
      print("Using name [%s] for emission." % name)
      self.openElement('emitter', { 'id' : '%s-emission' % name, 'type' : 'area'})
      self.parameter('float', 'samplingWeight', {'value' : '%f' % lamp.samplingWeight})
      self.parameter('rgb', 'radiance', { 'value' : "%f %f %f"
            % (lamp.color.r*mult, lamp.color.g*mult, lamp.color.b*mult)})
      self.closeElement()

I am attaching the BLEND file for the test scene below. You can find the revised init.py, with all the above mentioned code changes, in the text window of the attached BLEND file. Try rendering the scene with the current Mitsuba exporter. Save the revised _init.py from the attached BLEND file over top the existing one in the export folder of the Mitsuba AddOn. Try rendering again and Mitsuba should render something like this.

Attachments

26_mitsuba_particle_test.blend (144 KB)

Still messing around with the Mitsuba exporter. It seems like the intial code for generating the Matrix for each particle object is only valid when the emitter is located at world origin.


                        # Create a matrix for this particle.
                        vecLoc = mathutils.Vector((loc[n][0], loc[n][1], loc[n][2]))
                        quat = mathutils.Quaternion((rot[n][0], rot[n][1], rot[n][2], rot[n][3]))
                        eulerMat = quat.to_euler().to_matrix()         
                        vecScale = mathutils.Matrix.Scale(scale[n], 4)
                        matTran = obj.matrix_world*mathutils.Matrix.Translation(vecLoc)
                        matScal = matTran*vecScale
                        particle_matrix = matScal*eulerMat.to_4x4()

So somehow we need to get the Matrix of the emitter itself factored into the above equation?

Once I moved the and rotated the emitter, my particles were no longer deployed along the vertices of my cube.

obj is available as the emitter object. I tried something like this but it did not seem to work.

 particle_matrix = obj.matrix_world * matScal*eulerMat.to_4x4()

embree doesn’t use GPU either… so not sure what your point is…
My bad Hollyenigma. I confused it with Optix

http://www.mitsuba-renderer.org/download.html the irawan.zip and scarf.zip
Thanks Bashi. I didn’t know he update the examples files.

Will someone please post a .blend that works with Irawan cloth?

Thanks.

@Atom, thanks for your reports. Working on them.

@Aurosutru, the exporter doesn’t work with Irawan cloth yet.

Atom - cool work man. About emitter transform problem, maybe you just have to apply emitter transformations to each particle?
eg.
particle_matrix_new = particle_matrix_basic * emitter_Transate * emitter_rotate * emitter_scale ??

Aurosutru, fjuhec - well it was working in previous version, but I guess it has been broken or something.

JoseConseco, some parameters of irawan are deprecated and have to be removed from exporter. Will test it later.

Just a small question: the depth of field does not work ?

it does/should work, but not with focus object. Enter distance manually for now.

Like bashi said, it works with focus distance and not with focus object.

I have been very busy this week and had to delay uploading the new version I am working on. I am rewriting the geometry exporter with code from LuxBlend. From the tests I had run with the new code, it solves all issues with wrong matrix operations and supports more types of particle objects.

New features added are partial export and ply meshes. I will upload it in the next days.

Thank Bashi.

will this mean that deformation modifiers/parenting relationships will be applied as expected? y’all have done really impressive work already, and as far as i can tell, that’s the only obstacle keeping me from using this for animations yet!

Hi!

Sorry for the long wait. I have had trouble with my laptop overheating this week. I wanted to write earlier and have been reading the forum often but also wanted to wait until I had uploaded a new version…

@ohsnapitsjoel, I believe modifiers/parenting issues are solved now and should apply as expected. Let me know if it’s still not working.

So, here it is. I have uploaded a new version of the plugin for you all to test.
Some already reported bugs are still pending and I may have introduced new ones. I am still learning blender and python while working on the exporter.

Small description of changes:
Starting to rewrite and split code in smaller files.
Solved some issues with transform matrix of dupli objects.
Adapting code from LuxBlend to export geometry.
Added features:

  • Partial export of meshes, avoids exporting already exported meshes when option is selected.
  • Binary PLY mesh file output.
  • Preliminary support for Blender Hair (ASCII hair files). Parent only, no children.

Let me know if you find any issues or bugs, I will do my best to solve all and add more features to the exporter.
I look forward to seeing more renders from you all!

Wow! Blender hair in Mitsuba - a great feat and feature.

At https://www.mitsuba-renderer.org/tracker/issues/83 Wenzel commented on developing hair for Blender.

Where can details of how to use the hair integration be found? Are the ASCII files saved, and if so, where? Hair isn’t rendering for me, so maybe a working .blend with the correct settings could be posted. Thanks.