/** * GameLib.D3.API.Material * @param id * @param name * @param materialType * @param parentEntity * @param parentMeshes * @param alphaTest * @param blendDst * @param blendDstAlpha * @param blendEquation * @param blendEquationAlpha * @param blending * @param blendSrc * @param blendSrcAlpha * @param clipIntersection * @param clippingPlanes * @param clipShadows * @param colorWrite * @param customDepthMaterial * @param customDistanceMaterial * @param defines * @param depthFunc * @param depthTest * @param depthWrite * @param fog * @param lights * @param opacity * @param overdraw * @param polygonOffset * @param polygonOffsetFactor * @param polygonOffsetUnits * @param precision * @param premultipliedAlpha * @param dithering * @param flatShading * @param side * @param transparent * @param vertexColors * @param visible * @constructor */ GameLib.D3.API.Material = function( id, name, materialType, parentEntity, parentMeshes, alphaTest, blendDst, blendDstAlpha, blendEquation, blendEquationAlpha, blending, blendSrc, blendSrcAlpha, clipIntersection, clippingPlanes, clipShadows, colorWrite, customDepthMaterial, customDistanceMaterial, defines, depthFunc, depthTest, depthWrite, fog, lights, opacity, overdraw, polygonOffset, polygonOffsetFactor, polygonOffsetUnits, precision, premultipliedAlpha, dithering, flatShading, side, transparent, vertexColors, visible ) { if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Material (' + this.id + ')'; } this.name = name; if (GameLib.Utils.UndefinedOrNull(materialType)) { materialType = GameLib.D3.API.Material.MATERIAL_TYPE_NONE; } this.materialType = materialType; if (GameLib.Utils.UndefinedOrNull(parentMeshes)) { parentMeshes = []; } this.parentMeshes = parentMeshes; if (GameLib.Utils.UndefinedOrNull(alphaTest)) { alphaTest = 0; } this.alphaTest = alphaTest; if (GameLib.Utils.UndefinedOrNull(blendDst)) { blendDst = GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR; } this.blendDst = blendDst; if (GameLib.Utils.UndefinedOrNull(blendDstAlpha)) { blendDstAlpha = null; } this.blendDstAlpha = blendDstAlpha; if (GameLib.Utils.UndefinedOrNull(blendEquation)) { blendEquation = GameLib.D3.API.Material.TYPE_ADD_EQUATION; } this.blendEquation = blendEquation; if (GameLib.Utils.UndefinedOrNull(blendEquationAlpha)) { blendEquationAlpha = null; } this.blendEquationAlpha = blendEquationAlpha; if (GameLib.Utils.UndefinedOrNull(blending)) { blending = GameLib.D3.API.Material.TYPE_NORMAL_BLENDING; } this.blending = blending; if (GameLib.Utils.UndefinedOrNull(blendSrc)) { blendSrc = GameLib.D3.API.Material.TYPE_SRC_ALPHA_FACTOR; } this.blendSrc = blendSrc; if (GameLib.Utils.UndefinedOrNull(blendSrcAlpha)) { blendSrcAlpha = null; } this.blendSrcAlpha = blendSrcAlpha; if (GameLib.Utils.UndefinedOrNull(clipIntersection)) { clipIntersection = false; } this.clipIntersection = clipIntersection; if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) { clippingPlanes = []; } this.clippingPlanes = clippingPlanes; if (GameLib.Utils.UndefinedOrNull(clipShadows)) { clipShadows = false; } this.clipShadows = clipShadows; if (GameLib.Utils.UndefinedOrNull(colorWrite)) { colorWrite = true; } this.colorWrite = colorWrite; if (GameLib.Utils.UndefinedOrNull(customDepthMaterial)) { customDepthMaterial = null; } this.customDepthMaterial = customDepthMaterial; if (GameLib.Utils.UndefinedOrNull(customDistanceMaterial)) { customDistanceMaterial = null; } this.customDistanceMaterial = customDistanceMaterial; if (GameLib.Utils.UndefinedOrNull(defines)) { defines = null; } this.defines = defines; if (GameLib.Utils.UndefinedOrNull(depthFunc)) { depthFunc = GameLib.D3.API.Material.TYPE_LESS_EQUAL_DEPTH; } this.depthFunc = depthFunc; if (GameLib.Utils.UndefinedOrNull(depthTest)) { depthTest = true; } this.depthTest = depthTest; if (GameLib.Utils.UndefinedOrNull(depthWrite)) { depthWrite = true; } this.depthWrite = depthWrite; if (GameLib.Utils.UndefinedOrNull(fog)) { fog = true; } this.fog = fog; if (GameLib.Utils.UndefinedOrNull(lights)) { if (this.materialType === GameLib.D3.API.Material.MATERIAL_TYPE_BASIC) { lights = false; } else { lights = true; } } this.lights = lights; if (GameLib.Utils.UndefinedOrNull(opacity)) { opacity = 1.0; } this.opacity = opacity; if (GameLib.Utils.UndefinedOrNull(overdraw)) { overdraw = 0; } this.overdraw = overdraw; if (GameLib.Utils.UndefinedOrNull(polygonOffset)) { polygonOffset = false; } this.polygonOffset = polygonOffset; if (GameLib.Utils.UndefinedOrNull(polygonOffsetFactor)) { polygonOffsetFactor = 0; } this.polygonOffsetFactor = polygonOffsetFactor; if (GameLib.Utils.UndefinedOrNull(polygonOffsetUnits)) { polygonOffsetUnits = 0; } this.polygonOffsetUnits = polygonOffsetUnits; if (GameLib.Utils.UndefinedOrNull(precision)) { precision = null; } this.precision = precision; if (GameLib.Utils.UndefinedOrNull(premultipliedAlpha)) { premultipliedAlpha = false; } this.premultipliedAlpha = premultipliedAlpha; if (GameLib.Utils.UndefinedOrNull(dithering)) { dithering = false; } this.dithering = dithering; if (GameLib.Utils.UndefinedOrNull(flatShading)) { flatShading = false; } this.flatShading = flatShading; if (GameLib.Utils.UndefinedOrNull(side)) { side = GameLib.D3.API.Material.TYPE_FRONT_SIDE; } this.side = side; if (GameLib.Utils.UndefinedOrNull(transparent)) { transparent = false; } this.transparent = transparent; if (GameLib.Utils.UndefinedOrNull(vertexColors)) { vertexColors = GameLib.D3.API.Material.TYPE_NO_COLORS; } this.vertexColors = vertexColors; if (GameLib.Utils.UndefinedOrNull(visible)) { visible = true; } this.visible = visible; var componentType = null; switch (this.materialType) { case GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD : componentType = GameLib.Component.MATERIAL_STANDARD; break; case GameLib.D3.API.Material.MATERIAL_TYPE_BASIC : componentType = GameLib.Component.MATERIAL_BASIC; break; default : throw new Error('unhandled material type: ' + this.materialType); } this.needsUpdate = false; GameLib.API.Component.call( this, componentType, parentEntity ); }; GameLib.D3.API.Material.prototype = Object.create(GameLib.API.Component.prototype); GameLib.D3.API.Material.prototype.constructor = GameLib.D3.API.Material; /** * Combine Method * @type {number} */ GameLib.D3.API.Material.COMBINE_MULTIPLY_OPERATION = 0; GameLib.D3.API.Material.COMBINE_MIX_OPERATION = 1; GameLib.D3.API.Material.COMBINE_ADD_OPERATION = 2; /** * Vertex Color Mode * @type {number} */ GameLib.D3.API.Material.TYPE_NO_COLORS = 0; GameLib.D3.API.Material.TYPE_FACE_COLORS = 1; GameLib.D3.API.Material.TYPE_VERTEX_COLORS = 2; /** * Blending Mode * @type {number} */ GameLib.D3.API.Material.TYPE_NO_BLENDING = 0; GameLib.D3.API.Material.TYPE_NORMAL_BLENDING = 1; GameLib.D3.API.Material.TYPE_ADDITIVE_BLENDING = 2; GameLib.D3.API.Material.TYPE_SUBTRACTIVE_BLENDING = 3; GameLib.D3.API.Material.TYPE_MULTIPLY_BLENDING = 4; GameLib.D3.API.Material.TYPE_CUSTOM_BLENDING = 5; /** * Blend Source and Destination * @type {number} */ GameLib.D3.API.Material.TYPE_ZERO_FACTOR = 200; GameLib.D3.API.Material.TYPE_ONE_FACTOR = 201; GameLib.D3.API.Material.TYPE_SRC_COLOR_FACTOR = 202; GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR = 203; GameLib.D3.API.Material.TYPE_SRC_ALPHA_FACTOR = 204; GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR = 205; GameLib.D3.API.Material.TYPE_DST_ALPHA_FACTOR = 206; GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR = 207; GameLib.D3.API.Material.TYPE_DST_COLOR_FACTOR = 208; GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR = 209; GameLib.D3.API.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR = 210; /** * Blend Operation * @type {number} */ GameLib.D3.API.Material.TYPE_ADD_EQUATION = 100; GameLib.D3.API.Material.TYPE_SUBTRACT_EQUATION = 101; GameLib.D3.API.Material.TYPE_REVERSE_SUBTRACT_EQUATION = 102; GameLib.D3.API.Material.TYPE_MIN_EQUATION = 103; GameLib.D3.API.Material.TYPE_MAX_EQUATION = 104; /** * Depth Function * @type {number} */ GameLib.D3.API.Material.TYPE_NEVER_DEPTH = 0; GameLib.D3.API.Material.TYPE_ALWAYS_DEPTH = 1; GameLib.D3.API.Material.TYPE_LESS_DEPTH = 2; GameLib.D3.API.Material.TYPE_LESS_EQUAL_DEPTH = 3; GameLib.D3.API.Material.TYPE_EQUAL_DEPTH = 4; GameLib.D3.API.Material.TYPE_GREATER_EQUAL_DEPTH = 5; GameLib.D3.API.Material.TYPE_GREATER_DEPTH = 6; GameLib.D3.API.Material.TYPE_NOT_EQUAL_DEPTH = 7; /** * Culling Mode * @type {number} */ GameLib.D3.API.Material.TYPE_FRONT_SIDE = 0; GameLib.D3.API.Material.TYPE_BACK_SIDE = 1; GameLib.D3.API.Material.TYPE_DOUBLE_SIDE = 2; /** * Shading Type * @type {number} */ GameLib.D3.API.Material.TYPE_FLAT_SHADING = 1; GameLib.D3.API.Material.TYPE_SMOOTH_SHADING = 2; /** * Material Type * @type {string} */ GameLib.D3.API.Material.MATERIAL_TYPE_NONE = 0x0; GameLib.D3.API.Material.MATERIAL_TYPE_LINE_BASIC = 0x1; GameLib.D3.API.Material.MATERIAL_TYPE_LINE_DASHED = 0x2; GameLib.D3.API.Material.MATERIAL_TYPE_BASIC = 0x3; GameLib.D3.API.Material.MATERIAL_TYPE_DEPTH = 0x4; GameLib.D3.API.Material.MATERIAL_TYPE_LAMBERT = 0x5; GameLib.D3.API.Material.MATERIAL_TYPE_NORMAL = 0x6; GameLib.D3.API.Material.MATERIAL_TYPE_PHONG = 0x7; GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD = 0x8; GameLib.D3.API.Material.MATERIAL_TYPE_POINTS = 0x9; GameLib.D3.API.Material.MATERIAL_TYPE_SPRITE = 0xa; GameLib.D3.API.Material.MATERIAL_TYPE_TOON = 0xb; GameLib.D3.API.Material.MATERIAL_TYPE_SHADER = 0xc; /** * Line Cap * @type {number} */ GameLib.D3.API.Material.LINE_CAP_BUTT = 0x1;//'butt'; GameLib.D3.API.Material.LINE_CAP_ROUND = 0x2;//'round'; GameLib.D3.API.Material.LINE_CAP_SQUARE = 0x3;//'square'; /** * Line Join * @type {number} */ GameLib.D3.API.Material.LINE_JOIN_ROUND = 0x1;//'round'; GameLib.D3.API.Material.LINE_JOIN_BEVEL = 0x2;//'bevel'; GameLib.D3.API.Material.LINE_JOIN_MITER = 0x3;//'miter';