Created
June 22, 2015 06:50
-
-
Save taikomatsu/586dc7847517f01f153f to your computer and use it in GitHub Desktop.
uv set and get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from maya import OpenMaya | |
from pymel.core import * | |
def mdagpath_from_name(name, extend_to_shape=False): | |
if not objExists(name): | |
raise MayaNodeError, name | |
slist = OpenMaya.MSelectionList() | |
slist.add(name) | |
dagpath = OpenMaya.MDagPath() | |
slist.getDagPath(0, dagpath) | |
if extend_to_shape: | |
dagpath.extendToShape() | |
return dagpath | |
# store | |
def store_uvs(objs): | |
buff = {} | |
for o in objs: | |
print o.name() | |
mesh = mdagpath_from_name(o.name(), True) | |
meshfn = OpenMaya.MFnMesh(mesh) | |
us = OpenMaya.MFloatArray() | |
vs = OpenMaya.MFloatArray() | |
meshfn.getUVs(us, vs) | |
buff[o.name()] = (us, vs) | |
return buff | |
def set_uvs(objs, buff): | |
for o in objs: | |
qname = o.name().replace('_L', '_R') | |
mesh = mdagpath_from_name(o.name(), True) | |
meshfn = OpenMaya.MFnMesh(mesh) | |
us, vs = buff[qname] | |
meshfn.setUVs(us, vs) | |
# まずUV情報を取得したいポリゴンオブジェクトを選んでこれを実行 | |
buff = store_uvs(selected()) | |
# その後UV情報を移したいポリゴンオブジェクトを選んでこれを実行 | |
# 現状雑にハードコーディングしてあるが、例えば"geo_L"から取得した情報は"geo_R"にしか移植できない。 | |
# これはset_uvs()のqname変数のところを適当に書き換えればOK | |
set_uvs(selected(), buff) | |
# このuv情報はMayaを落とさない限り別のシーンにも移植可能。 | |
# あと当然トポロジは同じである必要がある。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment