Import 3D file into virtual world or node


node = vrimport(source)
node = vrimport(parent,source)
node = vrimport(___,format)
[node,virtualWorld] = vrimport(___)


node = vrimport(source) creates an empty VRML virtual world and imports the source 3D file into it. The format of the 3D file is detected automatically. You can import these file formats:

  • DAE (Collada digital asset exchange)

  • SDF (simulation description format)

  • STL (STereoLithography)

  • URDF (unified robot description file)


To import Physical Modeling XML files, use the stl2vrml function instead of vrimport.

The function returns a handle to the newly created node.

node = vrimport(parent,source) specifies the existing virtual world or node to import the 3D source file into.

node = vrimport(___,format) explicitly specifies the file format of the 3D source file (for example, 'urdf'). If the format of the source file does not match the format specified in the format argument, the function returns an error.


[node,virtualWorld] = vrimport(___) returns the handle of the new node and the handle of the virtual world that contains that node.


collapse all

This example imports an STL file rover_1.stl, a model of a simple wheeled robot. The example also shows how to add visual appearance and material nodes to the imported model in the virtual world.

Create a virtual world with the imported model.

[n,w] = vrimport(which('Rover_1.stl'));

View the virtual world with the imported shape.


Scale the imported model from mm to dm to see it in the view.

n.scale = [0.01 0.01 0.01]

Rotate the rover around the x-axis.

w.Rover_Transform.rotation = [1 0 0 -pi/2]

Explore the virtual world structure.


STL imported shapes have no visual properties. Add an Appearance and a Materials node to the shape. The Appearance node is created in the appearance field of the Shape. The Material node is create in the material field of the Appearance node.

app = vrnode(w.Rover_Shape,'appearance','Rover_App','Appearance');
mat = vrnode(w.Rover_App,'material','Rover_Mat','Material');

Set the diffuse color to a shade of blue.

w.Rover_Mat.diffuseColor = [0 0.5 1]

Save the virtual world.


This example imports a .dae format file into a virtual world.

Import the fox.dae file to a node in a virtual world.

[n,w] = vrimport(which('fox.dae'))
n = 

	vrnode object: 1-by-1

	COLLADA_fox_Transform_0001 (Transform) []

w = 

	vrworld object: 1-by-1

	 (No Virtual Reality 3D File Associated)

View the imported visual representation.


Save the virtual world.


Input Arguments

collapse all

3D source file path, specified as a character vector. The 3D file can be in DAE, SDF, STL, or URDF format.

File format of source 3D file, specified as a character vector. Use this argument to specify explicitly the required format for the source 3D file.

Virtual world or node to import 3D source file into, specified as a virtual world handle or node handle.

  • If the parent is a virtual world, the imported node is placed at the ROOT node of the parent.

  • If the parent is a node in a virtual world, the imported node is placed in the children field of the node.

Output Arguments

collapse all

New node, returned as a vrnode object.

Virtual world containing new node, returned as a vrworld object.

Introduced in R2016b

Was this topic helpful?