※フリーズ前提です
使い方
コンポーネントを選択
PICKセッションになるので、平面を作成
平面化しました。
JScript
//AlignPlane //2011 05 14 //v0.1 main(); function main(){ if(Selection(0).Count == 0) return var oSel = Selection(0); if(oSel.type == "polymsh"){ //ジオメトリを選択していた場合 oObj = oSel oSub = oSel.ActivePrimitive.Geometry.Points.SubComponent }else if(oSel.Type == "edgeSubComponent" || oSel.Type == "polySubComponent"){ oSub = oSel.SubComponent.ComponentCollection.NeighborVertices( 1 ).SubComponent; oObj = oSub.Parent3DObject; }else if(oSel.Type == "pntSubComponent"){ oSub = oSel.subComponent; oObj = oSub.Parent3DObject; }else{ return false; } FreezeModeling(oObj); Logmessage(oSub) oColl = oSub.ComponentCollection; //そろえるべき平面を作る p0 = XSIMath.CreateVector3(); p1 = XSIMath.CreateVector3(); p2 = XSIMath.CreateVector3(); Pick = pickPosition(); if(!Pick(0))return; p0.set(Pick(1),Pick(2),Pick(3)); Pick = pickPosition(); if(!Pick(0))return; p1.set(Pick(1),Pick(2),Pick(3)); Pick = pickPosition(); if(!Pick(0))return; p2.set(Pick(1),Pick(2),Pick(3)); v1 = XSIMath.CreateVector3(); v2 = XSIMath.CreateVector3(); nv = XSIMath.CreateVector3(); v1.sub(p0,p1); v2.sub(p2,p1); nv.Cross(v1,v2); nv.NormalizeInPlace(); //選択したコンポーネントのインデックスのアレイ IDArray = oColl.IndexArray.toArray(); //Logmessage("IDArray " + IDArray); //オブジェクトの頂点のアレイ Pnts = oObj.ActivePrimitive.Geometry.Points; PosArray = Pnts.PositionArray.toArray(); //ポイント移動用のベクトル mv = XSIMath.CreateVector3(); for(var i = 0; i < Pnts.count; i++){ for(var j = 0; j < IDArray.length; j++){ if(i == IDArray[j]){ //Logmessage("ID " + i + " point is Move") var pPos = L2W(oObj,Pnts(i).Position); var d = nv.Dot( p0 );//ポリ平面は p・n = d var dist = pPos.Dot( nv ) -d; //符号距離は p・n-d mv.Scale( - dist, nv) pPos.addInPlace( mv ); pPos = XSIMath.MapWorldPositionToObjectSpace( oObj.Kinematics.Local.Transform, pPos ); //Logmessage(PosArray[i * 3] + " > " + pPos.x); PosArray[i * 3] = pPos.x; PosArray[i * 3 + 1] = pPos.y; PosArray[i * 3 + 2] = pPos.z; } } } Pnts.PositionArray = PosArray; return true; } //Local to World function L2W(inObj,inVect){ v = inVect; m = XSIMath.CreateMatrix4(); inObj.Kinematics.Global.Transform.getMatrix4(m); v.MulByMatrix4InPlace( m ); return v; }
以前、ツイッターで平面化の話が出たときには???
って感じでしたけど、仕事で必要だったので、作ってみました。
0 件のコメント:
コメントを投稿