利用者:TrumanBlending/Matrix Indexing

提供: wiki
移動先: 案内検索

Matrix Indexing

Changes for 2.62 in Matrix Indexing

Matrix indexing has now been changed to be row first as is usual in math. This has some important consequences for script writers. See below for a list of Gotchas.


Cheat Sheet

matrix[j][k]   --> matrix[k][j]
matrix[j][k]   --> matrix.col[j][k]
matrix[j]      --> matrix.col[j]
matrix = Matrix((a, b, c), (d, e, f), (g, h, i)) --> Matrix((a, d, g), (b, e, h), (c, f, i))
len(matrix)    --> len(matrix[0])
len(matrix[0]) --> len(matrix)
translation = matrix[3][0:3] --> matrix.translation[:]
matrix[3][0:3] = x, y, z     --> matrix.translation = x, y, z
for vec in mat: ...          --> for vec in mat.col: ...
mat.col_size                 --> len(mat.row)
mat.row_size                 --> len(mat.col)

Gotchas for Script Writers

Matrix Index Order

Matrices now access the row with the first index and the column with the second index. So,

matrix = Matrix()
first_row = matrix[0]

Would access the first row of the matrix. Previously it was the first column.

This also means that matrix element access is now by row first indexing as is usual in math. That is, to access the second row's third element;

element = matrix[1][2]

In addition, care must be taken when looping over matrices. For example;

for row in matrix:
    for item in row:
        print(item)

will print all the items in the matrix reading the matrix from left to right and top to bottom. Previously this would have been from top to bottom and left to right.

Matrix Construction

When explicitly constructing new matrices, the rows are input as tuples.

matrix = Matrix(((1, 2), (3, 4)))

So this means matrix[0] == (1, 2) and matrix[1] == (3, 4).

Previously matrices were constructed by parsing tuples of the columns. The result is that all explicit matrix construction must be transposed.

Matrix Length

Matrix length,

len(matrix)

now returns the number of rows in the matrix. Previously this returned the number of columns.

Matrix Translation Component

For a 4 x 4 matrix you can now get and set the translation component using;

matrix.translation

Previously, you could could get the translation component from the third matrix item.

Matrix Column / Row Size

The col_size and row_size attributes have been removed, instead use;

len(mat.col)  # to replace mat.row_size
len(mat.row)  # to replace mat.col_size

Scripts to be Changed / Checked

Prefix with an '-' when checked. Prefix with an '*' when changes needed to be made.

