数码资源网

文章频道 软件下载 安卓下载 苹果下载

当前位置:首页文章中心渲染专栏3ds max → max脚本模拟3S效果

max脚本模拟3S效果

时间:2005-11-17 17:59:50人气:174作者:网友整理
节奏大师自动3S特别版(节奏大师特别版) v2.5.1 安卓版
节奏大师自动3S特别版(节奏大师特别版) v2.5.1 安卓版 for Android
  • 类型:手游存档大小:54.95M语言:简体中文 评分:3.0
  • 腾讯节奏大师小编玩了1000多关了呢,你呢?今天分享一款节奏大师特别版,适用于安...
立即下载
Drifting Max Prov1.4.9
Drifting Max Prov1.4.9 for Android
  • 类型:赛车竞技大小:13.05M语言: 评分:4.5
  • DriftingMaxPro是一款竞速类游戏,真实模拟赛车物理效果,而且允许玩家...
立即下载
3S智能预警安卓版(智能驾驶安全预警app) v3.11.4 手机版
3S智能预警安卓版(智能驾驶安全预警app) v3.11.4 手机版 for Android
  • 类型:安卓日常应用大小:37.61M语言:简体中文 评分:3.0
  • 生活当中开车总会怕遇见交通违章的时候,3S智能预警安卓版现在你不必在担心了,为你...
立即下载
首先看一下效果图

   下面是使用方法和步骤:
   一、创建几何体、光源。如图。

点击放大

二、选择几何体,为其指定一个纯白色材质(一定不要有颜色)。如图。

点击放大

   三、选择几何体,在utilities面板点击more按钮,选择 Assign Vertex Colors组件,确认channel组选择的是vertex color,按“指定到选择”(assign to selected)按钮。

点击放大

[page]

四、现在可以删除光源了(或把它关闭)。然后点选几何体,这是会弹出vertexPaint对话框,选择左上的vertex color display -unshaded ,这时可以看见即使场景中没有灯光几何体也会被照亮。

点击放大

   五、试着渲染一下,却没有变化,这时,需要给Diffuse一个vertex color材质。渲染一下,差不多了。还要给它一个100的自发光值。这时可以了。

点击放大

 六、塌陷成网格物体。然后运行脚本。点选“转变为max6几何体”按钮。然后简单设置如图:最后按下"Collapse + Generate Trans."按钮,等待结果。

点击放大

   完成如图,基本思想是将灯光的光照信息通过择 Assign Vertex Colors组件变成几何体的顶点的颜色值,然后通过公式计算各顶点颜色的混合程度。原脚本对max6不支持是因为max6网格物体增加了c-p-v vertex属性,导致着色错误。为了对比将原脚本,练习场景上传。

 


[page]

-- 版本 0.56 for max6
-- 作者 grant adam ghra@optushome.com.au
-- 修改 于浩 yuhao_dudu@163.com
-- 模拟半透明物体的效果

-- v0.56 修改了该脚本不能在max6环境下运行的毛病。主要是对顶点着色的机制作了调整
-- 为了尊重作者,所以只对修改的部分做了汉化。

