材质([name])

材质的抽象基类。

材质描述了对象[page:Object objects]的外观。它们的定义方式与渲染器无关, 因此,如果您决定使用不同的渲染器,不必重写材质。

所有其他材质类型都继承了以下属性和方法(尽管它们可能具有不同的默认值)。

构造函数(Constructor)

[name]()

该方法创建一个通用材质。

属性(Properties)

[property:Float alphaTest]

设置运行alphaTest时要使用的alpha值。如果不透明度低于此值,则不会渲染材质。默认值为*0*。

[property:Float alphaToCoverage]

Enables alpha to coverage. Can only be used with MSAA-enabled contexts (meaning when the renderer was created with *antialias* parameter set to *true*). Default is *false*.

[property:Integer blendDst]

混合目标。默认值为[page:CustomBlendingEquation OneMinusSrcAlphaFactor]。 目标因子所有可能的取值请参阅[page:CustomBlendingEquation constants]。 必须将材质的[page:Constant blending]设置为[page:Materials CustomBlending]才能生效。

[property:Integer blendDstAlpha]

[page:.blendDst]的透明度。 默认值为 *null*.

[property:Integer blendEquation]

使用混合时所采用的混合方程式。默认值为[page:CustomBlendingEquation AddEquation]。 混合方程式所有可能的取值请参阅[page:CustomBlendingEquation constants]。 必须将材质的[page:Constant blending]设置为[page:Materials CustomBlending]才能生效。

[property:Integer blendEquationAlpha]

[page:.blendEquation] 的透明度. 默认值为 *null*.

[property:Blending blending]

在使用此材质显示对象时要使用何种混合。
必须将其设置为[page:Materials CustomBlending]才能使用自定义[page:Constant blendSrc], [page:Constant blendDst] 或者 [page:Constant blendEquation]。 混合模式所有可能的取值请参阅[page:Materials constants]。默认值为[page:Materials NormalBlending]。

[property:Integer blendSrc]

混合源。默认值为[page:CustomBlendingEquation SrcAlphaFactor]。 源因子所有可能的取值请参阅[page:CustomBlendingEquation constants]。
必须将材质的[page:Constant blending]设置为[page:Materials CustomBlending]才能生效。

[property:Integer blendSrcAlpha]

[page:.blendSrc]的透明度。 默认值为 *null*.

[property:Boolean clipIntersection]

更改剪裁平面的行为,以便仅剪切其交叉点,而不是它们的并集。默认值为 *false*。

[property:Array clippingPlanes]

用户定义的剪裁平面,在世界空间中指定为THREE.Plane对象。这些平面适用于所有使用此材质的对象。空间中与平面的有符号距离为负的点被剪裁(未渲染)。 这需要[page:WebGLRenderer.localClippingEnabled]为*true*。 示例请参阅[example:webgl_clipping_intersection WebGL / clipping /intersection]。默认值为 *null*。

[property:Boolean clipShadows]

定义是否根据此材质上指定的剪裁平面剪切阴影。默认值为 *false*。

[property:Boolean colorWrite]

是否渲染材质的颜色。 这可以与网格的[page:Integer renderOrder]属性结合使用,以创建遮挡其他对象的不可见对象。默认值为*true*。

[property:Object defines]

注入shader的自定义对象。 以键值对形式的对象传递,{ MY_CUSTOM_DEFINE: '' , PI2: Math.PI * 2 }。 这些键值对在顶点和片元着色器中定义。默认值为*undefined*。

[property:Integer depthFunc]

使用何种深度函数。默认为[page:Materials LessEqualDepth]。 深度模式所有可能的取值请查阅[page:Materials constants]。

[property:Boolean depthTest]

是否在渲染此材质时启用深度测试。默认为 *true*。

[property:Boolean depthWrite]

渲染此材质是否对深度缓冲区有任何影响。默认为*true*。

在绘制2D叠加时,将多个事物分层在一起而不创建z-index时,禁用深度写入会很有用。

[property:Number format]

When this property is set to [page:Textures THREE.RGBFormat], the material is considered to be opaque and alpha values are ignored. Default is [page:Textures THREE.RGBAFormat].

[property:Boolean stencilWrite]

Whether stencil operations are performed against the stencil buffer. In order to perform writes or comparisons against the stencil buffer this value must be *true*. Default is *false*.

[property:Integer stencilWriteMask]

The bit mask to use when writing to the stencil buffer. Default is *0xFF*.

[property:Integer stencilFunc]

The stencil comparison function to use. Default is [page:Materials AlwaysStencilFunc]. See stencil function [page:Materials constants] for all possible values.

[property:Integer stencilRef]

The value to use when performing stencil comparisons or stencil operations. Default is *0*.

[property:Integer stencilFuncMask]

The bit mask to use when comparing against the stencil buffer. Default is *0xFF*.

[property:Integer stencilFail]

Which stencil operation to perform when the comparison function returns false. Default is [page:Materials KeepStencilOp]. See the stencil operations [page:Materials constants] for all possible values.

[property:Integer stencilZFail]

Which stencil operation to perform when the comparison function returns true but the depth test fails. Default is [page:Materials KeepStencilOp]. See the stencil operations [page:Materials constants] for all possible values.