- addons/add_curve_aceous_galore.py
- addons/add_curve_ivygen.py
- addons/add_curve_sapling/__init__.py
- addons/add_curve_sapling/presets/black_tupelo.py
- addons/add_curve_sapling/presets/ca_black_oak.py
- addons/add_curve_sapling/presets/quaking_aspen.py
- addons/add_curve_sapling/presets/weeping_willow.py
- addons/add_curve_sapling/utils.py
- addons/add_curve_torus_knots.py
- addons/add_mesh_BoltFactory/Boltfactory.py
- addons/add_mesh_BoltFactory/__init__.py
* addons/add_mesh_BoltFactory/createMesh.py
- addons/add_mesh_BoltFactory/preset_utils.py
- addons/add_mesh_BoltFactory/presets/M10.py
- addons/add_mesh_BoltFactory/presets/M12.py
- addons/add_mesh_BoltFactory/presets/M3.py
- addons/add_mesh_BoltFactory/presets/M4.py
- addons/add_mesh_BoltFactory/presets/M5.py
- addons/add_mesh_BoltFactory/presets/M6.py
- addons/add_mesh_BoltFactory/presets/M8.py
- addons/add_mesh_ant_landscape.py
- addons/add_mesh_extra_objects/__init__.py
- addons/add_mesh_extra_objects/add_mesh_3d_function_surface.py
- addons/add_mesh_extra_objects/add_mesh_extra_objects.py
- addons/add_mesh_extra_objects/add_mesh_gears.py
- addons/add_mesh_extra_objects/add_mesh_gemstones.py
- addons/add_mesh_extra_objects/add_mesh_polysphere.py
- addons/add_mesh_extra_objects/add_mesh_pyramid.py
- addons/add_mesh_extra_objects/add_mesh_supertoroid.py
- addons/add_mesh_extra_objects/add_mesh_twisted_torus.py
- addons/add_mesh_pipe_joint.py
- addons/add_mesh_solid.py
* addons/animation_add_corrective_shape_key.py
- addons/animation_animall.py
- addons/animation_rotobezier.py
- addons/curve_simplify.py
- addons/development_api_navigator.py
- addons/development_icon_get.py
- addons/game_engine_save_as_runtime.py
- addons/io_anim_acclaim/__init__.py
- addons/io_anim_bvh/__init__.py
- addons/io_anim_bvh/export_bvh.py
- addons/io_anim_bvh/import_bvh.py
- addons/io_anim_c3d/__init__.py
- addons/io_anim_c3d/import_c3d.py
- addons/io_anim_camera.py
- addons/io_anim_nuke_chan/__init__.py
- addons/io_anim_nuke_chan/export_nuke_chan.py
- addons/io_anim_nuke_chan/import_nuke_chan.py
- addons/io_coat3D/__init__.py
- addons/io_coat3D/coat.py
- addons/io_coat3D/tex.py
- addons/io_convert_image_to_mesh_img/__init__.py
- addons/io_convert_image_to_mesh_img/import_img.py
- addons/io_curve_svg/__init__.py
- addons/io_curve_svg/import_svg.py
- addons/io_curve_svg/svg_colors.py
- addons/io_export_after_effects.py
* addons/io_export_directx_x.py
- addons/io_export_pc2.py
- addons/io_export_unreal_psk_psa.py
- addons/io_import_gimp_image_to_scene.py
- addons/io_import_images_as_planes.py
* addons/io_import_scene_dxf.py
- addons/io_import_scene_lwo.py
addons/io_import_scene_mhx.py
* addons/io_import_scene_unreal_psk.py
- addons/io_mesh_pdb/__init__.py
- addons/io_mesh_pdb/import_pdb.py
- addons/io_mesh_ply/__init__.py
- addons/io_mesh_ply/export_ply.py
- addons/io_mesh_ply/import_ply.py
- addons/io_mesh_raw/__init__.py
- addons/io_mesh_raw/export_raw.py
- addons/io_mesh_raw/import_raw.py
- addons/io_mesh_stl/__init__.py
- addons/io_mesh_stl/blender_utils.py
- addons/io_mesh_stl/stl_utils.py
- addons/io_mesh_uv_layout/__init__.py
- addons/io_mesh_uv_layout/export_uv_eps.py
- addons/io_mesh_uv_layout/export_uv_png.py
- addons/io_mesh_uv_layout/export_uv_svg.py
- addons/io_scene_3ds/__init__.py
* addons/io_scene_3ds/export_3ds.py
* addons/io_scene_3ds/import_3ds.py
- addons/io_scene_fbx/__init__.py
* addons/io_scene_fbx/export_fbx.py
- addons/io_scene_m3/__init__.py
- addons/io_scene_m3/import_m3.py
- addons/io_scene_map/__init__.py
- addons/io_scene_map/export_map.py
- addons/io_scene_obj/__init__.py
- addons/io_scene_obj/export_obj.py
- addons/io_scene_obj/import_obj.py
- addons/io_scene_x3d/__init__.py
- addons/io_scene_x3d/export_x3d.py
- addons/io_scene_x3d/import_x3d.py
- addons/io_shape_mdd/__init__.py
- addons/io_shape_mdd/export_mdd.py
- addons/io_shape_mdd/import_mdd.py
- addons/light_field_tools/__init__.py
- addons/light_field_tools/light_field_tools.py
- addons/mesh_bsurfaces.py
- addons/mesh_inset/__init__.py
- addons/mesh_inset/geom.py
- addons/mesh_inset/model.py
- addons/mesh_inset/offset.py
- addons/mesh_inset/triquad.py
- addons/mesh_looptools.py --- note, this needs some care taken! <- fixed by original author
- addons/mesh_relax.py
addons/mocap/__init__.py
addons/mocap/mocap_constraints.py
addons/mocap/mocap_tools.py
addons/mocap/retarget.py
- addons/modules/add_utils.py
- addons/modules/constants_utils.py
- addons/modules/cursor_utils.py
- addons/modules/extensions_framework/__init__.py
- addons/modules/extensions_framework/ui.py
- addons/modules/extensions_framework/util.py
- addons/modules/extensions_framework/validate.py
- addons/modules/geometry_utils.py
- addons/modules/misc_utils.py
- addons/modules/ui_utils.py
- addons/netrender/__init__.py
- addons/netrender/balancing.py
- addons/netrender/client.py
- addons/netrender/master.py
- addons/netrender/master_html.py
- addons/netrender/model.py
- addons/netrender/operators.py
- addons/netrender/repath.py
- addons/netrender/slave.py
- addons/netrender/thumbnail.py
- addons/netrender/ui.py
- addons/netrender/utils.py
- addons/netrender/versioning.py
- addons/object_add_chain.py
- addons/object_animrenderbake.py
- addons/object_cloud_gen.py
- addons/object_fracture/__init__.py
- addons/object_fracture/fracture_ops.py
- addons/object_fracture/fracture_setup.py
- addons/object_grease_scatter.py
- addons/paint_palette.py
- addons/render_copy_settings/__init__.py
- addons/render_copy_settings/operator.py
- addons/render_copy_settings/panel.py
- addons/render_copy_settings/presets.py
- addons/render_povray/__init__.py
* addons/render_povray/render.py
- addons/render_povray/ui.py
- addons/render_povray/update_files.py
- addons/render_renderfarmfi.py
- addons/rigify/__init__.py
- addons/rigify/generate.py
- addons/rigify/metarig_menu.py
- addons/rigify/metarigs/__init__.py
- addons/rigify/metarigs/human.py
- addons/rigify/rig_ui_template.py
- addons/rigify/rigs/__init__.py
- addons/rigify/rigs/basic/__init__.py
- addons/rigify/rigs/basic/copy.py
- addons/rigify/rigs/basic/copy_chain.py
- addons/rigify/rigs/biped/__init__.py
- addons/rigify/rigs/biped/arm/__init__.py
- addons/rigify/rigs/biped/arm/deform.py
- addons/rigify/rigs/biped/arm/fk.py
- addons/rigify/rigs/biped/arm/ik.py
- addons/rigify/rigs/biped/leg/__init__.py
- addons/rigify/rigs/biped/leg/deform.py
- addons/rigify/rigs/biped/leg/fk.py
- addons/rigify/rigs/biped/leg/ik.py
- addons/rigify/rigs/finger.py
- addons/rigify/rigs/misc/__init__.py
- addons/rigify/rigs/misc/delta.py
- addons/rigify/rigs/neck_short.py
- addons/rigify/rigs/palm.py
- addons/rigify/rigs/spine.py
- addons/rigify/ui.py
- addons/rigify/utils.py
- addons/space_view3d_3d_navigation.py
- addons/space_view3d_copy_attributes.py
- addons/space_view3d_materials_utils.py
- addons/space_view3d_math_vis/__init__.py
* addons/space_view3d_math_vis/draw.py
- addons/space_view3d_math_vis/utils.py
- addons/space_view3d_panel_measure.py
- addons/space_view3d_screencast_keys.py
- addons/space_view3d_spacebar_menu.py
- addons/system_blend_info.py
- addons/system_demo_mode/__init__.py
- addons/system_demo_mode/config.py
- addons/system_demo_mode/demo_mode.py
- addons/system_property_chart.py
- addons/texture_paint_layer_manager.py

