405 lines
9.6 KiB
JavaScript
405 lines
9.6 KiB
JavaScript
|
/**
|
||
|
* 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
|
||
|
) {
|
||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||
|
id = GameLib.Utils.RandomId();
|
||
|
}
|
||
|
this.id = id;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(materialType)) {
|
||
|
materialType = GameLib.D3.Material.MATERIAL_TYPE_STANDARD;
|
||
|
}
|
||
|
this.materialType = materialType;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||
|
name = 'Material (' + materialType + ')';
|
||
|
}
|
||
|
this.name = name;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(opacity)) {
|
||
|
opacity = 1.0;
|
||
|
}
|
||
|
this.opacity = opacity;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(side)) {
|
||
|
side = GameLib.D3.Material.TYPE_FRONT_SIDE;
|
||
|
}
|
||
|
this.side = side;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(transparent)) {
|
||
|
transparent = false;
|
||
|
}
|
||
|
this.transparent = transparent;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(maps)) {
|
||
|
maps = GameLib.D3.API.TextureMapTemplate();
|
||
|
}
|
||
|
this.maps = maps;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(specular)) {
|
||
|
specular = new GameLib.D3.API.Color(0.06, 0.06, 0.06, 0.06);
|
||
|
}
|
||
|
this.specular = specular;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(lightMapIntensity)) {
|
||
|
lightMapIntensity = 1;
|
||
|
}
|
||
|
this.lightMapIntensity = lightMapIntensity;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(aoMapIntensity)) {
|
||
|
aoMapIntensity = 1;
|
||
|
}
|
||
|
this.aoMapIntensity = aoMapIntensity;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(color)) {
|
||
|
color = new GameLib.D3.API.Color(1, 1, 1, 1)
|
||
|
}
|
||
|
this.color = color;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(emissive)) {
|
||
|
emissive = new GameLib.D3.API.Color(0, 0, 0, 0);
|
||
|
}
|
||
|
this.emissive = emissive;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(emissiveIntensity)) {
|
||
|
emissiveIntensity = 1;
|
||
|
}
|
||
|
this.emissiveIntensity = emissiveIntensity;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(combine)) {
|
||
|
combine = GameLib.D3.Material.TYPE_MULTIPLY_OPERATION;
|
||
|
}
|
||
|
this.combine = combine;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(shininess)) {
|
||
|
shininess = 30;
|
||
|
}
|
||
|
this.shininess = shininess;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(reflectivity)) {
|
||
|
reflectivity = 1;
|
||
|
}
|
||
|
this.reflectivity = reflectivity;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(refractionRatio)) {
|
||
|
refractionRatio = 0.98;
|
||
|
}
|
||
|
this.refractionRatio = refractionRatio;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(fog)) {
|
||
|
fog = true;
|
||
|
}
|
||
|
this.fog = fog;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(wireframe)) {
|
||
|
wireframe = false;
|
||
|
}
|
||
|
this.wireframe = wireframe;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(wireframeLineWidth)) {
|
||
|
wireframeLineWidth = 1;
|
||
|
}
|
||
|
this.wireframeLineWidth = wireframeLineWidth;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(wireframeLineCap)) {
|
||
|
wireframeLineCap = 'round';
|
||
|
}
|
||
|
this.wireframeLineCap = wireframeLineCap;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(wireframeLineJoin)) {
|
||
|
wireframeLineJoin = 'round';
|
||
|
}
|
||
|
this.wireframeLineJoin = wireframeLineJoin;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(vertexColors)) {
|
||
|
vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
||
|
}
|
||
|
this.vertexColors = vertexColors;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(skinning)) {
|
||
|
skinning = false;
|
||
|
}
|
||
|
this.skinning = skinning;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(morphTargets)) {
|
||
|
morphTargets = false;
|
||
|
}
|
||
|
this.morphTargets = morphTargets;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(morphNormals)) {
|
||
|
morphNormals = false;
|
||
|
}
|
||
|
this.morphNormals = morphNormals;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(overdraw)) {
|
||
|
overdraw = 0;
|
||
|
}
|
||
|
this.overdraw = overdraw;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(lineWidth)) {
|
||
|
lineWidth = 1;
|
||
|
}
|
||
|
this.lineWidth = lineWidth;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(lineCap)) {
|
||
|
lineCap = 'round';
|
||
|
}
|
||
|
this.lineCap = lineCap;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(lineJoin)) {
|
||
|
lineJoin = 'round';
|
||
|
}
|
||
|
this.lineJoin = lineJoin;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(dashSize)) {
|
||
|
dashSize = 3;
|
||
|
}
|
||
|
this.dashSize = dashSize;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(gapWidth)) {
|
||
|
gapWidth = 1;
|
||
|
}
|
||
|
this.gapWidth = gapWidth;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(blending)) {
|
||
|
blending = GameLib.D3.Material.TYPE_NORMAL_BLENDING;
|
||
|
}
|
||
|
this.blending = blending;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(blendSrc)) {
|
||
|
blendSrc = GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR;
|
||
|
}
|
||
|
this.blendSrc = blendSrc;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(blendDst)) {
|
||
|
blendDst = GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR;
|
||
|
}
|
||
|
this.blendDst = blendDst;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(blendEquation)) {
|
||
|
blendEquation = GameLib.D3.Material.TYPE_ADD_EQUATION;
|
||
|
}
|
||
|
this.blendEquation = blendEquation;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(depthTest)) {
|
||
|
depthTest = true;
|
||
|
}
|
||
|
this.depthTest = depthTest;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(depthFunc)) {
|
||
|
depthFunc = GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH;
|
||
|
}
|
||
|
this.depthFunc = depthFunc;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(depthWrite)) {
|
||
|
depthWrite = true;
|
||
|
}
|
||
|
this.depthWrite = depthWrite;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(polygonOffset)) {
|
||
|
polygonOffset = false;
|
||
|
}
|
||
|
this.polygonOffset = polygonOffset;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(polygonOffsetFactor)) {
|
||
|
polygonOffsetFactor = 1;
|
||
|
}
|
||
|
this.polygonOffsetFactor = polygonOffsetFactor;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(polygonOffsetUnits)) {
|
||
|
polygonOffsetUnits = 1;
|
||
|
}
|
||
|
this.polygonOffsetUnits = polygonOffsetUnits;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(alphaTest)) {
|
||
|
alphaTest = 0;
|
||
|
}
|
||
|
this.alphaTest = alphaTest;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) {
|
||
|
clippingPlanes = [];
|
||
|
}
|
||
|
this.clippingPlanes = clippingPlanes;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(clipShadows)) {
|
||
|
clipShadows = false;
|
||
|
}
|
||
|
this.clipShadows = clipShadows;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(visible)) {
|
||
|
visible = true;
|
||
|
}
|
||
|
this.visible = visible;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(shading)) {
|
||
|
shading = GameLib.D3.Material.TYPE_FLAT_SHADING;
|
||
|
}
|
||
|
this.shading = shading;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(bumpScale)) {
|
||
|
bumpScale = 1;
|
||
|
}
|
||
|
this.bumpScale = bumpScale;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(normalScale)) {
|
||
|
normalScale = 1;
|
||
|
}
|
||
|
this.normalScale = normalScale;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(displacementScale)) {
|
||
|
displacementScale = 1;
|
||
|
}
|
||
|
this.displacementScale = displacementScale;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(displacementBias)) {
|
||
|
displacementBias = 0;
|
||
|
}
|
||
|
this.displacementBias = displacementBias;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(roughness)) {
|
||
|
roughness = 0.5;
|
||
|
}
|
||
|
this.roughness = roughness;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(metalness)) {
|
||
|
metalness = 0.5;
|
||
|
}
|
||
|
this.metalness = metalness;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(pointSize)) {
|
||
|
pointSize = 1;
|
||
|
}
|
||
|
this.pointSize = pointSize;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(pointSizeAttenuation)) {
|
||
|
pointSizeAttenuation = true;
|
||
|
}
|
||
|
this.pointSizeAttenuation = pointSizeAttenuation;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(spriteRotation)) {
|
||
|
spriteRotation = 0;
|
||
|
}
|
||
|
this.spriteRotation = spriteRotation;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(envMapIntensity)) {
|
||
|
envMapIntensity = 1.0;
|
||
|
}
|
||
|
this.envMapIntensity = envMapIntensity;
|
||
|
};
|