[property:Integer stencilZPass]

Which stencil operation to perform when the comparison function returns true and the depth test passes. Default is [page:Materials KeepStencilOp]. See the stencil operations [page:Materials constants] for all possible values.

[property:Boolean fog]

材质是否受雾影响。默认为*true*。

[property:Integer id]

此材质实例的唯一编号。

[property:String name]

对象的可选名称(不必是唯一的)。默认值为空字符串。

[property:Boolean needsUpdate]

指定需要重新编译材质。

[property:Float opacity]

在0.0 - 1.0的范围内的浮点数,表明材质的透明度。值*0.0*表示完全透明,*1.0*表示完全不透明。
如果材质的[page:Boolean transparent]属性未设置为*true*,则材质将保持完全不透明,此值仅影响其颜色。 默认值为*1.0*。

[property:Boolean polygonOffset]

是否使用多边形偏移。默认值为*false*。这对应于WebGL的*GL_POLYGON_OFFSET_FILL*功能。

[property:Integer polygonOffsetFactor]

设置多边形偏移系数。默认值为*0*。

[property:Integer polygonOffsetUnits]

设置多边形偏移单位。默认值为*0*。

[property:String precision]

重写此材质渲染器的默认精度。可以是"*highp*", "*mediump*" 或 "*lowp*"。默认值为*null*。

[property:Boolean premultipliedAlpha]

是否预乘alpha(透明度)值。有关差异的示例,请参阅[Example:webgl_materials_physical_transmission WebGL / Materials / Physical / Transmission]。 默认值为*false*。

[property:Boolean dithering]

是否对颜色应用抖动以消除条带的外观。默认值为 *false*。

[property:Integer shadowSide]

定义投影的面。设置时,可以是[page:Materials THREE.FrontSide], [page:Materials THREE.BackSide], 或[page:Materials]。默认值为 *null*。
如果为*null*, 则面投射阴影确定如下:

[page:Material.side] Side casting shadows
THREE.FrontSide 背面
THREE.BackSide 前面
THREE.DoubleSide 双面

[property:Integer side]

定义将要渲染哪一面 - 正面,背面或两者。 默认为[page:Materials THREE.FrontSide]。其他选项有[page:Materials THREE.BackSide]和[page:Materials THREE.DoubleSide]。

[property:Boolean toneMapped]

Defines whether this material is tone mapped according to the renderer's [page:WebGLRenderer.toneMapping toneMapping] setting. Default is *true*.

[property:Boolean transparent]

定义此材质是否透明。这对渲染有影响,因为透明对象需要特殊处理,并在非透明对象之后渲染。
设置为true时,通过设置材质的[page:Float opacity]属性来控制材质透明的程度。
默认值为*false*。

[property:String type]

值是字符串'Material'。不应该被更改,并且可以用于在场景中查找此类型的所有对象。

[property:String uuid]

此材质实例的[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID],会自动分配,不应该被更改。

[property:Integer version]

This starts at *0* and counts how many times [property:Boolean needsUpdate] is set to *true*.

[property:Boolean vertexColors]

是否使用顶点着色。默认值为false。

[property:Boolean visible]

此材质是否可见。默认为*true*。

[property:Object userData]

一个对象,可用于存储有关Material的自定义数据。它不应该包含对函数的引用,因为这些函数不会被克隆。

方法(Methods)

[page:EventDispatcher EventDispatcher] 方法在此类中可用。

[method:Material clone]( )

返回与此材质具有相同参数的新材质。

[method:this copy]( [param:material material] )

将被传入材质中的参数复制到此材质中。

[method:undefined dispose]()

处理材质。材质的纹理不会被处理。需要通过[page:Texture Texture]处理。

[method:undefined onBeforeCompile]( [param:Shader shader], [param:WebGLRenderer renderer] )

在编译shader程序之前立即执行的可选回调。此函数使用shader源码作为参数。用于修改内置材质。

Unlike properties, the callback is not supported by [page:Material.clone .clone](), [page:Material.copy .copy]() and [page:Material.toJSON .toJSON]().

[method:String customProgramCacheKey]()

In case onBeforeCompile is used, this callback can be used to identify values of settings used in onBeforeCompile, so three.js can reuse a cached shader or recompile the shader for this material as needed.

For example, if onBeforeCompile contains a conditional statement like:
if ( black ) { shader.fragmentShader = shader.fragmentShader.replace('gl_FragColor = vec4(1)', 'gl_FragColor = vec4(0)') } then customProgramCacheKey should be set like this:
material.customProgramCacheKey = function() { return black ? '1' : '0'; }

Unlike properties, the callback is not supported by [page:Material.clone .clone](), [page:Material.copy .copy]() and [page:Material.toJSON .toJSON]().

[method:undefined setValues]( [param:Object values] )

values -- 具有参数的容器。 根据*values*设置属性。

[method:Object toJSON]( [param:Object meta] )

meta -- 包含有元数据的对象,例如该对象的纹理或图片。 将material对象转换为 three.js [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format](three.js JSON 物体/场景格式)。

源码(Source)

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]