ポイントの位置を2D Array として設定したり、戻したりします(最初の次元には x,y,z 値が含まれます)。スクリプトオペレータでないオペレータの場合は、このプロパティは、オブジェクトがフリーズされている場合にのみ設定できます。このコマンドは取り消すことができません。
// get accessor Object rtn = PointCollection.PositionArray; // set accessor PointCollection.PositionArray = Object; |
set oRoot = application.activeproject.activescene.root set oObj = oRoot.addgeometry( "Cube", "MeshSurface" ) FreezeObj oObj set oGeometry = oObj.activeprimitive.geometry dGlobalPosY = oObj.Kinematics.global.parameters("posy").value ' get the geometry points in an array of x,y,z values aPositions = oGeometry.Points.PositionArray ' squish all the points that are below the Y=0 axis dSquishFactor = 3 for i = LBound(aPositions, 2) to UBound(aPositions, 2) ' Compute the point's global Y position. dGlobalYPnt = aPositions(1, i) + dGlobalPosY ' If the point is below the Y=0 plane... If dGlobalYPnt < 0 Then ' Compute the squish factor for the point. dSquishPnt = 1.0 - dGlobalYPnt * dSquishFactor ' Squish the point. aPositions(0, i) = aPositions(0, i) * dSquishFactor aPositions(1, i) = - dGlobalPosY aPositions(2, i) = aPositions(2, i) * dSquishFactor End If next ' set the geometry points using the modified position array oGeometry.Points.PositionArray = aPositions |
TestPointsPositionArray(); function TestPointsPositionArray() { LogMessage( "----- Test PointCollection.PositionArray -----" ); var oCube = CreatePrim("Cube", "MeshSurface"); FreezeObj( oCube.name ); LogMessage( "--- current position array ---" ); var aPos = new VBArray(oCube.ActivePrimitive.Geometry.Points.PositionArray); for (i = 0; i <= aPos.ubound(2); i++) { LogMessage(i + " " + aPos.getItem(0, i) + " " + aPos.getItem(1, i) + " " + aPos.getItem(2, i)); } LogMessage( "--- current position array (1 dim) ---" ); var aPos2 = aPos.toArray(); LogMessage(typeof(aPos2)); LogMessage(aPos2.length); for (i = 0; i < aPos2.length; i += 3) { LogMessage(i + " " + aPos2[i] + " " + aPos2[i+1] + " " + aPos2[i+2]); } aPos2[0] = -4; aPos2[1] = -4; aPos2[2] = -4; aPos2[3] = 4; aPos2[4] = -4; aPos2[5] = -4; aPos2[6] = -1; aPos2[7] = 4; aPos2[8] = -1; aPos2[9] = 1; aPos2[10] = 4; aPos2[11] = -1; aPos2[12] = -4; aPos2[13] = -4; aPos2[14] = 4; aPos2[15] = 4; aPos2[16] = -4; aPos2[17] = 4; aPos2[18] = -1; aPos2[19] = 4; aPos2[20] = 1; aPos2[21] = 1; aPos2[22] = 4; aPos2[23] = 1; oCube.ActivePrimitive.Geometry.Points.PositionArray = aPos2; LogMessage( "--- new position array ---" ); var aPos = new VBArray(oCube.ActivePrimitive.Geometry.Points.PositionArray); for (i = 0; i <= aPos.ubound(2); i++) { LogMessage(i + " " + aPos.getItem(0, i) + " " + aPos.getItem(1, i) + " " + aPos.getItem(2, i)); } return 0; } |