385 lines
11 KiB
JavaScript
385 lines
11 KiB
JavaScript
/**
|
|
* R3.D3.API.Material
|
|
* @param apiComponent
|
|
*
|
|
* @property alphaTest
|
|
* @property blendDst
|
|
* @property blendDstAlpha
|
|
* @property blendEquation
|
|
* @property blendEquationAlpha
|
|
* @property blending
|
|
* @property blendSrc
|
|
* @property blendSrcAlpha
|
|
* @property clipIntersection
|
|
* @property clippingPlanes
|
|
* @property clipShadows
|
|
* @property colorWrite
|
|
* @property defines
|
|
* @property depthFunc
|
|
* @property depthTest
|
|
* @property depthWrite
|
|
* @property dithering
|
|
* @property flatShading
|
|
* @property fog
|
|
* @property lights
|
|
* @property opacity
|
|
* @property overdraw
|
|
* @property polygonOffset
|
|
* @property polygonOffsetFactor
|
|
* @property polygonOffsetUnits
|
|
* @property precision
|
|
* @property premultipliedAlpha
|
|
* @property side
|
|
* @property stencilWrite
|
|
* @property stencilFunc
|
|
* @property stencilRef
|
|
* @property stencilMask
|
|
* @property stencilFail
|
|
* @property stencilZFail
|
|
* @property stencilZPass
|
|
* @property transparent
|
|
* @property vertexColors
|
|
* @property visible
|
|
*
|
|
* @constructor
|
|
*/
|
|
R3.D3.API.Material = function(
|
|
apiComponent
|
|
) {
|
|
|
|
__API_COMPONENT__;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.alphaTest)) {
|
|
apiComponent.alphaTest = 0;
|
|
}
|
|
this.alphaTest = apiComponent.alphaTest;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.blendDst)) {
|
|
apiComponent.blendDst = R3.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR;
|
|
}
|
|
this.blendDst = apiComponent.blendDst;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.blendDstAlpha)) {
|
|
apiComponent.blendDstAlpha = null;
|
|
}
|
|
this.blendDstAlpha = apiComponent.blendDstAlpha;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.blendEquation)) {
|
|
apiComponent.blendEquation = R3.D3.API.Material.TYPE_ADD_EQUATION;
|
|
}
|
|
this.blendEquation = apiComponent.blendEquation;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.blendEquationAlpha)) {
|
|
apiComponent.blendEquationAlpha = null;
|
|
}
|
|
this.blendEquationAlpha = apiComponent.blendEquationAlpha;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.blending)) {
|
|
apiComponent.blending = R3.D3.API.Material.TYPE_NORMAL_BLENDING;
|
|
}
|
|
this.blending = apiComponent.blending;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.blendSrc)) {
|
|
apiComponent.blendSrc = R3.D3.API.Material.TYPE_SRC_ALPHA_FACTOR;
|
|
}
|
|
this.blendSrc = apiComponent.blendSrc;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.blendSrcAlpha)) {
|
|
apiComponent.blendSrcAlpha = null;
|
|
}
|
|
this.blendSrcAlpha = apiComponent.blendSrcAlpha;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.clipIntersection)) {
|
|
apiComponent.clipIntersection = false;
|
|
}
|
|
this.clipIntersection = apiComponent.clipIntersection;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.clippingPlanes)) {
|
|
apiComponent.clippingPlanes = [];
|
|
}
|
|
this.clippingPlanes = apiComponent.clippingPlanes;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.clipShadows)) {
|
|
apiComponent.clipShadows = false;
|
|
}
|
|
this.clipShadows = apiComponent.clipShadows;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.colorWrite)) {
|
|
apiComponent.colorWrite = true;
|
|
}
|
|
this.colorWrite = apiComponent.colorWrite;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.defines)) {
|
|
apiComponent.defines = null;
|
|
}
|
|
this.defines = apiComponent.defines;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.depthFunc)) {
|
|
apiComponent.depthFunc = R3.D3.API.Material.TYPE_LESS_EQUAL_DEPTH;
|
|
}
|
|
this.depthFunc = apiComponent.depthFunc;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.depthTest)) {
|
|
apiComponent.depthTest = true;
|
|
}
|
|
this.depthTest = apiComponent.depthTest;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.depthWrite)) {
|
|
apiComponent.depthWrite = true;
|
|
}
|
|
this.depthWrite = apiComponent.depthWrite;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.fog)) {
|
|
apiComponent.fog = true;
|
|
}
|
|
this.fog = apiComponent.fog;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.lights)) {
|
|
|
|
if (
|
|
this instanceof R3.D3.Material.Basic ||
|
|
this instanceof R3.D3.Material.Shader ||
|
|
this instanceof R3.D3.Material.Shader.Raw ||
|
|
this instanceof R3.D3.Material.Points
|
|
) {
|
|
apiComponent.lights = false;
|
|
} else {
|
|
apiComponent.lights = true;
|
|
}
|
|
|
|
}
|
|
this.lights = apiComponent.lights;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.opacity)) {
|
|
apiComponent.opacity = 1.0;
|
|
}
|
|
this.opacity = apiComponent.opacity;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.overdraw)) {
|
|
apiComponent.overdraw = 0;
|
|
}
|
|
this.overdraw = apiComponent.overdraw;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.polygonOffset)) {
|
|
apiComponent.polygonOffset = false;
|
|
}
|
|
this.polygonOffset = apiComponent.polygonOffset;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.polygonOffsetFactor)) {
|
|
apiComponent.polygonOffsetFactor = 0;
|
|
}
|
|
this.polygonOffsetFactor = apiComponent.polygonOffsetFactor;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.polygonOffsetUnits)) {
|
|
apiComponent.polygonOffsetUnits = 0;
|
|
}
|
|
this.polygonOffsetUnits = apiComponent.polygonOffsetUnits;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.precision)) {
|
|
apiComponent.precision = null;
|
|
}
|
|
this.precision = apiComponent.precision;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.premultipliedAlpha)) {
|
|
apiComponent.premultipliedAlpha = false;
|
|
}
|
|
this.premultipliedAlpha = apiComponent.premultipliedAlpha;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.dithering)) {
|
|
apiComponent.dithering = false;
|
|
}
|
|
this.dithering = apiComponent.dithering;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.flatShading)) {
|
|
apiComponent.flatShading = false;
|
|
}
|
|
this.flatShading = apiComponent.flatShading;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.side)) {
|
|
apiComponent.side = R3.D3.API.Material.TYPE_FRONT_SIDE;
|
|
}
|
|
this.side = apiComponent.side;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.stencilWrite)) {
|
|
apiComponent.stencilWrite = false;
|
|
}
|
|
this.stencilWrite = apiComponent.stencilWrite;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.stencilFunc)) {
|
|
apiComponent.stencilFunc = R3.D3.API.Material.STENCIL_FUNC_ALWAYS;
|
|
}
|
|
this.stencilFunc = apiComponent.stencilFunc;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.stencilRef)) {
|
|
apiComponent.stencilRef = 0;
|
|
}
|
|
this.stencilRef = apiComponent.stencilRef;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.stencilMask)) {
|
|
apiComponent.stencilMask = 0xFF;
|
|
}
|
|
this.stencilMask = apiComponent.stencilMask;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.stencilFail)) {
|
|
apiComponent.stencilFail = R3.D3.API.Material.STENCIL_OPERATION_KEEP;
|
|
}
|
|
this.stencilFail = apiComponent.stencilFail;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.stencilZFail)) {
|
|
apiComponent.stencilZFail = R3.D3.API.Material.STENCIL_OPERATION_KEEP;
|
|
}
|
|
this.stencilZFail = apiComponent.stencilZFail;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.stencilZPass)) {
|
|
apiComponent.stencilZPass = R3.D3.API.Material.STENCIL_OPERATION_KEEP;
|
|
}
|
|
this.stencilZPass = apiComponent.stencilZPass;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.transparent)) {
|
|
apiComponent.transparent = false;
|
|
}
|
|
this.transparent = apiComponent.transparent;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.vertexColors)) {
|
|
apiComponent.vertexColors = R3.D3.API.Material.TYPE_NO_COLORS;
|
|
}
|
|
this.vertexColors = apiComponent.vertexColors;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.visible)) {
|
|
apiComponent.visible = true;
|
|
}
|
|
this.visible = apiComponent.visible;
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiComponent.needsUpdate)) {
|
|
apiComponent.needsUpdate = false;
|
|
}
|
|
this.needsUpdate = apiComponent.needsUpdate;
|
|
|
|
};
|
|
|
|
|
|
R3.D3.API.Material.prototype = Object.create(R3.API.Component.prototype);
|
|
R3.D3.API.Material.prototype.constructor = R3.D3.API.Material;
|
|
|
|
/**
|
|
* Combine Method
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.COMBINE_MULTIPLY_OPERATION = 0;
|
|
R3.D3.API.Material.COMBINE_MIX_OPERATION = 1;
|
|
R3.D3.API.Material.COMBINE_ADD_OPERATION = 2;
|
|
|
|
/**
|
|
* Vertex Color Mode
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.TYPE_NO_COLORS = 0;
|
|
R3.D3.API.Material.TYPE_FACE_COLORS = 1;
|
|
R3.D3.API.Material.TYPE_VERTEX_COLORS = 2;
|
|
|
|
/**
|
|
* Blending Mode
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.TYPE_NO_BLENDING = 0;
|
|
R3.D3.API.Material.TYPE_NORMAL_BLENDING = 1;
|
|
R3.D3.API.Material.TYPE_ADDITIVE_BLENDING = 2;
|
|
R3.D3.API.Material.TYPE_SUBTRACTIVE_BLENDING = 3;
|
|
R3.D3.API.Material.TYPE_MULTIPLY_BLENDING = 4;
|
|
R3.D3.API.Material.TYPE_CUSTOM_BLENDING = 5;
|
|
|
|
/**
|
|
* Blend Source and Destination
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.TYPE_ZERO_FACTOR = 200;
|
|
R3.D3.API.Material.TYPE_ONE_FACTOR = 201;
|
|
R3.D3.API.Material.TYPE_SRC_COLOR_FACTOR = 202;
|
|
R3.D3.API.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR = 203;
|
|
R3.D3.API.Material.TYPE_SRC_ALPHA_FACTOR = 204;
|
|
R3.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR = 205;
|
|
R3.D3.API.Material.TYPE_DST_ALPHA_FACTOR = 206;
|
|
R3.D3.API.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR = 207;
|
|
R3.D3.API.Material.TYPE_DST_COLOR_FACTOR = 208;
|
|
R3.D3.API.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR = 209;
|
|
R3.D3.API.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR = 210;
|
|
|
|
/**
|
|
* Blend Operation
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.TYPE_ADD_EQUATION = 100;
|
|
R3.D3.API.Material.TYPE_SUBTRACT_EQUATION = 101;
|
|
R3.D3.API.Material.TYPE_REVERSE_SUBTRACT_EQUATION = 102;
|
|
R3.D3.API.Material.TYPE_MIN_EQUATION = 103;
|
|
R3.D3.API.Material.TYPE_MAX_EQUATION = 104;
|
|
|
|
/**
|
|
* Depth Function
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.TYPE_NEVER_DEPTH = 0;
|
|
R3.D3.API.Material.TYPE_ALWAYS_DEPTH = 1;
|
|
R3.D3.API.Material.TYPE_LESS_DEPTH = 2;
|
|
R3.D3.API.Material.TYPE_LESS_EQUAL_DEPTH = 3;
|
|
R3.D3.API.Material.TYPE_EQUAL_DEPTH = 4;
|
|
R3.D3.API.Material.TYPE_GREATER_EQUAL_DEPTH = 5;
|
|
R3.D3.API.Material.TYPE_GREATER_DEPTH = 6;
|
|
R3.D3.API.Material.TYPE_NOT_EQUAL_DEPTH = 7;
|
|
|
|
/**
|
|
* Culling Mode
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.TYPE_FRONT_SIDE = 0;
|
|
R3.D3.API.Material.TYPE_BACK_SIDE = 1;
|
|
R3.D3.API.Material.TYPE_DOUBLE_SIDE = 2;
|
|
|
|
/**
|
|
* Shading Type
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.TYPE_FLAT_SHADING = 1;
|
|
R3.D3.API.Material.TYPE_SMOOTH_SHADING = 2;
|
|
|
|
/**
|
|
* Line Cap
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.LINE_CAP_BUTT = 0x1;//'butt';
|
|
R3.D3.API.Material.LINE_CAP_ROUND = 0x2;//'round';
|
|
R3.D3.API.Material.LINE_CAP_SQUARE = 0x3;//'square';
|
|
|
|
/**
|
|
* Line Join
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.LINE_JOIN_ROUND = 0x1;//'round';
|
|
R3.D3.API.Material.LINE_JOIN_BEVEL = 0x2;//'bevel';
|
|
R3.D3.API.Material.LINE_JOIN_MITER = 0x3;//'miter';
|
|
|
|
/**
|
|
* Stencil Functions
|
|
*/
|
|
R3.D3.API.Material.STENCIL_FUNC_NEVER = 512;
|
|
R3.D3.API.Material.STENCIL_FUNC_LESS = 513;
|
|
R3.D3.API.Material.STENCIL_FUNC_EQUAL = 514;
|
|
R3.D3.API.Material.STENCIL_FUNC_LESS_EQUAL = 515;
|
|
R3.D3.API.Material.STENCIL_FUNC_GREATER = 516;
|
|
R3.D3.API.Material.STENCIL_FUNC_NOT_EQUAL = 517;
|
|
R3.D3.API.Material.STENCIL_FUNC_GREATER_EQUAL = 518;
|
|
R3.D3.API.Material.STENCIL_FUNC_ALWAYS = 519;
|
|
|
|
/**
|
|
* Stencil Operations
|
|
* @type {number}
|
|
*/
|
|
R3.D3.API.Material.STENCIL_OPERATION_ZERO = 0;
|
|
R3.D3.API.Material.STENCIL_OPERATION_KEEP = 7680;
|
|
R3.D3.API.Material.STENCIL_OPERATION_REPLACE = 7681;
|
|
R3.D3.API.Material.STENCIL_OPERATION_INCREMENT = 7682;
|
|
R3.D3.API.Material.STENCIL_OPERATION_DECREMENT = 7683;
|
|
R3.D3.API.Material.STENCIL_OPERATION_INCREMENT_WRAP = 34055;
|
|
R3.D3.API.Material.STENCIL_OPERATION_DECREMENT_WRAP = 34056;
|
|
R3.D3.API.Material.STENCIL_OPERATION_INVERT = 5386;
|