Commits

Anonymous committed 7994d1f

binary ply working

  • Participants
  • Parent commits cce1279

Comments (0)

Files changed (1)

su2lux/LuxrenderExport.rb

 	  else
 	    ply_path=File.dirname(@export_file_path) + @os_separator + @instance_name.to_s + '_' + mat.display_name+'.ply'
 	  end
-    output_ply_geometry(ply_path, meshes, mirrored, mat_dir, rest, has_texture, matname, pointcount, polycount, default_mat, distorted_uv, (!has_texture and @exp_default_uvs==true) )
+    output_ply_geometry(ply_path, meshes, mirrored, mat_dir, rest, has_texture, matname, pointcount, polycount, default_mat, distorted_uv, (!has_texture and @exp_default_uvs==true), true )
     out.puts "Shape \"plymesh\"\n"
     out.puts "\n\"string filename\" [\"#{ply_path}\"]\n"    
 
     @exp_default_uvs=true
     no_texture_uvs=(!has_texture and @exp_default_uvs==true)
     if has_texture or no_texture_uvs
-      output_inline_uv(out, meshes, has_texture, matname, mat_dir, default_mat, distorted_uv)
+      output_inline_uv(out, meshes, has_texture, matname, mat_dir, default_mat, distorted_uv, (!has_texture and @exp_default_uvs==true))
     end
   end   
 
 end
 
 
-def output_ply_geometry(ply_path, meshes, mirrored, mat_dir, rest, has_texture, matname, pointcount, polycount, default_mat, distorted_uv, no_texture_uvs )
+def output_ply_geometry(ply_path, meshes, mirrored, mat_dir, rest, has_texture, matname, pointcount, polycount, default_mat, distorted_uv, no_texture_uvs, binary)
 	startindex = 0
   i=0
 
 	ply_file=File.new(ply_path,"w")
 	ply_file << "ply\n"
-	ply_file << "format ascii 1.0\n"
-	ply_file << "comment created by SU2Lux " << Time.new << "\n"
+  if ( binary == true)
+	  ply_file << "format binary_little_endian 1.0\n"
+  else
+    ply_file << "format ascii 1.0\n"
+	end
+  ply_file << "comment created by SU2Lux " << Time.new << "\n"
   ply_file << "element vertex #{pointcount}\n"
 	ply_file << "property float x\n"
 	ply_file << "property float y\n"
 				pos = mesh.point_at(p).to_a
 				norm = mesh.normal_at(p)
 				norm.reverse! if mat_dir_tmp==false
-				ply_file << "#{"%.6f" %(pos[0]*@scale)} #{"%.6f" %(pos[1]*@scale)} #{"%.6f" %(pos[2]*@scale)} #{"%.4f" %(norm.x)} #{"%.4f" %(norm.y)} #{"%.4f" %(norm.z)} #{"%.4f" %(uv.x)} #{"%.4f" %(-uv.y+1)}\n"		
-			end
+        if ( binary != true)
+				  ply_file << "#{"%.6f" %(pos[0]*@scale)} #{"%.6f" %(pos[1]*@scale)} #{"%.6f" %(pos[2]*@scale)} #{"%.4f" %(norm.x)} #{"%.4f" %(norm.y)} #{"%.4f" %(norm.z)} #{"%.4f" %(uv.x)} #{"%.4f" %(-uv.y+1)}\n"		
+			  else
+          ply_file << [pos[0]*@scale, pos[1]*@scale, pos[2]*@scale, norm.x, norm.y, norm.z, uv.x, (-uv.y+1)].pack('e*.')
+        end
+      end
 		end
 
 	for mesh in meshes
 			v3 = (poly[2]>=0?poly[2]:-poly[2])+startindex
 			if !mirrored_tmp
 				if mat_dir_tmp==true
-					ply_file << "3 #{v1-1} #{v2-1} #{v3-1}\n"
+          out_a = [ 3, v1-1, v2-1, v3-1 ]
 				else
-					ply_file << "3 #{v1-1} #{v3-1} #{v2-1}\n"
+          out_a = [ 3, v1-1, v3-1, v2-1 ]
 				end
 			else
 				if mat_dir_tmp==true
-					ply_file << "3 #{v2-1} #{v1-1} #{v3-1}\n"
+          out_a = [ 3, v2-1, v1-1, v3-1 ]
 				else
-					ply_file << "3 #{v2-1} #{v3-1} #{v1-1}\n"
+          out_a = [ 3, v2-1, v3-1, v1-1 ]
 				end
 			end		
-		
+    if ( binary == true)
+      ply_file << out_a.pack('CVVV')
+    else
+	    ply_file << "3 #{out_a[1]} #{out_a[2]} #{out_a[3]} \n"
+    end 	
 		@count_tri = @count_tri + 1
 	  end
 	  startindex = startindex + mesh.count_points
 	out.puts ']'
 end
 
-def output_inline_uv(out, meshes, has_texture, matname, mat_dir, default_mat, distorted_uv)
+def output_inline_uv(out, meshes, has_texture, matname, mat_dir, default_mat, distorted_uv, no_texture_uvs)
   i = 0
   out.puts '"float uv" ['
   for mesh in meshes