r3-legacy/src/game-lib-d3-api-material.js

405 lines
9.6 KiB
JavaScript
Raw Normal View History

2016-11-29 12:54:25 +01:00
/**
* Raw material API object - should always correspond with the Material Schema
* @param id
* @param materialType
* @param name
* @param opacity
* @param side
* @param transparent
* @param maps
* @param specular
* @param lightMapIntensity
* @param aoMapIntensity
* @param color
* @param emissive
* @param emissiveIntensity
* @param combine
* @param shininess
* @param reflectivity
* @param refractionRatio
* @param fog
* @param wireframe
* @param wireframeLineWidth
* @param wireframeLineCap
* @param wireframeLineJoin
* @param vertexColors
* @param skinning
* @param morphTargets
* @param morphNormals
* @param lineWidth
* @param lineCap
* @param lineJoin
* @param dashSize
* @param gapWidth
* @param blending
* @param blendSrc
* @param blendDst
* @param blendEquation
* @param depthTest
* @param depthFunc
* @param depthWrite
* @param polygonOffset
* @param polygonOffsetFactor
* @param polygonOffsetUnits
* @param alphaTest
* @param clippingPlanes
* @param clipShadows
* @param visible
* @param overdraw
* @param shading
* @param bumpScale
* @param normalScale
* @param displacementScale
* @param displacementBias
* @param roughness
* @param metalness
* @param pointSize
* @param pointSizeAttenuation
* @param spriteRotation
* @param envMapIntensity
* @constructor
*/
GameLib.D3.API.Material = function(
id,
materialType,
name,
opacity,
side,
transparent,
maps,
specular,
lightMapIntensity,
aoMapIntensity,
color,
emissive,
emissiveIntensity,
combine,
shininess,
reflectivity,
refractionRatio,
fog,
wireframe,
wireframeLineWidth,
wireframeLineCap,
wireframeLineJoin,
vertexColors,
skinning,
morphTargets,
morphNormals,
lineWidth,
lineCap,
lineJoin,
dashSize,
gapWidth,
blending,
blendSrc,
blendDst,
blendEquation,
depthTest,
depthFunc,
depthWrite,
polygonOffset,
polygonOffsetFactor,
polygonOffsetUnits,
alphaTest,
clippingPlanes,
clipShadows,
visible,
overdraw,
shading,
bumpScale,
normalScale,
displacementScale,
displacementBias,
roughness,
metalness,
pointSize,
pointSizeAttenuation,
spriteRotation,
envMapIntensity
) {
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
2016-11-29 12:54:25 +01:00
}
this.id = id;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(materialType)) {
2016-11-29 12:54:25 +01:00
materialType = GameLib.D3.Material.MATERIAL_TYPE_STANDARD;
}
this.materialType = materialType;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(name)) {
2016-11-29 12:54:25 +01:00
name = 'Material (' + materialType + ')';
}
this.name = name;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(opacity)) {
2016-11-29 12:54:25 +01:00
opacity = 1.0;
}
this.opacity = opacity;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(side)) {
2016-11-29 12:54:25 +01:00
side = GameLib.D3.Material.TYPE_FRONT_SIDE;
}
this.side = side;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(transparent)) {
2016-11-29 12:54:25 +01:00
transparent = false;
}
this.transparent = transparent;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(maps)) {
2016-11-29 12:54:25 +01:00
maps = GameLib.D3.API.TextureMapTemplate();
}
this.maps = maps;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(specular)) {
2016-12-02 13:00:56 +01:00
specular = new GameLib.D3.API.Color(0.06, 0.06, 0.06, 0.06);
2016-11-29 12:54:25 +01:00
}
this.specular = specular;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(lightMapIntensity)) {
2016-11-29 12:54:25 +01:00
lightMapIntensity = 1;
}
this.lightMapIntensity = lightMapIntensity;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(aoMapIntensity)) {
2016-11-29 12:54:25 +01:00
aoMapIntensity = 1;
}
this.aoMapIntensity = aoMapIntensity;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(color)) {
2016-12-02 13:00:56 +01:00
color = new GameLib.D3.API.Color(1, 1, 1, 1)
2016-11-29 12:54:25 +01:00
}
this.color = color;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(emissive)) {
2016-12-02 13:00:56 +01:00
emissive = new GameLib.D3.API.Color(0, 0, 0, 0);
2016-11-29 12:54:25 +01:00
}
this.emissive = emissive;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(emissiveIntensity)) {
2016-11-29 12:54:25 +01:00
emissiveIntensity = 1;
}
this.emissiveIntensity = emissiveIntensity;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(combine)) {
2016-11-29 12:54:25 +01:00
combine = GameLib.D3.Material.TYPE_MULTIPLY_OPERATION;
}
this.combine = combine;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(shininess)) {
2016-11-29 12:54:25 +01:00
shininess = 30;
}
this.shininess = shininess;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(reflectivity)) {
2016-11-29 12:54:25 +01:00
reflectivity = 1;
}
this.reflectivity = reflectivity;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(refractionRatio)) {
2016-11-29 12:54:25 +01:00
refractionRatio = 0.98;
}
this.refractionRatio = refractionRatio;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(fog)) {
2016-11-29 12:54:25 +01:00
fog = true;
}
this.fog = fog;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(wireframe)) {
2016-11-29 12:54:25 +01:00
wireframe = false;
}
this.wireframe = wireframe;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(wireframeLineWidth)) {
2016-11-29 12:54:25 +01:00
wireframeLineWidth = 1;
}
this.wireframeLineWidth = wireframeLineWidth;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(wireframeLineCap)) {
2016-11-29 12:54:25 +01:00
wireframeLineCap = 'round';
}
this.wireframeLineCap = wireframeLineCap;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(wireframeLineJoin)) {
2016-11-29 12:54:25 +01:00
wireframeLineJoin = 'round';
}
this.wireframeLineJoin = wireframeLineJoin;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(vertexColors)) {
2016-11-29 12:54:25 +01:00
vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
}
this.vertexColors = vertexColors;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(skinning)) {
2016-11-29 12:54:25 +01:00
skinning = false;
}
this.skinning = skinning;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(morphTargets)) {
2016-11-29 12:54:25 +01:00
morphTargets = false;
}
this.morphTargets = morphTargets;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(morphNormals)) {
2016-11-29 12:54:25 +01:00
morphNormals = false;
}
this.morphNormals = morphNormals;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(overdraw)) {
2016-11-29 12:54:25 +01:00
overdraw = 0;
}
this.overdraw = overdraw;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(lineWidth)) {
2016-11-29 12:54:25 +01:00
lineWidth = 1;
}
this.lineWidth = lineWidth;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(lineCap)) {
2016-11-29 12:54:25 +01:00
lineCap = 'round';
}
this.lineCap = lineCap;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(lineJoin)) {
2016-11-29 12:54:25 +01:00
lineJoin = 'round';
}
this.lineJoin = lineJoin;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(dashSize)) {
2016-11-29 12:54:25 +01:00
dashSize = 3;
}
this.dashSize = dashSize;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(gapWidth)) {
2016-11-29 12:54:25 +01:00
gapWidth = 1;
}
this.gapWidth = gapWidth;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(blending)) {
2016-11-29 12:54:25 +01:00
blending = GameLib.D3.Material.TYPE_NORMAL_BLENDING;
}
this.blending = blending;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(blendSrc)) {
2016-11-29 12:54:25 +01:00
blendSrc = GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR;
}
this.blendSrc = blendSrc;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(blendDst)) {
2016-11-29 12:54:25 +01:00
blendDst = GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR;
}
this.blendDst = blendDst;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(blendEquation)) {
2016-11-29 12:54:25 +01:00
blendEquation = GameLib.D3.Material.TYPE_ADD_EQUATION;
}
this.blendEquation = blendEquation;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(depthTest)) {
2016-11-29 12:54:25 +01:00
depthTest = true;
}
this.depthTest = depthTest;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(depthFunc)) {
2016-11-29 12:54:25 +01:00
depthFunc = GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH;
}
this.depthFunc = depthFunc;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(depthWrite)) {
2016-11-29 12:54:25 +01:00
depthWrite = true;
}
this.depthWrite = depthWrite;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(polygonOffset)) {
2016-11-29 12:54:25 +01:00
polygonOffset = false;
}
this.polygonOffset = polygonOffset;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(polygonOffsetFactor)) {
2016-11-29 12:54:25 +01:00
polygonOffsetFactor = 1;
}
this.polygonOffsetFactor = polygonOffsetFactor;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(polygonOffsetUnits)) {
2016-11-29 12:54:25 +01:00
polygonOffsetUnits = 1;
}
this.polygonOffsetUnits = polygonOffsetUnits;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(alphaTest)) {
2016-11-29 12:54:25 +01:00
alphaTest = 0;
}
this.alphaTest = alphaTest;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) {
2016-11-29 12:54:25 +01:00
clippingPlanes = [];
}
this.clippingPlanes = clippingPlanes;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(clipShadows)) {
2016-11-29 12:54:25 +01:00
clipShadows = false;
}
this.clipShadows = clipShadows;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(visible)) {
2016-11-29 12:54:25 +01:00
visible = true;
}
this.visible = visible;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(shading)) {
2016-11-29 12:54:25 +01:00
shading = GameLib.D3.Material.TYPE_FLAT_SHADING;
}
this.shading = shading;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(bumpScale)) {
2016-11-29 12:54:25 +01:00
bumpScale = 1;
}
this.bumpScale = bumpScale;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(normalScale)) {
2016-11-29 12:54:25 +01:00
normalScale = 1;
}
this.normalScale = normalScale;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(displacementScale)) {
2016-11-29 12:54:25 +01:00
displacementScale = 1;
}
this.displacementScale = displacementScale;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(displacementBias)) {
2016-11-29 12:54:25 +01:00
displacementBias = 0;
}
this.displacementBias = displacementBias;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(roughness)) {
2016-11-29 12:54:25 +01:00
roughness = 0.5;
}
this.roughness = roughness;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(metalness)) {
2016-11-29 12:54:25 +01:00
metalness = 0.5;
}
this.metalness = metalness;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(pointSize)) {
2016-11-29 12:54:25 +01:00
pointSize = 1;
}
this.pointSize = pointSize;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(pointSizeAttenuation)) {
2016-11-29 12:54:25 +01:00
pointSizeAttenuation = true;
}
this.pointSizeAttenuation = pointSizeAttenuation;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(spriteRotation)) {
2016-11-29 12:54:25 +01:00
spriteRotation = 0;
}
this.spriteRotation = spriteRotation;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(envMapIntensity)) {
2016-11-29 12:54:25 +01:00
envMapIntensity = 1.0;
}
this.envMapIntensity = envMapIntensity;
};