Package pyffi :: Package formats :: Package cgf :: Class CgfFormat :: Class MeshChunk
[hide private]
[frames] | no frames]

Class MeshChunk

source code

                  object --+                            
                           |                            
      utils.graph.DetailNode --+                        
                               |                        
          utils.graph.GlobalNode --+                    
                                   |                    
object_models.xml.struct_.StructBase --+                
                                       |                
                        CgfFormat._Chunk --+            
                                           |            
                             CgfFormat.Chunk --+        
                                               |        
                   CgfFormat.AbstractObjectChunk --+    
                                                   |    
                                CgfFormat._MeshChunk --+
                                                       |
                                                      CgfFormat.MeshChunk
Known Subclasses:

Nested Classes [hide private]

Inherited from object_models.xml.struct_.StructBase: __metaclass__

Instance Methods [hide private]
 
apply_scale(self, scale)
Apply scale factor on data.
source code
 
get_vertices(self)
Generator for all vertices.
source code
 
get_normals(self)
Generator for all normals.
source code
 
get_colors(self)
Generator for all vertex colors.
source code
 
get_num_triangles(self)
Get number of triangles.
source code
 
get_triangles(self)
Generator for all triangles.
source code
 
get_material_indices(self)
Generator for all materials (per triangle).
source code
 
get_uvs(self)
Generator for all uv coordinates.
source code
 
get_uv_triangles(self)
Generator for all uv triangles.
source code
 
