createMesh
Description
Examples
Build Actor from Mesh Data and Apply Texture
This example shows how to build an actor from mesh data using the createMesh
function and how to use the texture property of the sim3d.Actor
object. First, you create a world scene and an actor object. Next, you build the appearance of the actor from a mesh and apply a texture. Then, you add the actor to the world, transform the actor, and set a view in the scene. Finally, you view the actor in the Simulation 3D Viewer window.
A mesh is a 3D build of a model consisting of polygons and is defined by vertices, normals, and faces. If you require detailed control over the geometry of an actor, create an actor from a mesh. This example uses sphere geometry for the mesh data to build the actor.
Build Actor from Mesh in World
Create a world scene.
world = sim3d.World();
Instantiate an actor object named sphere
. Use the sim3d.utils.Geometry
function to create a sphere. Obtain the sphere vertices V
, normals N
, faces F
, texture coordinates T
, and vertex colors C
.
ActObj = sim3d.Actor('ActorName', 'sphere'); [V, N, F, T, C] = sim3d.utils.Geometry.sphere([0.5 0.5 0.5]);
Create a mesh using the actor object and sphere geometry. Set a texture provided by the image file. Add the actor object to the world.
createMesh(ActObj, V, N, F, T, C);
ActObj.Texture = fullfile(pwd,"image.png");
add(world,ActObj);
Set Actor Transformation
Use the actor object translation, rotation, and scale properties to orient the actor relative to the world origin.
ActObj.Translation = [0 0 0]; ActObj.Rotation = [0, 0, 0]; ActObj.Scale = [1, 1, 1];
Set Viewer Window Point of View
If you do not create a viewport, then the point of view is set to 0, 0 ,0, and you can use the arrow keys and pointer to navigate in the Simulation 3D Viewer window.
For this example, use the createViewport
function to create a viewport with a single field, Main
, that contains a sim3d.sensors.MainCamera
object.
viewport = createViewport(world); viewport.Translation = [-3, 0, 0];
Run Animation
Run a simulation set for 10 seconds with a sample time of 0.02 seconds.
run(world,0.02,10)
Delete World
Delete the world object.
delete(world)
Input Arguments
vertices
— Vertex positions
real positive (N,3) vector
Vertex positions, specified as a real positive (N,3) vector. This vector includes all vertex positions to be used for the mesh geometry.
Example: vertices = reshape(1: 6, 2, 3)
Data Types: double
actor
— Actor class where mesh is being created
sim3d.Actor
object
Actor class where mesh is created, specified as a sim3d.Actor
object.
faces
— Faces of actor shape
real positive (N,3) vector
Faces of actor shape, specified as a real positive (N,3) vector. This vector defines how each triangle of the mesh is drawn. Length must be a multiple of 3.
Example: faces = [1: 3; 4 : 6]
Data Types: double
normals
— Normal vectors
real positive (N,3) vector
Normal vectors for each vertex, specified as a real positive (N,3) vector.
This vector must be the same length as vertices
vector.
Example: normals = reshape(7: 12, 2, 3)
Data Types: double
vcolor
— Vertex colors
real positive (N,3) vector
Vertex colors, specified a real positive (N,3) vector. This vector must be
the same length as vertices
vector.
Example: vertexcolor = reshape(25 : 33, 3, 3)
Data Types: double
tcoords
— Texture coordinates
real positive (N,2) vector
Texture coordinates of each vertex, specified a real positive (N,2) vector. This must be the same length as vertices
array.
Example: texturecoord = reshape(21 : 24, 2, 2)
Data Types: double
Version History
Introduced in R2022b
See Also
copy
| findBy
| propagate
| gather
| takeSnapshot
| restoreSnapshot
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)