contrib

addons_contrib/add_mesh_beam_builder.py
addons_contrib/add_mesh_column.py
addons_contrib/add_mesh_rocks/__init__.py
addons_contrib/add_mesh_rocks/rockgen.py
addons_contrib/add_mesh_rocks/settings.py
addons_contrib/add_mesh_rocks/utils.py
addons_contrib/add_mesh_stairs/__init__.py
addons_contrib/add_mesh_stairs/general.py
addons_contrib/add_mesh_stairs/post.py
addons_contrib/add_mesh_stairs/rail.py
addons_contrib/add_mesh_stairs/retainer.py
addons_contrib/add_mesh_stairs/stairbuilder.py
addons_contrib/add_mesh_stairs/stringer.py
addons_contrib/add_mesh_stairs/tread.py
addons_contrib/add_mesh_walls/Blocks.py
addons_contrib/add_mesh_walls/Wallfactory.py
addons_contrib/add_mesh_walls/__init__.py
addons_contrib/animation_motion_trail.py
addons_contrib/btrace/__init__.py
addons_contrib/btrace/bTrace.py
addons_contrib/cmu_mocap_browser/__init__.py
addons_contrib/cmu_mocap_browser/library.py
addons_contrib/cursor_control/__init__.py
addons_contrib/cursor_control/data.py
addons_contrib/cursor_control/history.py
addons_contrib/cursor_control/memory.py
addons_contrib/cursor_control/operators.py
addons_contrib/cursor_control/ui.py
addons_contrib/curve_tools.py
addons_contrib/development_class_viewer.py
addons_contrib/game_engine_ragdolls_kit/__init__.py
addons_contrib/game_engine_ragdolls_kit/brik.py
addons_contrib/game_engine_ragdolls_kit/brik_funcs.py
addons_contrib/game_engine_ragdolls_kit/templates/brik_init_ragdoll.py
addons_contrib/game_engine_ragdolls_kit/templates/brik_load.py
addons_contrib/game_engine_ragdolls_kit/templates/brik_spawn.py
addons_contrib/geodesic_domes/__init__.py
addons_contrib/geodesic_domes/add_shape_geodesic.py
addons_contrib/geodesic_domes/forms_259.py
addons_contrib/geodesic_domes/geodesic_classes_259.py
addons_contrib/geodesic_domes/third_domes_panel.py
addons_contrib/geodesic_domes/vefm_259.py
addons_contrib/gpencil_retopo/__init__.py
addons_contrib/gpencil_retopo/retopo.py
addons_contrib/gyes/__init__.py
addons_contrib/gyes/random_material_generator.py
addons_contrib/gyes/random_texture_generator.py
addons_contrib/io_export_dxf/__init__.py
addons_contrib/io_export_dxf/draw_blenders/__init__.py
addons_contrib/io_export_dxf/export_dxf.py
addons_contrib/io_export_dxf/model/__init__.py
addons_contrib/io_export_dxf/model/dxfLibrary.py
addons_contrib/io_export_dxf/model/migiusModel.py
addons_contrib/io_export_dxf/model/model.py
addons_contrib/io_export_dxf/operator.py
addons_contrib/io_export_dxf/primitive_exporters/__init__.py
addons_contrib/io_export_dxf/primitive_exporters/base_exporter.py
addons_contrib/io_export_dxf/primitive_exporters/camera_exporter.py
addons_contrib/io_export_dxf/primitive_exporters/curve_exporter.py
addons_contrib/io_export_dxf/primitive_exporters/empty_exporter.py
addons_contrib/io_export_dxf/primitive_exporters/insert_exporter.py
addons_contrib/io_export_dxf/primitive_exporters/lamp_exporter.py
addons_contrib/io_export_dxf/primitive_exporters/mesh_exporter.py
addons_contrib/io_export_dxf/primitive_exporters/text_exporter.py
addons_contrib/io_export_dxf/primitive_exporters/viewborder_exporter.py
addons_contrib/io_export_md3.py
addons_contrib/io_import_BrushSet.py
addons_contrib/io_import_LRO_Lola_MGS_Mola_img.py
addons_contrib/io_import_fbx.py
addons_contrib/io_import_lipSync_Importer.py
addons_contrib/io_import_voodoo_camera.py
addons_contrib/io_mesh_wow_mdl.py
addons_contrib/io_mesh_xyz/__init__.py
addons_contrib/io_mesh_xyz/import_xyz.py
addons_contrib/io_points_pcd/__init__.py
addons_contrib/io_points_pcd/pcd_utils.py
addons_contrib/io_points_pcd/pcdparser.py
addons_contrib/io_scene_ms3d/__init__.py
addons_contrib/io_scene_ms3d/ms3d_export.py
addons_contrib/io_scene_ms3d/ms3d_import.py
addons_contrib/io_scene_ms3d/ms3d_spec.py
addons_contrib/io_scene_ms3d/ms3d_utils.py
addons_contrib/lamp_geographical_sun.py
addons_contrib/mesh_edge_intersection_tools.py
addons_contrib/mesh_inset_extrude.py
addons_contrib/mesh_normal_smooth.py
addons_contrib/mesh_seam_from_uv_isles.py
addons_contrib/mesh_select_vertex_groups.py
addons_contrib/mesh_vertex_slide.py
addons_contrib/object_batch_rename_datablocks.py
addons_contrib/object_drop_to_ground.py
addons_contrib/render_clay.py
addons_contrib/render_to_print.py
addons_contrib/space_view3d_add_surround_cameras.py
addons_contrib/space_view3d_align_tools.py
addons_contrib/space_view3d_enhanced_3d_cursor.py
addons_contrib/space_view3d_game_props_visualiser.py
addons_contrib/space_view3d_manipulator_Menu.py
addons_contrib/space_view3d_objects_panel.py
- addons_contrib/system_keyboard_svg.py
addons_contrib/system_theme_manager.py
addons_contrib/text_editor_pasteall.py
addons_contrib/wetted_mesh.py