-- 典型工作流程:
-- 1. 创建几何体、光源。
-- 2. 选择几何体, 为它指定一个白色材质, 使用 'assign vertex colors' 功能
-- 3. 塌陷几何体为网格物体, 运行脚本, 点击"转变为max6几何体"。
-- 4. 选择那些不应该被照亮的顶点 然后使用'Assign selected verts as black'。
-- 5. 调整参数, 点击 'collapse + generate trans.' 按钮然后等待计算完成。
-- 6. assign a material with a vertex map in the self illum slot, render.
-- 7. if you don't like result hit the 'restore vertex colors' play with params and rebuild trans.
-- 8. when happy with trans, play with material until desired result.
-- note the vertex color map can be made sub to an output map and curve/multiplier/etc. changed there.
-- try the vertex color map as the input for a Mapped Gradient Ramp.
-- use a larger 'nth vertex' param until you are happy, then set to 1 or 2 and wait much longer (depending on mesh density).
-- more than likely you can get away with calculating on a lighter mesh and then meshsmoothing.
-------------------------------------------------------------
global orig_clr_array
rollout trlncy "Translucency 0.56 for max 6"
(
spinner srchrad "Search Radius" range:[0,1000000,100] type:#float fieldwidth:50
spinner vskip "nth Vertex (skip verts)" range:[1,100000,4] type:#integer fieldwidth:50
spinner vflf "Trans. Falloff" range:[0.1,25, 1] fieldwidth:50
--spinner vmult "Trans. multiplier" range:[0.1,100,1.5] fieldwidth:50
button doit "Collapse + Generate Trans." width:170
checkbox solonly "Transluc. component only" checked:false
checkbox ussel "Selected Vertices"
label a1 "You must have vertex colors"
label a2 "assigned with the vert colors"
label a3 "utility, using the 'mix' type."
button und "Restore vertex colors to base" width:170 offset:[-8,0]
button set_und "Set vertex color base to current" width:170 offset:[-3,0]
button crblk "Assign selected verts as black" width:170 offset:[-6,0]
button crwt "Assign selected verts as white" width:170 offset:[-6,0]
button crSS "Assign Sel.verts>Soft Selection:" width:170 offset:[-2,0]
label a5 "if cancel = no screen redraw:"
button fxsc "Enable ScreenRedraw" width:170
button btn_cvtmax6 "转变为max6几何体" pos:[4,320] width:170 height:16
on fxsc pressed do
(
  enablesceneredraw()
)

on btn_cvtmax6 pressed do
(
  c=#()
  for i=0 to 255 do
  (
    c[i+1]=meshop.getVertsByColor $ (color i i i) 1 1 1 

  ----将cpv顶点数和几何体顶点数对应
  defaultVCFaces $
  -----给每个顶点着色
  for j=0 to 255 do
  (
    select $.verts[c[j+1]]
    a=$.selectedverts
    for k=1 to a.count do
    (
      setVertColor $ a[k].index (color j j j)
)

on set_und pressed do
(  
    orig_clr_array = #()
    for i in 1 to (getnumcpvverts $) do --------------
    (
      append orig_clr_array (getvertcolor $ i) -- store original vertex colors
    
    und.enabled = true
)

on crSS pressed do
(
    try(getvertcolor $ 1)
    catch(defaultVCFaces $)
  try
  (
  --orig_clr_array = #()     -- store original color vertex array
  if orig_clr_array[1] == undefined then
  (
    for i in 1 to (getnumcpvverts $) do
    (
      append orig_clr_array (getvertcolor $ i) -- store original vertex colors 
  
  und.enabled = true
  SS_clr_array = #() -- to store the new data
    if $.modifiers.count != 0 then collapseStack $
    subObjectLevel = 1
    --sel_array = getvertselection $
    for i in 1 to (getnumcpvverts $) do
    (
      if btow.checked then (append SS_clr_array ((color 255 255 255) * (pointSelection $ i)))
      else (append SS_clr_array ((color 255 255 255) * (1 - (pointSelection $ i))))
    --  else (setvertcolor $ i ((color 255 255 255) * (1 - (pointSelection $ i))))
    
    -- now composite the color data
    clrstor_array_mod = #()
    for i in 1 to (getnumcpvverts $) do
    (
      if btow.checked then
      (
      append clrstor_array_mod (orig_clr_array[i] * ((color 255 255 255) - SS_clr_array[i]) + SS_clr_array[i]) -- screens value
      
      else
      (
      append clrstor_array_mod (orig_clr_array[i] * SS_clr_array[i] ) -- multiplies value    
    
    for i in 1 to (getnumcpvverts $) do
    (
       setvertcolor $ i clrstor_array_mod[i]   

    update $
  und.enabled = true
  
  catch(messagebox "Failure - no object selected?")
)

on crblk pressed do
(
    try(getvertcolor $ 1)
    catch(defaultVCFaces $)
  try
  (
    if orig_clr_array[1] == undefined then
    (
      for i in 1 to (getnumcpvverts $) do
      (
        append orig_clr_array (getvertcolor $ i) -- store original vertex colors      
    
    if $.modifiers.count != 0 then collapseStack $
    subObjectLevel = 1
    sel_array = getvertselection $
    for i in sel_array do
    (
      setvertcolor $ i (color 0 0 0)
    
    update $
    und.enabled = true  
  catch(messagebox "Failure - no object selected?")
)

on crwt pressed do
(
    try(getvertcolor $ 1)
    catch(defaultVCFaces $)
  try
  (
    if orig_clr_array[1] == undefined then
    (
      for i in 1 to (getnumcpvverts $) do
      (
        append orig_clr_array (getvertcolor $ i) -- store original vertex colors     
    
    if $.modifiers.count != 0 then collapseStack $
    subObjectLevel = 1
    sel_array = getvertselection $
    for i in sel_array do
    (
      setvertcolor $ i (color 255 255 255)
    
    update $
    und.enabled = true  
  catch(messagebox "Failure - no object selected?")
)

on doit pressed do
(
k=#()
r_val = #()
g_val = #()
b_val = #()
rgb_val = #()
clrstor_array = #()
start = timeStamp()
disableSceneRedraw()
try
(
  wht = (color 255 255 255)
  collapseStack $
    -- store original color vertex array
  orig_clr_array = #()
  for i in 1 to (getnumcpvverts $) do
  (
    append orig_clr_array (getvertcolor $ i) -- store original vertex colors
  
  setProgressCancel true
  progressStart "Generating Translucency"
  d = 0
  if ussel.checked then
  (
    sv = for i in $.selectedVerts collect i.index
    for i in 1 to (getnumcpvverts $) do
    (
      if (finditem sv i) != 0 then
      (
        if getprogresscancel() then exit
        clr_array = #()
        dist_array = #() -- array to store distances
        for j in 1 to (getnumcpvverts $) by vskip.value do
        (
          f = (distance (getvert $ i) (getvert $ j))
          if (f < srchrad.value) and (f != 0) then
          (
            append clr_array orig_clr_array[j]
            append dist_array f       
    
        a = getvertcolor $ i
        b = clr_array.count
        c = (color 0 0 0)
        for g in 1 to b do
        (
          c += ((clr_array[g]/b) * (1 - (dist_array[g]^vflf.value/srchrad.value^vflf.value)))
        
        append clrstor_array c
        --setvertcolor $ i (a * (wht - c) + c) -- this 'screens' the new values onto the initial vrtx value
        d += 1
        if mod d 20 == 0 then (progressUpdate (i*100/$.numverts)) -- don't want to update progressbar too often
      
      else append clrstor_array (color 0 0 0)   
  
  else
  (
    for i in 1 to (getnumcpvverts $) do
    (
      if getprogresscancel() then exit
      clr_array = #()
      dist_array = #() -- array to store distances
      for j in 1 to (getnumcpvverts $) by vskip.value do
      (
        f = (distance (getvert $ i) (getvert $ j))
        if (f < srchrad.value) and (f != 0) then
        (
          append clr_array orig_clr_array[j]
          append dist_array f
  
      a = getvertcolor $ i
      b = clr_array.count
      c = (color 0 0 0)
      for g in 1 to b do
      (
        c += ((clr_array[g]/b) * (1 - (dist_array[g]^vflf.value/srchrad.value^vflf.value)))      
      append clrstor_array c
      --setvertcolor $ i (a * (wht - c) + c) -- this 'screens' the new values onto the initial vrtx value
      d += 1
      if mod d 20 == 0 then (progressUpdate (i*100/$.numverts)) -- don't want to update progressbar too often    
  
  progressEnd()
  for k in 1 to clrstor_array.count do
  (
    append r_val clrstor_array[k].r
    append g_val clrstor_array[k].g
    append b_val clrstor_array[k].b  
  append rgb_val (amax r_val)
  append rgb_val (amax g_val)
  append rgb_val (amax b_val)
  clrmax = amax rgb_val
  if clrmax == 0 do clrmax = 255
  mulval = 255/clrmax  
  for i in 1 to (getnumcpvverts $) do
  (
    if solonly.checked then (setvertcolor $ i (clrstor_array[i] * mulval))
    else (setvertcolor $ i (orig_clr_array[i] * (wht - (clrstor_array[i]* mulval)) + (clrstor_array[i] * mulval)))  

update $
)
  catch
  (
    enablesceneredraw()
    redrawviews()  

und.enabled = true
enablesceneredraw()
end = timeStamp()
redrawviews()
Print ((end - start) / 1000.0)
)

on und pressed do -- this is the restore vertex colors button
(
  disableSceneRedraw()
  try
  (
    for i in 1 to (getnumcpvverts $) do
    (
      setVertColor $ i orig_clr_array[i]
    
    update $
    enablesceneredraw()
    redrawviews()
    doit.enabled = true
  
  catch
  (
    enablesceneredraw()
    redrawviews()  
)

on trlncy open do -- some stuff that is probably a waste of time
(
  try ( -- the following so existing stored data is not lost
  if orig_clr_array[1] != undefined then
  (
    if orig_clr_array.count != $.numverts do (orig_clr_array = #()) -- if object selected does not match on open
   -- this simply to see if the array exists with items
  
  catch (orig_clr_array = #()) -- if not, then create as an empty array.
)
)
-- end
if trl != undefined then closerolloutfloater trl
trl = newRolloutFloater "Translucency" 205 452 1000 200
addRollout trlncy trl 

 

效果图。

感谢速联科技、八度网络、九九数据、亿恩科技、群英网络赞助部分带宽!

关于本站 | 联系方式 | 版权声明 | 下载帮助(?) | 网站地图

Copyright 2002-2020 95262.com 【数码资源网】 版权所有 粤ICP备2020128507号-1

本站所有软件来自互联网,版权归原著所有。如有侵权,敬请来信告知 ,我们将及时撤销。