Samples/Geometry/VertexColor.py

Samples/Geometry/VertexColor.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 simple geometry creation and vertex color display feature.
7 #
8 # Topic: FBMesh, FBVector3d, 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, True)
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 lMesh.VertexColorSet(1, 0, 0, 1, 0)
29 lMesh.VertexColorSet(0, 1, 0, 1, 1)
30 lMesh.VertexColorSet(0, 0, 1, 1, 2)
31 lMesh.VertexColorSet(1, 1, 0, 1, 3)
32 
33 # Add a Polygon
34 lMesh.PolygonBegin()
35 lMesh.PolygonVertexAdd(0) # add polygon vertex 0
36 lMesh.PolygonVertexAdd(1) # add polygon vertex 1
37 lMesh.PolygonVertexAdd(2) # add polygon vertex 2
38 lMesh.PolygonVertexAdd(3) # add polygon vertex 3
39 # Polygon add End
40 lMesh.PolygonEnd()
41 
42 # Compute mesh vertex normal with Counter Clock-Wise order
43 lMesh.ComputeVertexNormals(True)
44 
45 # Alway call GeometryBegin() / GeometryEnd() in pair when editting geometry.
46 lMesh.GeometryEnd()
47 
48 # And we use Geometry Instancing feature to share this simple plane among multiple models.
49 for lIndex in range(1, 10):
50  #create a cube but we will replace its geometry
51  lModel = FBModelCube("myModel")
52 
53  # Replace the geometry instance
54  lModel.Geometry = lMesh
55 
56  lModel.SetVector( FBVector3d(120*lIndex - 600, 50, 50 ) )
57 
58  # Let's use a different shading mode.
59  if (lIndex > 5):
60  lModel.ShadingMode = FBModelShadingMode.kFBModelShadingWire
61  else:
62  lModel.ShadingMode = FBModelShadingMode.kFBModelShadingFlat
63 
64  # The object must be set visible to be present in the system.
65  lModel.Visible = True
66  lModel.Show = True
67 
68 # Cleanup.
69 del( lModel, lMesh, FBMesh, FBModelCube, FBVector3d, FBModelTransformationType, FBModelShadingMode )