set_vertices_normals(self, vertices, normals)
B{Deprecated.
source code
 
set_geometry(self, verticeslist=None, normalslist=None, triangleslist=None, matlist=None, uvslist=None, colorslist=None)
Set geometry data.
source code
 
update_tangent_space(self)
Recalculate tangent space data.
source code

Inherited from Chunk: tree

Inherited from object_models.xml.struct_.StructBase: __init__, __str__, deepcopy, fix_links, get_attribute, get_basic_attribute, get_detail_child_names, get_detail_child_nodes, get_global_child_nodes, get_global_display, get_hash, get_links, get_refs, get_size, get_strings, get_template_attribute, read, replace_global_node, set_attribute, set_basic_attribute, set_template_attribute, write

Inherited from utils.graph.GlobalNode: get_global_child_edge_types, get_global_iterator

Inherited from utils.graph.DetailNode: get_detail_child_edge_types, get_detail_display, get_detail_iterator

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Methods [hide private]

Inherited from object_models.xml.struct_.StructBase: get_games, get_versions

Class Variables [hide private]
  _attribute_list = [<pyffi.object_models.xml.StructAttribute ob...

Inherited from _MeshChunk (private): _attrs, _games, _has_links, _has_refs, _names

Inherited from AbstractObjectChunk (private): _is_template

Inherited from object_models.xml.struct_.StructBase: arg

Properties [hide private]

Inherited from _MeshChunk: bone_map_data, colors_2_data, colors_data, face_map_data, faces, flags_1, flags_2, has_vertex_colors, has_vertex_weights, in_world_space, indices_data, material, max_bound, mesh_subsets, min_bound, normals_data, num_faces, num_indices, num_mesh_subsets, num_uvs, num_vertices, physics_data, reserved_1, reserved_2, reserved_3, reserved_data, sh_coeffs_data, shape_deformation_data, tangents_data, uv_faces, uvs, uvs_data, vert_anim, vert_mats_data, vertex_colors, vertex_weights, vertices, vertices_data

Inherited from object: __class__

Method Details [hide private]

apply_scale(self, scale)

source code 
Apply scale factor on data.
Overrides: Chunk.apply_scale

set_vertices_normals(self, vertices, normals)

source code 

B{Deprecated. Use L{set_geometry} instead.} Set vertices and normals. This used to be the first function to call when setting mesh geometry data.

Returns list of chunks that have been added.

set_geometry(self, verticeslist=None, normalslist=None, triangleslist=None, matlist=None, uvslist=None, colorslist=None)

source code 

Set geometry data.

>>> from pyffi.formats.cgf import CgfFormat
>>> chunk = CgfFormat.MeshChunk()
>>> vertices1 = [(0,0,0),(0,1,0),(1,0,0),(1,1,0)]
>>> vertices2 = [(0,0,1),(0,1,1),(1,0,1),(1,1,1)]
>>> normals1 = [(0,0,-1),(0,0,-1),(0,0,-1),(0,0,-1)]
>>> normals2 = [(0,0,1),(0,0,1),(0,0,1),(0,0,1)]
>>> triangles1 = [(0,1,2),(2,1,3)]
>>> triangles2 = [(0,1,2),(2,1,3)]
>>> uvs1 = [(0,0),(0,1),(1,0),(1,1)]
>>> uvs2 = [(0,0),(0,1),(1,0),(1,1)]
>>> colors1 = [(0,1,2,3),(4,5,6,7),(8,9,10,11),(12,13,14,15)]
>>> colors_2 = [(50,51,52,53),(54,55,56,57),(58,59,60,61),(62,63,64,65)]
>>> chunk.set_geometry(verticeslist = [vertices1, vertices2],
...                   normalslist = [normals1, normals2],
...                   triangleslist = [triangles1, triangles2],
...                   uvslist = [uvs1, uvs2],
...                   matlist = [2,5],
...                   colorslist = [colors1, colors_2])
>>> print(chunk) # doctest: +ELLIPSIS +REPORT_UDIFF
<class 'pyffi.formats.cgf.MeshChunk'> instance at ...
* has_vertex_weights : False
* has_vertex_colors : True
* in_world_space : False
* reserved_1 : 0
* reserved_2 : 0
* flags_1 : 0
* flags_2 : 0
* num_vertices : 8
* num_indices : 12
* num_uvs : 8
* num_faces : 4
* material : None
* num_mesh_subsets : 2
* mesh_subsets : <class 'pyffi.formats.cgf.MeshSubsetsChunk'> instance at ...
* vert_anim : None
* vertices :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: <class 'pyffi.formats.cgf.Vertex'> instance at ...
    * p : [  0.000  0.000  0.000 ]
    * n : [  0.000  0.000 -1.000 ]
    1: <class 'pyffi.formats.cgf.Vertex'> instance at ...
    * p : [  0.000  1.000  0.000 ]
    * n : [  0.000  0.000 -1.000 ]
    2: <class 'pyffi.formats.cgf.Vertex'> instance at ...
    * p : [  1.000  0.000  0.000 ]
    * n : [  0.000  0.000 -1.000 ]
    3: <class 'pyffi.formats.cgf.Vertex'> instance at ...
    * p : [  1.000  1.000  0.000 ]
    * n : [  0.000  0.000 -1.000 ]
    4: <class 'pyffi.formats.cgf.Vertex'> instance at ...
    * p : [  0.000  0.000  1.000 ]
    * n : [  0.000  0.000  1.000 ]
    5: <class 'pyffi.formats.cgf.Vertex'> instance at ...
    * p : [  0.000  1.000  1.000 ]
    * n : [  0.000  0.000  1.000 ]
    6: <class 'pyffi.formats.cgf.Vertex'> instance at ...
    * p : [  1.000  0.000  1.000 ]
    * n : [  0.000  0.000  1.000 ]
    7: <class 'pyffi.formats.cgf.Vertex'> instance at ...
    * p : [  1.000  1.000  1.000 ]
    * n : [  0.000  0.000  1.000 ]
* faces :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: <class 'pyffi.formats.cgf.Face'> instance at ...
    * v_0 : 0
    * v_1 : 1
    * v_2 : 2
    * material : 2
    * sm_group : 1
    1: <class 'pyffi.formats.cgf.Face'> instance at ...
    * v_0 : 2
    * v_1 : 1
    * v_2 : 3
    * material : 2
    * sm_group : 1
    2: <class 'pyffi.formats.cgf.Face'> instance at ...
    * v_0 : 4
    * v_1 : 5
    * v_2 : 6
    * material : 5
    * sm_group : 1
    3: <class 'pyffi.formats.cgf.Face'> instance at ...
    * v_0 : 6
    * v_1 : 5
    * v_2 : 7
    * material : 5
    * sm_group : 1
* uvs :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 0.0
    * v : 0.0
    1: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 0.0
    * v : 1.0
    2: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 1.0
    * v : 0.0
    3: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 1.0
    * v : 1.0
    4: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 0.0
    * v : 0.0
    5: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 0.0
    * v : 1.0
    6: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 1.0
    * v : 0.0
    7: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 1.0
    * v : 1.0
* uv_faces :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: <class 'pyffi.formats.cgf.UVFace'> instance at ...
    * t_0 : 0
    * t_1 : 1
    * t_2 : 2
    1: <class 'pyffi.formats.cgf.UVFace'> instance at ...
    * t_0 : 2
    * t_1 : 1
    * t_2 : 3
    2: <class 'pyffi.formats.cgf.UVFace'> instance at ...
    * t_0 : 4
    * t_1 : 5
    * t_2 : 6
    3: <class 'pyffi.formats.cgf.UVFace'> instance at ...
    * t_0 : 6
    * t_1 : 5
    * t_2 : 7
* vertex_colors :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: <class 'pyffi.formats.cgf.IRGB'> instance at ...
    * r : 0
    * g : 1
    * b : 2
    1: <class 'pyffi.formats.cgf.IRGB'> instance at ...
    * r : 4
    * g : 5
    * b : 6
    2: <class 'pyffi.formats.cgf.IRGB'> instance at ...
    * r : 8
    * g : 9
    * b : 10
    3: <class 'pyffi.formats.cgf.IRGB'> instance at ...
    * r : 12
    * g : 13
    * b : 14
    4: <class 'pyffi.formats.cgf.IRGB'> instance at ...
    * r : 50
    * g : 51
    * b : 52
    5: <class 'pyffi.formats.cgf.IRGB'> instance at ...
    * r : 54
    * g : 55
    * b : 56
    6: <class 'pyffi.formats.cgf.IRGB'> instance at ...
    * r : 58
    * g : 59
    * b : 60
    7: <class 'pyffi.formats.cgf.IRGB'> instance at ...
    * r : 62
    * g : 63
    * b : 64
* vertices_data : <class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* normals_data : <class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* uvs_data : <class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* colors_data : <class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* colors_2_data : None
* indices_data : <class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* tangents_data : <class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* sh_coeffs_data : None
* shape_deformation_data : None
* bone_map_data : None
* face_map_data : None
* vert_mats_data : None
* reserved_data :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: None
    1: None
    2: None
    3: None
* physics_data :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: None
    1: None
    2: None
    3: None
* min_bound : [  0.000  0.000  0.000 ]
* max_bound : [  1.000  1.000  1.000 ]
* reserved_3 :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: 0
    1: 0
    2: 0
    3: 0
    4: 0
    5: 0
    6: 0
    7: 0
    8: 0
    9: 0
    10: 0
    11: 0
    12: 0
    13: 0
    14: 0
    15: 0
    16: 0
    etc...
<BLANKLINE>
>>> print(chunk.mesh_subsets) # doctest: +ELLIPSIS
<class 'pyffi.formats.cgf.MeshSubsetsChunk'> instance at ...
* flags :
    <class 'pyffi.formats.cgf.MeshSubsetsFlags'> instance at ...
    * sh_has_decompr_mat : 0
    * bone_indices : 0
* num_mesh_subsets : 2
* reserved_1 : 0
* reserved_2 : 0
* reserved_3 : 0
* mesh_subsets :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: <class 'pyffi.formats.cgf.MeshSubset'> instance at ...
    * first_index : 0
    * num_indices : 6
    * first_vertex : 0
    * num_vertices : 4
    * mat_id : 2
    * radius : 0.7071067...
    * center : [  0.500  0.500  0.000 ]
    1: <class 'pyffi.formats.cgf.MeshSubset'> instance at ...
    * first_index : 6
    * num_indices : 6
    * first_vertex : 4
    * num_vertices : 4
    * mat_id : 5
    * radius : 0.7071067...
    * center : [  0.500  0.500  1.000 ]
<BLANKLINE>
>>> print(chunk.vertices_data) # doctest: +ELLIPSIS
<class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* flags : 0
* data_stream_type : VERTICES
* num_elements : 8
* bytes_per_element : 12
* reserved_1 : 0
* reserved_2 : 0
* vertices :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: [  0.000  0.000  0.000 ]
    1: [  0.000  1.000  0.000 ]
    2: [  1.000  0.000  0.000 ]
    3: [  1.000  1.000  0.000 ]
    4: [  0.000  0.000  1.000 ]
    5: [  0.000  1.000  1.000 ]
    6: [  1.000  0.000  1.000 ]
    7: [  1.000  1.000  1.000 ]
<BLANKLINE>
>>> print(chunk.normals_data) # doctest: +ELLIPSIS
<class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* flags : 0
* data_stream_type : NORMALS
* num_elements : 8
* bytes_per_element : 12
* reserved_1 : 0
* reserved_2 : 0
* normals :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: [  0.000  0.000 -1.000 ]
    1: [  0.000  0.000 -1.000 ]
    2: [  0.000  0.000 -1.000 ]
    3: [  0.000  0.000 -1.000 ]
    4: [  0.000  0.000  1.000 ]
    5: [  0.000  0.000  1.000 ]
    6: [  0.000  0.000  1.000 ]
    7: [  0.000  0.000  1.000 ]
<BLANKLINE>
>>> print(chunk.indices_data) # doctest: +ELLIPSIS
<class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* flags : 0
* data_stream_type : INDICES
* num_elements : 12
* bytes_per_element : 2
* reserved_1 : 0
* reserved_2 : 0
* indices :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: 0
    1: 1
    2: 2
    3: 2
    4: 1
    5: 3
    6: 4
    7: 5
    8: 6
    9: 6
    10: 5
    11: 7
<BLANKLINE>
>>> print(chunk.uvs_data) # doctest: +ELLIPSIS
<class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* flags : 0
* data_stream_type : UVS
* num_elements : 8
* bytes_per_element : 8
* reserved_1 : 0
* reserved_2 : 0
* uvs :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 0.0
    * v : 1.0
    1: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 0.0
    * v : 0.0
    2: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 1.0
    * v : 1.0
    3: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 1.0
    * v : 0.0
    4: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 0.0
    * v : 1.0
    5: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 0.0
    * v : 0.0
    6: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 1.0
    * v : 1.0
    7: <class 'pyffi.formats.cgf.UV'> instance at ...
    * u : 1.0
    * v : 0.0
<BLANKLINE>
>>> print(chunk.tangents_data) # doctest: +ELLIPSIS
<class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* flags : 0
* data_stream_type : TANGENTS
* num_elements : 8
* bytes_per_element : 16
* reserved_1 : 0
* reserved_2 : 0
* tangents :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0, 0: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 32767
    * y : 0
    * z : 0
    * w : 32767
    0, 1: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 0
    * y : -32767
    * z : 0
    * w : 32767
    1, 0: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 32767
    * y : 0
    * z : 0
    * w : 32767
    1, 1: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 0
    * y : -32767
    * z : 0
    * w : 32767
    2, 0: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 32767
    * y : 0
    * z : 0
    * w : 32767
    2, 1: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 0
    * y : -32767
    * z : 0
    * w : 32767
    3, 0: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 32767
    * y : 0
    * z : 0
    * w : 32767
    3, 1: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 0
    * y : -32767
    * z : 0
    * w : 32767
    4, 0: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 32767
    * y : 0
    * z : 0
    * w : 32767
    4, 1: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 0
    * y : -32767
    * z : 0
    * w : 32767
    5, 0: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 32767
    * y : 0
    * z : 0
    * w : 32767
    5, 1: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 0
    * y : -32767
    * z : 0
    * w : 32767
    6, 0: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 32767
    * y : 0
    * z : 0
    * w : 32767
    6, 1: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 0
    * y : -32767
    * z : 0
    * w : 32767
    7, 0: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 32767
    * y : 0
    * z : 0
    * w : 32767
    7, 1: <class 'pyffi.formats.cgf.Tangent'> instance at ...
    * x : 0
    * y : -32767
    * z : 0
    * w : 32767
<BLANKLINE>
>>> print(chunk.colors_data) # doctest: +ELLIPSIS
<class 'pyffi.formats.cgf.DataStreamChunk'> instance at ...
* flags : 0
* data_stream_type : COLORS
* num_elements : 8
* bytes_per_element : 4
* reserved_1 : 0
* reserved_2 : 0
* rgba_colors :
    <class 'pyffi.object_models.xml.array.Array'> instance at ...
    0: <class 'pyffi.formats.cgf.IRGBA'> instance at ...
    * r : 0
    * g : 1
    * b : 2
    * a : 3
    1: <class 'pyffi.formats.cgf.IRGBA'> instance at ...
    * r : 4
    * g : 5
    * b : 6
    * a : 7
    2: <class 'pyffi.formats.cgf.IRGBA'> instance at ...
    * r : 8
    * g : 9
    * b : 10
    * a : 11
    3: <class 'pyffi.formats.cgf.IRGBA'> instance at ...
    * r : 12
    * g : 13
    * b : 14
    * a : 15
    4: <class 'pyffi.formats.cgf.IRGBA'> instance at ...
    * r : 50
    * g : 51
    * b : 52
    * a : 53
    5: <class 'pyffi.formats.cgf.IRGBA'> instance at ...
    * r : 54
    * g : 55
    * b : 56
    * a : 57
    6: <class 'pyffi.formats.cgf.IRGBA'> instance at ...
    * r : 58
    * g : 59
    * b : 60
    * a : 61
    7: <class 'pyffi.formats.cgf.IRGBA'> instance at ...
    * r : 62
    * g : 63
    * b : 64
    * a : 65
<BLANKLINE>
Parameters:
  • verticeslist - A list of lists of vertices (one list per material).
  • normalslist - A list of lists of normals (one list per material).
  • triangleslist - A list of lists of triangles (one list per material).
  • matlist - A list of material indices. Optional.
  • uvslist - A list of lists of uvs (one list per material). Optional.
  • colorslist - A list of lists of RGBA colors (one list per material). Optional. Each color is a tuple (r, g, b, a) with each component an integer between 0 and 255.

Class Variable Details [hide private]

_attribute_list

Value:
[<pyffi.object_models.xml.StructAttribute object at 0x27245d0>,
 <pyffi.object_models.xml.StructAttribute object at 0x2724710>,
 <pyffi.object_models.xml.StructAttribute object at 0x2724810>,
 <pyffi.object_models.xml.StructAttribute object at 0x2724890>,
 <pyffi.object_models.xml.StructAttribute object at 0x27248d0>,
 <pyffi.object_models.xml.StructAttribute object at 0x2724910>,
 <pyffi.object_models.xml.StructAttribute object at 0x2724950>,
 <pyffi.object_models.xml.StructAttribute object at 0x2724990>,
...