'2017/07'에 해당되는 글 2건

  1. 2017.07.26 Maya 의 Face Normal 의 방향
  2. 2017.07.11 point 하나를 attribute로 받는 방법
posted by cimple 2017. 7. 26. 10:13

Maya 에서 face normal 의 방향은, vertex 의 index 순서에 다라서 오른손 법칙에 따라 결정된다.

다음과 같은 코드로 vertex 의 index 를 확인할 수 있다.


sList = om.MSelectionList()
sList.add('srcShape')
meshDagPath = sList.getDagPath(0)
meshFn = om.MFnMesh(meshDagPath)
vtxIdxList = meshFn.getPolygonVertices(0) # vertex indes list of 0th face
print vtxIdxList


만약 Maya 의 face normal reverse 기능으로 노말 방향을 뒤집으면

이 index list의 순서도 바뀌는 것을 확인할 수 있다.

posted by cimple 2017. 7. 11. 15:45

참고링크 : http://www.marcogiordanotd.com/blog/maya/maya-api-tip-creating-compound-vs-point-attribute


position 과 vector 와 같은 multiple attribute를 Maya API 에서 넘겨주는 방법에는 다음과 같은 방법이 있다.


1) Compound attribute

//Output vector attribute
//Creating 3 single attributes  vectorX,Y,Z
MFnNumericAttribute oVecXAttr;
oVecX= oVecXAttr.create("vectorX","vx",MFnNumericData::kFloat);
addAttribute(oVecX);
 
MFnNumericAttribute oVecYAttr;
oVecY= oVecYAttr.create("vectorY","vy",MFnNumericData::kFloat);
addAttribute(oVecY);
 
MFnNumericAttribute oVecZAttr;
oVecZ= oVecZAttr.create("vectorZ","vZ",MFnNumericData::kFloat);
addAttribute(oVecZ);
 
//Output vector compound attribute
//Group them togheter with a compound attribute
MFnCompoundAttribute FoVec;
oVec= FoVec.create("outputVector","ov");
 
//use addChild method to add our attributes to the compound attribute
FoVec.addChild(oVecX);
FoVec.addChild(oVecY);
FoVec.addChild(oVecZ);
addAttribute(oVec);


2) Point attribute

//Create a numeric attribute function set
 
MFnNumericAttribute originFn;
 
 
 
// instead using create() we will use createPoint()
origin=originFn.createPoint("origin","o");
addAttribute(origin);

그런데 이 경우 dataHandle 로 받아서 .asDouble3() 으로 받으면 제대로 값이 들어오지 않는다. .asVector() 도 Double 과 동일하다.

dataHandle.asFloat3() 으로 받아야 제대로 값이 들어온다.

compound attribute 를 사용할 경우 반대로 .asFloat() 을 쓰면 제대로 값이 들어오지 않고 .asDouble3() 을 사용해야 한다.

왜 이런지는 Autodesk 에 직접 문의해보아야 할 듯.


3) Compound attribute with different style

pointXAttrFn = om.MFnNumericAttribute()
lightFollicleLocator.aPositionX = pointXAttrFn.create("positionX", "px", om.MFnNumericData.kDouble, 0.0)
om.MPxNode.addAttribute(lightFollicleLocator.aPositionX)

pointYAttrFn = om.MFnNumericAttribute()
lightFollicleLocator.aPositionY = pointYAttrFn.create("positionY", "py", om.MFnNumericData.kDouble, 0.0)
om.MPxNode.addAttribute(lightFollicleLocator.aPositionY)

pointZAttrFn = om.MFnNumericAttribute()
lightFollicleLocator.aPositionZ = pointZAttrFn.create("positionZ", "pz", om.MFnNumericData.kDouble, 0.0)
om.MPxNode.addAttribute(lightFollicleLocator.aPositionZ)

pointAttrFn = om.MFnNumericAttribute()
lightFollicleLocator.aPosition = pointAttrFn.create("position", "p", lightFollicleLocator.aPositionX, lightFollicleLocator.aPositionY, lightFollicleLocator.aPositionZ)
om.MPxNode.addAttribute(lightFollicleLocator.aPosition)


그리고 이 경우, compute function 에서 plug==attribute 에 해당하는 부분에 attribute 를 그대로 compound attribute 이름을 넣으면 안된다. plug 에서 자동적으로 compound 하위 attribute 들을 plug 로 가져오기 때문이다.

custom 하게 만들어진 attribute들의 경우에는 각각의 경우를 넣으면 되겠지만, createPoint 로 attribute를 만들었을 경우에는 해당 plug 이름에 직접 접근하기가 애매하므로 plug.parent() 가 내가 만든 compound attribute 이름이 맞다면 compute 해라 라고 만들어주면 된다.