简体   繁体   English

如何正确扩展3Ds Max材质

[英]How do I extend a 3Ds Max material correctly

Basically, I'm just trying to add a few more properties to the "Standard" material in 3Ds Max 9. I've actually managed to accomplish this through max script, but it is breaking our exporter. 基本上,我只是想向3Ds Max 9中的“标准”材料添加更多属性。实际上,我已经设法通过max脚本来完成此操作,但是这破坏了我们的导出器。

The exporter works fine for anything skinned with the normal "Standard" material, but the extended version seems to hide the base class's properties from the exporter. 对于使用普通“标准”材质蒙皮的任何内容,导出器都可以正常工作,但是扩展版本似乎对导出器隐藏了基类的属性。

What I have so far is this: 我到目前为止所拥有的是:


plugin material Standard_WithOutlines
name:"Standard & Outlines"
classID:#(0x73212413, 0x1ca9e3e6)
extends:Standard replaceUI:false version:1
(
    parameters shaderParameters
    (
        diffuse type:#color
        glossiness type:#float
        specular type:#color
        specularLevel type:#float
        selfIllumColor type:#color
        selfIllumAmount type:#float
        opacity type:#float

        on diffuse get val do delegate.diffuse
        on glossiness get val do delegate.glossiness / 100.0
        on specular get val do delegate.specular
        on specularLevel get val do delegate.specularLevel
        on selfIllumColor get val do delegate.selfIllumColor
        on selfIllumAmount get val do delegate.selfIllumAmount
        on opacity get val do delegate.opacity / 100.0

        on diffuse set val do delegate.diffuse = val
        on glossiness set val do delegate.glossiness = val * 100.0
        on specular set val do delegate.specular = val
        on specularLevel set val do delegate.specularLevel = val
        on selfIllumColor set val do delegate.selfIllumColor = val
        on selfIllumAmount set val do delegate.selfIllumAmount = val
        on opacity set val do delegate.opacity = val * 100.0
    )

    parameters MainParams rollout:ExtendedMatRollout
    (
        ShowOutlining type:#boolean animatable:false default:false ui:outline_Enabled
        OutlineColour type:#color animatable:false default:(color 0 0 0) ui:outline_Colour
        OutlineThickness type:#float animatable:false default:5 ui:outline_Thickness
    )

    rollout ExtendedMatRollout "Extended Parameters"
    (
        groupBox outlinegrp "Outlining" pos:[8,0] width:312 height:62
        checkbox outline_Enabled "Enabled" pos:[18,16] width:128 height:16
        colorPicker outline_Colour "Colour:" pos:[160,34] width:56 height:20 enabled:ShowOutlining
        spinner outline_Thickness "Thickness:" pos:[50,36] width:80 height:16 enabled:ShowOutlining range:[0,100,0]
        on outline_Enabled changed state do
        (
            outline_Colour.enabled = state
            outline_Thickness.enabled = state
        )

    )
)

By declaring the variables myself, the exporter could read them, but this didn't actually link to the values being set by the UI. 通过自己声明变量,导出器可以读取它们,但实际上并没有链接到UI设置的值。 To solve that, I used the 'on XXX get/set' events to link to the hidden items. 为了解决这个问题,我使用了“在XXX上获取/设置”事件来链接到隐藏的项目。 So those now work correctly, but the material maps for things like diffuse and specular don't work (which is the only way to texture the thing AFAIK). 因此,这些材质现在可以正常工作,但是诸如漫反射和镜面反射之类的材质贴图不起作用(这是对AFAIK材质进行纹理化的唯一方法)。

How should I be going about adding these couple of settings to a material type, so that it exports all of the data within the 'delegate' class as well (is basic inheritance too much to ask for)? 我应该如何将这两个设置添加到材料类型,以便它也导出“委托”类中的所有数据(基本继承要求太多了)?

Thanks 谢谢

Two possiblities: 两种可能性:

  1. Does your exporter enumerate all the paramblocks? 您的出口商是否列举了所有参数块? I imagine that your parameters in the script will end up in an additional pblock. 我想脚本中的参数将以另一个pblock结尾。 If your exporter just looks at pblock 0 that might be your problem. 如果您的出口商只是看pblock 0,那可能是您的问题。

  2. I haven't seen this usage before where parameters have the same name in the script and the delegate. 在脚本和委托中参数具有相同名称之前,我还没有看到这种用法。 I think you typically are supposed to make new parameters in the script and assign to the delegate ones appropriately, using different names. 我认为通常应该在脚本中创建新参数,并使用不同的名称适当地分配给委托参数。 At least, that's how I've done it. 至少,这就是我做到的方式。

Here's a basic extended shader. 这是一个基本的扩展着色器。 I think the problem you have is that your rollout is not specified for the parameters. 我认为您遇到的问题是未为参数指定推出。 If it's not defined, then you cannot find then, if it cannot find them then exporter get's all buggy. 如果未定义,则找不到,如果找不到它们,则导出器会出现所有错误。

plugin material Matte name:"Matte" classID:#(0x61108483, 0x4d218a72) extends:Standard replaceUI:true version:1
( 
    parameters main rollout:params
    (
        kdColor type:#color default:[90,90,90] ui:mkdColor
        on kdColor set val do delegate.diffuse_color = val
    )

    rollout params "Matte Parameters"
    (
        -- Basic matte parameters
        group "Basic Parameters" (
            colorpicker mkdColor "Diffuse: " across:2
        )

    )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM