Export Mesh Vertex Colour Data
-
- Posts: 8
- Joined: Mon Mar 10, 2014 3:33 pm
Export Mesh Vertex Colour Data
Hello,
I have an issue with exporting mesh colour data out of Realflow, in order to multi-colour 3D print an RF mesh. In the file that I have, I've fused together 3 individual particle systems in one ParticleMeshLegacy and got the 3 different particle system colours on the mesh (attached screenshot). The problem that I have with it, is how to get the mesh vertex colour data out of Realflow.
I was therefore wondering:
1. If there is any format to save the mesh at that allows for vertex colour data to be visible i.e. baked on the mesh. I am aware that I can import the mesh in other software like Maya and Houdini and use the blind data editors there, but the problem with this is that it is only for rendering and visualization purposes. VRML97, X3D and PLY are some formats that meshes can be saved at with their colours, as per the info here: https://www.shapeways.com/tutorials/exp ... r_printing
2. If there isn't a format like that, is there a way to export mesh vertex colour (I'm aware that I can export fluid weight data through Python) RGB values as a text file?
Thanks
I have an issue with exporting mesh colour data out of Realflow, in order to multi-colour 3D print an RF mesh. In the file that I have, I've fused together 3 individual particle systems in one ParticleMeshLegacy and got the 3 different particle system colours on the mesh (attached screenshot). The problem that I have with it, is how to get the mesh vertex colour data out of Realflow.
I was therefore wondering:
1. If there is any format to save the mesh at that allows for vertex colour data to be visible i.e. baked on the mesh. I am aware that I can import the mesh in other software like Maya and Houdini and use the blind data editors there, but the problem with this is that it is only for rendering and visualization purposes. VRML97, X3D and PLY are some formats that meshes can be saved at with their colours, as per the info here: https://www.shapeways.com/tutorials/exp ... r_printing
2. If there isn't a format like that, is there a way to export mesh vertex colour (I'm aware that I can export fluid weight data through Python) RGB values as a text file?
Thanks
You do not have the required permissions to view the files attached to this post.
Re: Export Mesh Vertex Colour Data
Hi Kostas,
We believe the best approach would be the second one that you suggest.
The following script interpolates the emitter colors according to their vertex weight and saves the list as a text file:
There is one important thing to consider. The emitter weight data remains in memory only right after building the mesh in RealFlow. This means that you cannot iterate loading meshes from disk. This script should be executed right after the mesh has been built. That's something easy to achieve by adding a mesh.build() sentence at the beginning of it.
In that example we are using HSV values to perform the colour interpolation. Feel free to replace the call to interpolateColorsHSV with interpolateColorsRGB if you prefer colors being interpolated in the RGB colorspace.
It should be easy from that point to tweak the script to generate your own PLY ASCII files.
Hope it helps.
We believe the best approach would be the second one that you suggest.
The following script interpolates the emitter colors according to their vertex weight and saves the list as a text file:
Code: Select all
from colorsys import *
# interpolate using HSV
def interpolateColorsHSV( rgbs, rates ):
tmpR = [ 0.0, 0.0, 0.0 ]
for i in range( len(rgbs) ):
c = rgbs[ i ]
rate = rates[ i ]
tmp0 = rgb_to_hsv( *c )
for i in range( 3 ):
tmpR[ i ] += tmp0[ i ] * rate
return hsv_to_rgb( *tmpR )
# interpolate using RGB
def interpolateColorsRGB( rgbs, rates ):
tmpR = [ 0.0, 0.0, 0.0 ]
for i in range( len(rgbs) ):
c = rgbs[ i ]
rate = rates[ i ]
for i in range( 3 ):
tmpR[ i ] += c[ i ] * rate
return tmpR
# Write legacy mesh vertex weights to text file
def writeVertexWeights( mesh, filename ):
f = open( filename, 'w' )
vertices = mesh.getGeometry()[ 0 ]
for i in range(len( vertices )):
weights = mesh.getFluidsWeightAtVertex( i )
colors = []
rates = []
for pair in weights:
# Get color of the emitter
c = eval( pair[ 0 ] ).getParameter( "Color" )
c = ( c.getX() / 255.0, c.getY() / 255.0, c.getZ() / 255.0 )
colors.append( c )
rates.append( pair[ 1 ] )
# interpolate the colors
result = interpolateColorsHSV( colors, rates )
# write to file
string = "%d %f %f %f\n" % ( i, result[ 0 ], result[ 1 ], result[ 2 ] )
f.write( string )
f.close()
#example
mesh = ParticleMeshLegacy01
filename = "/tmp/vertexcolor.txt"
writeVertexWeights( mesh, filename )
In that example we are using HSV values to perform the colour interpolation. Feel free to replace the call to interpolateColorsHSV with interpolateColorsRGB if you prefer colors being interpolated in the RGB colorspace.
It should be easy from that point to tweak the script to generate your own PLY ASCII files.
Hope it helps.
Last edited by Alex on Mon Apr 20, 2015 1:47 pm, edited 1 time in total.
Alex Ribao
RealFlow Team
Next Limit Technologies
RealFlow Team
Next Limit Technologies
-
- Posts: 8
- Joined: Mon Mar 10, 2014 3:33 pm
Re: Export Mesh Vertex Colour Data
Hi Alex,
This is brilliant, thank you very much.
There seems to be one issue, however, which is that when I run the script I get the following error (the script itself only has 46 lines...):
WARNING: Script error: "global name 'rgbs' is not defined" at line number 47.
This is your part of the code that I used:
I have also attached a screenshot of this.
Many thanks again.
This is brilliant, thank you very much.
There seems to be one issue, however, which is that when I run the script I get the following error (the script itself only has 46 lines...):
WARNING: Script error: "global name 'rgbs' is not defined" at line number 47.
This is your part of the code that I used:
Code: Select all
from colorsys import *
# interpolate using RGB
def interpolateColorsRGB( rgb, rates ):
tmpR = [ 0.0, 0.0, 0.0 ]
for i in range( len(rgbs) ):
c = rgbs[ i ]
rate = rates[ i ]
for i in range( 3 ):
tmpR[ i ] += c[ i ] * rate
return tmpR
# Write legacy mesh vertex weights to text file
def writeVertexWeights( mesh, filename ):
f = open( filename, 'w' )
vertices = mesh.getGeometry()[ 0 ]
for i in range(len( vertices )):
weights = mesh.getFluidsWeightAtVertex( i )
colors = []
rates = []
for pair in weights:
# Get color of the emitter
c = eval( pair[ 0 ] ).getParameter( "Color" )
c = ( c.getX() / 255.0, c.getY() / 255.0, c.getZ() / 255.0 )
colors.append( c )
rates.append( pair[ 1 ] )
# interpolate the colors
result = interpolateColorsRGB( colors, rates )
# write to file
string = "%d %f %f %f\n" % ( i, result[ 0 ], result[ 1 ], result[ 2 ] )
f.write( string )
f.close()
#example
mesh = ParticleMeshLegacy01
filename = "/Users/Kostas/Desktop/vertexcolor.txt"
writeVertexWeights( mesh, filename )
Many thanks again.
You do not have the required permissions to view the files attached to this post.
Re: Export Mesh Vertex Colour Data
Sorry, there seems to be a typo at the definition of the interpolateColorsRGB function.
Replace it with: Note the missing s Let me know if there is anything else missing.
Replace it with: Note the missing s
Code: Select all
def interpolateColorsRGB( rgbs, rates ):
Alex Ribao
RealFlow Team
Next Limit Technologies
RealFlow Team
Next Limit Technologies
-
- Posts: 8
- Joined: Mon Mar 10, 2014 3:33 pm
Re: Export Mesh Vertex Colour Data
This works great now.
Thank you very much.
Thank you very much.
-
- Posts: 8
- Joined: Mon Mar 10, 2014 3:33 pm
Re: Export Mesh Vertex Colour Data
Hi Alex, I just had a go at the script with 3 particle emitters instead of 2 and I get the following error:
>[21/April/2015 19:48:57] - WARNING: Script syntax error at line number 0.
I am attaching a screenshot of this as well. Any help would be great.
>[21/April/2015 19:48:57] - WARNING: Script syntax error at line number 0.
I am attaching a screenshot of this as well. Any help would be great.
You do not have the required permissions to view the files attached to this post.
Re: Export Mesh Vertex Colour Data
Hi Kostas,
a syntax error on line 0 might sound weird, but it is most likely related to the line which calls to the Python eval function. About line #12.
Maybe you can replace the following line:
With:
a syntax error on line 0 might sound weird, but it is most likely related to the line which calls to the Python eval function. About line #12.
Maybe you can replace the following line:
Code: Select all
c = eval( pair[0] ).getParameter( "Color" )
Code: Select all
emitter = scene.get_PB_Emitter( pair[0] )
c = emitter.getParameter( "Color" )
Alex Ribao
RealFlow Team
Next Limit Technologies
RealFlow Team
Next Limit Technologies
-
- Posts: 8
- Joined: Mon Mar 10, 2014 3:33 pm
Re: Export Mesh Vertex Colour Data
Works now. Thank you very much.