# WRL and VRML to Matplotlib/Numpy

I would like to import (or parse ??) a WRL/VRML file format in python in order to work the data with Matplotlib. Is there any way of converting this file format into plottable numpy arrays ?

I attached a photo a WRL file visualized with the FreeWRL viewer

• I am not really sure if this question is more suitable for stackoverflow.com
May 4, 2014 at 3:25
• I'd try looking at PyVRML or ScientificPython to start. May 4, 2014 at 4:50
• I stumbled on it while searching but I couldnt find a decent documentation not to mention that the Github repository links are broken !
May 4, 2014 at 10:56

{Assuming you still need the code} Let A1.wrl is your wrl file.

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import re
holder = []
with open("A1.wrl", "rb") as vrml:
for lines in vrml:
a = re.findall("[-0-9]{1,3}.[0-9]{6}", lines)
if len(a) == 3:
holder.append(map(float, a))

holder_array = np.array(holder) #if you want numpy array

#3D Plotting
x,y,z = zip(*holder)
fig = plt.figure()
ax = Axes3D(fig)
ax.plot(x,y,z)
plt.show()


My A.wrl: http://pastebin.com/PeVXbR5C

File generate:

• what version of wrl files are you using ? I tested it but no regular expression are found, and the numpy array are empty.
• your A.wrl file works, but I think your python script doesnt work with my file B.wrl (pastebin.com/HCVjqETa)
• Actually i am very familiarbwith re module, nonethless i ll take a look at yourr wrl file to see how you did it. For this, you have also my up vote also.