trunk - modules

- modules/addon_utils.py
- modules/animsys_refactor.py
- modules/blend_render_info.py
- modules/bpy/__init__.py
- modules/bpy/ops.py
- modules/bpy/path.py
- modules/bpy/utils.py
- modules/bpy_extras/__init__.py
- modules/bpy_extras/anim_utils.py
- modules/bpy_extras/image_utils.py
* modules/bpy_extras/io_utils.py
- modules/bpy_extras/keyconfig_utils.py
- modules/bpy_extras/mesh_utils.py
- modules/bpy_extras/object_utils.py
* modules/bpy_extras/view3d_utils.py
- modules/bpy_types.py
- modules/bpyml.py
- modules/bpyml_ui.py
- modules/console/__init__.py
- modules/console/complete_calltip.py
- modules/console/complete_import.py
- modules/console/complete_namespace.py
- modules/console/intellisense.py
- modules/console_python.py
- modules/console_shell.py
- modules/graphviz_export.py
- modules/keyingsets_utils.py
- modules/rna_info.py
- modules/rna_prop_ui.py
- modules/sys_info.py

trunk - startup

- startup/bl_operators/add_mesh_torus.py
- startup/bl_operators/anim.py
- startup/bl_operators/clip.py
- startup/bl_operators/console.py
- startup/bl_operators/image.py
- startup/bl_operators/mesh.py
- startup/bl_operators/object.py
- startup/bl_operators/object_align.py
- startup/bl_operators/object_quick_effects.py
- startup/bl_operators/object_randomize_transform.py
- startup/bl_operators/presets.py
- startup/bl_operators/screen_play_rendered_anim.py
- startup/bl_operators/sequencer.py
- startup/bl_operators/uvcalc_follow_active.py
- startup/bl_operators/uvcalc_lightmap.py
- startup/bl_operators/uvcalc_smart_project.py
- startup/bl_operators/vertexpaint_dirt.py
- startup/bl_operators/view3d.py
- startup/bl_operators/wm.py
- startup/bl_ui/__init__.py
- startup/bl_ui/properties_animviz.py
- startup/bl_ui/properties_data_armature.py
- startup/bl_ui/properties_data_bone.py
- startup/bl_ui/properties_data_camera.py
- startup/bl_ui/properties_data_curve.py
- startup/bl_ui/properties_data_empty.py
- startup/bl_ui/properties_data_lamp.py
- startup/bl_ui/properties_data_lattice.py
- startup/bl_ui/properties_data_mesh.py
- startup/bl_ui/properties_data_metaball.py
- startup/bl_ui/properties_data_modifier.py
- startup/bl_ui/properties_data_speaker.py
- startup/bl_ui/properties_game.py
- startup/bl_ui/properties_material.py
- startup/bl_ui/properties_object.py
- startup/bl_ui/properties_object_constraint.py
- startup/bl_ui/properties_particle.py
- startup/bl_ui/properties_physics_cloth.py
- startup/bl_ui/properties_physics_common.py
- startup/bl_ui/properties_physics_dynamicpaint.py
- startup/bl_ui/properties_physics_field.py
- startup/bl_ui/properties_physics_fluid.py
- startup/bl_ui/properties_physics_smoke.py
- startup/bl_ui/properties_physics_softbody.py
- startup/bl_ui/properties_render.py
- startup/bl_ui/properties_scene.py
- startup/bl_ui/properties_texture.py
- startup/bl_ui/properties_world.py
- startup/bl_ui/space_clip.py
- startup/bl_ui/space_console.py
- startup/bl_ui/space_dopesheet.py
- startup/bl_ui/space_filebrowser.py
- startup/bl_ui/space_graph.py
- startup/bl_ui/space_image.py
- startup/bl_ui/space_info.py
- startup/bl_ui/space_logic.py
- startup/bl_ui/space_nla.py
- startup/bl_ui/space_node.py
- startup/bl_ui/space_outliner.py
- startup/bl_ui/space_sequencer.py
- startup/bl_ui/space_text.py
- startup/bl_ui/space_time.py
- startup/bl_ui/space_userpref.py
- startup/bl_ui/space_userpref_keymap.py
- startup/bl_ui/space_view3d.py
- startup/bl_ui/space_view3d_toolbar.py
- startup/keyingsets_builtins.py

trunk - templates

- templates/addon_add_object.py
- templates/background_job.py
- templates/batch_export.py
- templates/builtin_keyingset.py
- templates/driver_functions.py
- templates/gamelogic.py
- templates/gamelogic_basic.py
- templates/gamelogic_module.py
- templates/operator_export.py
- templates/operator_mesh_add.py
- templates/operator_modal.py
- templates/operator_modal_draw.py
- templates/operator_modal_timer.py
- templates/operator_modal_view3d.py
- templates/operator_simple.py
- templates/operator_uv.py
- templates/ui_menu.py
- templates/ui_menu_simple.py
- templates/ui_panel_simple.py