【问题标题】:Maxscript function doesn't update in while loopMaxscript函数在while循环中不更新
【发布时间】:2016-02-14 19:44:43
【问题描述】:

我在 maxscript 中有这个函数来检查顶点是否在相机帧中。我想要做的是将函数放在一个while循环中并将相机向后移动,每次相机移动时它都应该检查对象是否在相机中。但是当我这样做时,while循环中的函数不会更新,它总是返回第一次检查的值。

fn getVertsInViewport theObject =
(
local theVerts = #() --return array
local theMesh = snapshotasmesh theObject --grab the mesh from top of the stack
local theCount = theMesh.numverts --get the number of vertices 
local theTM  = viewport.getTM() --get the current view's transformation
local screen_width = renderWidth --get the current render height
local screen_height = renderHeight --get the current render width
for v = 1 to theCount do --loop through all vertices
(
    local thePos = (getVert theMesh v) * theTM --transform vertex in view space
    --get the world location of the upper left corner of the camera view at the depth of the vertex
    local screen_origin = mapScreenToView [0,0] (thePos.z) [screen_width,screen_height]
    --get the bottom right corner at the vertex depth
    local end_screen = mapScreenToView [screen_width,screen_height] (thePos.z) [screen_width,screen_height]
    --calculate the world size based on the two corners
    local world_size = screen_origin-end_screen
    --calculate the X and Y aspect factors
    local x_aspect = screen_width/(abs world_size.x)
    local y_aspect = screen_height/(abs world_size.y)
    --calculate the screen coordinates using all the above data:
    local screen_coords = point2 (x_aspect*(thePos.x-screen_origin.x)) (-(y_aspect*(thePos.y-screen_origin.y)))
    --if the vertex is outside of the screen (negative or higher than the render size), collect it
    if screen_coords.x <= 0 or screen_coords.y <= 0 or screen_coords.x > screen_width or screen_coords.y > screen_height  then
        append theVerts v
)--end v loop
delete theMesh --release the memory used by the TriMesh
theVerts  --return the collected vertices
)--end fn verts in viewport

maksimum = 3
counter = 1
 while counter < maksimum do
 (
    move $Camera001 [0,-550,0] 
    cameraOK = getVertsInViewport $
    print (counter as string +"  "+ "camera_pos = "+ $Camera001.pos.y as   string +" : " +(cameraOK as string))
    counter += 1
 )

【问题讨论】:

    标签: maxscript


    【解决方案1】:

    在移动相机后添加对 forceCompleteRedraw() 的调用。

    我假设您已将活动视口设置为相机视图,因为您使用 viewport.getTM() 来获取相机转换。重绘似乎允许视口刷新,尊重新的相机位置,并给出预期的结果。

    请注意,MaxScript 在运行时会阻塞 3ds Max 的主线程。这意味着没有处理 UI 事件和其他类型的刷新活动,这可能是这里造成冲突的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-28
      • 1970-01-01
      • 2016-01-25
      • 2019-03-05
      相关资源
      最近更新 更多