Samples/Geometry/GeometryInstancing.py

Samples/Geometry/GeometryInstancing.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # This script is to demonstrate the ssimple geometry creation and gemoetry instancing feature.
7 #
8 # Topic: FBMesh, FBVector3d, FBModelTransformationType, FBModelShadingMode
9 #
10 from pyfbsdk import FBMesh, FBModelCube, FBVector3d, FBModelTransformationType, FBModelShadingMode
11 
12 # Create the custom mesh
13 lMesh = FBMesh("myGeom")
14 
15 # Alway call GeometryBegin() / GeometryEnd() in pair when editting geometry.
16 lMesh.GeometryBegin()
17 
18 # Call VertexInit() to resize or reserve vertex/normal array.
19 # pResize = true, work with known vertex count and VertexSet() function.
20 # pResize = false, work with dynamical vertex count and VertexAdd() function.
21 lMesh.VertexInit(4, False, False)
22 
23 lMesh.VertexAdd(0, 100, 0) # vertex 0
24 lMesh.VertexAdd(100,100, 0) # vertex 1
25 lMesh.VertexAdd(100, 0, 0) # vertex 2
26 lMesh.VertexAdd(0, 0, 0) # vertex 3
27 
28 # Add a Polygon
29 lMesh.PolygonBegin()
30 lMesh.PolygonVertexAdd(0) # add polygon vertex 0
31 lMesh.PolygonVertexAdd(1) # add polygon vertex 1
32 lMesh.PolygonVertexAdd(2) # add polygon vertex 2
33 lMesh.PolygonVertexAdd(3) # add polygon vertex 3
34 # Polygon add End
35 lMesh.PolygonEnd()
36 
37 # Compute mesh vertex normal with Counter Clock-Wise order
38 lMesh.ComputeVertexNormals(True)
39 
40 # Alway call GeometryBegin() / GeometryEnd() in pair when editting geometry.
41 lMesh.GeometryEnd()
42 
43 # And we use Geometry Instancing feature to share this simple plane among multiple models.
44 for lIndex in range(1, 10):
45  #create a cube but we will replace its geometry
46  lModel = FBModelCube("myModel")
47 
48  # Replace the geometry instance
49  lModel.Geometry = lMesh
50 
51  lModel.SetVector( FBVector3d(120*lIndex - 600, 50, 50 ) )
52 
53  # Let's use a different shading mode.
54  if (lIndex > 5):
55  lModel.ShadingMode = FBModelShadingMode.kFBModelShadingWire
56 
57  # The object must be set visible to be present in the system.
58  lModel.Visible = True
59  lModel.Show = True
60 
61 
62 # Cleanup.
63 del( lModel, lMesh, FBMesh, FBModelCube, FBVector3d, FBModelTransformationType, FBModelShadingMode )