Python Reference Guide
 
Loading...
Searching...
No Matches
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#
10from pyfbsdk import FBMesh, FBModelCube, FBVector3d, FBModelTransformationType, FBModelShadingMode
11
12# Create the custom mesh
13lMesh = FBMesh("myGeom")
14
15# Alway call GeometryBegin() / GeometryEnd() in pair when editting geometry.
16lMesh.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.
21lMesh.VertexInit(4, False, False, True)
22
23lMesh.VertexAdd(0, 100, 0) # vertex 0
24lMesh.VertexAdd(100,100, 0) # vertex 1
25lMesh.VertexAdd(100, 0, 0) # vertex 2
26lMesh.VertexAdd(0, 0, 0) # vertex 3
27
28lMesh.VertexColorSet(1, 0, 0, 1, 0)
29lMesh.VertexColorSet(0, 1, 0, 1, 1)
30lMesh.VertexColorSet(0, 0, 1, 1, 2)
31lMesh.VertexColorSet(1, 1, 0, 1, 3)
32
33# Add a Polygon
34lMesh.PolygonBegin()
35lMesh.PolygonVertexAdd(0) # add polygon vertex 0
36lMesh.PolygonVertexAdd(1) # add polygon vertex 1
37lMesh.PolygonVertexAdd(2) # add polygon vertex 2
38lMesh.PolygonVertexAdd(3) # add polygon vertex 3
39# Polygon add End
40lMesh.PolygonEnd()
41
42# Compute mesh vertex normal with Counter Clock-Wise order
43lMesh.ComputeVertexNormals(True)
44
45# Alway call GeometryBegin() / GeometryEnd() in pair when editting geometry.
46lMesh.GeometryEnd()
47
48# And we use Geometry Instancing feature to share this simple plane among multiple models.
49for 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.
69del( lModel, lMesh, FBMesh, FBModelCube, FBVector3d, FBModelTransformationType, FBModelShadingMode )
Mesh class.
Definition: pyfbsdk_generated.h:10906
Cube model class.
Definition: pyfbsdk_generated.h:11394