Socket
Socket
Sign inDemoInstall

zen-3d

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

examples/js/objects/Water.js

2

examples/js/controls/FreeControls.js

@@ -66,3 +66,3 @@ /**

return false;
}
};

@@ -69,0 +69,0 @@ var tempVector = new zen3d.Vector3();

@@ -17,2 +17,111 @@ /**

var MaterialCache = function() {
var normalGlossinessMaterials = new Map();
var albedoMetalnessMaterials = new Map();
var MRTMaterials = new Map();
var state = {};
function generateMaterialState(renderable, result) {
result.useFlatShading = !renderable.geometry.attributes["a_Normal"] || (renderable.material.shading === zen3d.SHADING_TYPE.FLAT_SHADING);
result.useDiffuseMap = !!renderable.material.diffuseMap;
result.useRoughnessMap = !!renderable.material.roughnessMap;
result.useMetalnessMap = !!renderable.material.metalnessMap;
result.useSkinning = renderable.object.type === zen3d.OBJECT_TYPE.SKINNED_MESH && renderable.object.skeleton;
result.morphTargets = !!renderable.object.morphTargetInfluences;
result.morphNormals = !!renderable.object.morphTargetInfluences && renderable.object.geometry.morphAttributes.normal;
}
function getMrtMaterial(renderable) {
generateMaterialState(renderable, state);
var material;
var code = state.useFlatShading +
"_" + state.useDiffuseMap +
"_" + state.useRoughnessMap +
"_" + state.useMetalnessMap +
"_" + state.useSkinning +
"_" + state.morphTargets +
"_" + state.morphNormals;
if (!MRTMaterials.has(code)) {
material = new zen3d.ShaderMaterial(GBufferShader.MRT);
material.shading = state.useFlatShading ? zen3d.SHADING_TYPE.FLAT_SHADING : zen3d.SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = state.useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
MRTMaterials.set(code, material);
} else {
material = MRTMaterials.get(code);
}
material.diffuse.copy(renderable.material.diffuse);
material.diffuseMap = renderable.material.diffuseMap;
material.uniforms["roughness"] = renderable.material.roughness !== undefined ? renderable.material.roughness : 0.5;
material.roughnessMap = renderable.material.roughnessMap;
material.uniforms["metalness"] = renderable.material.metalness !== undefined ? renderable.material.metalness : 0.5;
material.metalnessMap = renderable.material.metalnessMap;
return material;
}
function getNormalGlossinessMaterial(renderable) {
generateMaterialState(renderable, state);
var material;
var code = state.useFlatShading +
"_" + state.useDiffuseMap +
"_" + state.useRoughnessMap +
"_" + state.useSkinning +
"_" + state.morphTargets +
"_" + state.morphNormals;
if (!normalGlossinessMaterials.has(code)) {
material = new zen3d.ShaderMaterial(GBufferShader.normalGlossiness);
material.shading = state.useFlatShading ? zen3d.SHADING_TYPE.FLAT_SHADING : zen3d.SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = state.useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
normalGlossinessMaterials.set(code, material);
} else {
material = normalGlossinessMaterials.get(code);
}
material.diffuseMap = renderable.material.diffuseMap;
material.uniforms["roughness"] = renderable.material.roughness !== undefined ? renderable.material.roughness : 0.5;
material.roughnessMap = renderable.material.roughnessMap;
return material;
}
function getAlbedoMetalnessMaterial(renderable) {
generateMaterialState(renderable, state);
var material;
var code = state.useFlatShading +
"_" + state.useDiffuseMap +
"_" + state.useMetalnessMap +
"_" + state.useSkinning +
"_" + state.morphTargets +
"_" + state.morphNormals;
if (!albedoMetalnessMaterials.has(code)) {
material = new zen3d.ShaderMaterial(GBufferShader.albedoMetalness);
material.shading = state.useFlatShading ? zen3d.SHADING_TYPE.FLAT_SHADING : zen3d.SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = state.useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
albedoMetalnessMaterials.set(code, material);
} else {
material = albedoMetalnessMaterials.get(code);
}
material.diffuse.copy(renderable.material.diffuse);
material.diffuseMap = renderable.material.diffuseMap;
material.uniforms["metalness"] = renderable.material.metalness !== undefined ? renderable.material.metalness : 0.5;
material.metalnessMap = renderable.material.metalnessMap;
return material;
}
return {
getMrtMaterial: getMrtMaterial,
getNormalGlossinessMaterial: getNormalGlossinessMaterial,
getAlbedoMetalnessMaterial: getAlbedoMetalnessMaterial
}
}
var materialCache = new MaterialCache();
function GBuffer(width, height) {

@@ -75,3 +184,2 @@ this._renderTarget1 = new zen3d.RenderTarget2D(width, height);

var renderList = scene.getRenderList(camera);
var that = this;

@@ -115,12 +223,3 @@ // Use MRT if support

getMaterial: function(renderable) {
var mrtMaterial = that._getMrtMaterial(renderable);
mrtMaterial.diffuse.copy(renderable.material.diffuse);
mrtMaterial.diffuseMap = renderable.material.diffuseMap;
mrtMaterial.uniforms["roughness"] = renderable.material.roughness !== undefined ? renderable.material.roughness : 0.5;
mrtMaterial.roughnessMap = renderable.material.roughnessMap;
mrtMaterial.uniforms["metalness"] = renderable.material.metalness !== undefined ? renderable.material.metalness : 0.5;
mrtMaterial.metalnessMap = renderable.material.metalnessMap;
return mrtMaterial;
return materialCache.getMrtMaterial(renderable);
},

@@ -146,9 +245,3 @@ ifRender: function(renderable) {

getMaterial: function(renderable) {
var normalGlossinessMaterial = that._getNormalGlossinessMaterial(renderable);
normalGlossinessMaterial.diffuseMap = renderable.material.diffuseMap;
normalGlossinessMaterial.uniforms["roughness"] = renderable.material.roughness !== undefined ? renderable.material.roughness : 0.5;
normalGlossinessMaterial.roughnessMap = renderable.material.roughnessMap;
return normalGlossinessMaterial;
return materialCache.getNormalGlossinessMaterial(renderable);
},

@@ -172,10 +265,3 @@ ifRender: function(renderable) {

getMaterial: function(renderable) {
var albedoMetalnessMaterial = that._getAlbedoMetalnessMaterial(renderable);
albedoMetalnessMaterial.diffuse.copy(renderable.material.diffuse);
albedoMetalnessMaterial.diffuseMap = renderable.material.diffuseMap;
albedoMetalnessMaterial.uniforms["metalness"] = renderable.material.metalness !== undefined ? renderable.material.metalness : 0.5;
albedoMetalnessMaterial.metalnessMap = renderable.material.metalnessMap;
return albedoMetalnessMaterial;
return materialCache.getAlbedoMetalnessMaterial(renderable);
},

@@ -258,61 +344,9 @@ ifRender: function(renderable) {

this._MRTMaterials.forEach(material => material.dispose());
this._normalGlossinessMaterials.forEach(material => material.dispose());
this._albedoMetalnessMaterials.forEach(material => material.dispose());
materialCache.MRTMaterials.forEach(material => material.dispose());
materialCache.normalGlossinessMaterials.forEach(material => material.dispose());
materialCache.albedoMetalnessMaterials.forEach(material => material.dispose());
this._MRTMaterials.clear();
this._normalGlossinessMaterials.clear();
this._albedoMetalnessMaterials.clear();
},
// get materials from cache
// Avoid frequently updating materials
_getMrtMaterial: function(renderable) {
var useFlatShading = !renderable.geometry.attributes["a_Normal"];
var useDiffuseMap = renderable.material.diffuseMap;
var useRoughnessMap = !!renderable.material.roughnessMap;
var useMetalnessMap = !!renderable.material.metalnessMap;
var code = useFlatShading + "_" + useDiffuseMap + "_" + useRoughnessMap + "_" + useMetalnessMap;
if (!this._MRTMaterials.has(code)) {
var material = new zen3d.ShaderMaterial(GBufferShader.MRT);
material.shading = useFlatShading ? zen3d.SHADING_TYPE.FLAT_SHADING : zen3d.SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
this._MRTMaterials.set(code, material);
}
return this._MRTMaterials.get(code);
},
_getNormalGlossinessMaterial: function(renderable) {
var useFlatShading = !renderable.geometry.attributes["a_Normal"];
var useDiffuseMap = renderable.material.diffuseMap;
var useRoughnessMap = !!renderable.material.roughnessMap;
var code = useFlatShading + "_" + useDiffuseMap + "_" + useRoughnessMap;
if (!this._normalGlossinessMaterials.has(code)) {
var material = new zen3d.ShaderMaterial(GBufferShader.normalGlossiness);
material.shading = useFlatShading ? zen3d.SHADING_TYPE.FLAT_SHADING : zen3d.SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
this._normalGlossinessMaterials.set(code, material);
}
return this._normalGlossinessMaterials.get(code);
},
_getAlbedoMetalnessMaterial: function(renderable) {
var useFlatShading = !renderable.geometry.attributes["a_Normal"];
var useDiffuseMap = renderable.material.diffuseMap;
var useMetalnessMap = !!renderable.material.metalnessMap;
var code = useFlatShading + "_" + useDiffuseMap + "_" + useMetalnessMap;
if (!this._albedoMetalnessMaterials.has(code)) {
var material = new zen3d.ShaderMaterial(GBufferShader.albedoMetalness);
material.shading = useFlatShading ? zen3d.SHADING_TYPE.FLAT_SHADING : zen3d.SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
this._albedoMetalnessMaterials.set(code, material);
}
return this._albedoMetalnessMaterials.get(code);
materialCache.MRTMaterials.clear();
materialCache.normalGlossinessMaterials.clear();
materialCache.albedoMetalnessMaterials.clear();
}

@@ -335,5 +369,3 @@

"#include <common_vert>",
"#define USE_NORMAL",
"#include <morphtarget_pars_vert>",
"#include <skinning_pars_vert>",

@@ -343,7 +375,10 @@ "#include <normal_pars_vert>",

"void main() {",
"#include <uv_vert>",
"#include <begin_vert>",
"#include <skinning_vert>",
"#include <normal_vert>",
"#include <pvm_vert>",
" #include <uv_vert>",
" #include <begin_vert>",
" #include <morphtarget_vert>",
" #include <morphnormal_vert>",
" #include <skinning_vert>",
" #include <skinnormal_vert>",
" #include <normal_vert>",
" #include <pvm_vert>",
"}"

@@ -360,4 +395,2 @@

"#define USE_NORMAL",
"#include <packing>",

@@ -369,25 +402,25 @@ "#include <normal_pars_frag>",

"#ifdef USE_ROUGHNESSMAP",
"uniform sampler2D roughnessMap;",
" uniform sampler2D roughnessMap;",
"#endif",
"void main() {",
"#if defined(USE_DIFFUSE_MAP) && defined(ALPHATEST)",
"vec4 texelColor = texture2D( diffuseMap, v_Uv );",
" #if defined(USE_DIFFUSE_MAP) && defined(ALPHATEST)",
" vec4 texelColor = texture2D( diffuseMap, v_Uv );",
"float alpha = texelColor.a * u_Opacity;",
"if(alpha < ALPHATEST) discard;",
"#endif",
" float alpha = texelColor.a * u_Opacity;",
" if(alpha < ALPHATEST) discard;",
" #endif",
"vec3 normal = normalize(v_Normal);",
" vec3 normal = normalize(v_Normal);",
"float roughnessFactor = roughness;",
"#ifdef USE_ROUGHNESSMAP",
"roughnessFactor *= texture2D( roughnessMap, v_Uv ).g;",
"#endif",
" float roughnessFactor = roughness;",
" #ifdef USE_ROUGHNESSMAP",
" roughnessFactor *= texture2D( roughnessMap, v_Uv ).g;",
" #endif",
"vec4 packedNormalGlossiness;",
"packedNormalGlossiness.xyz = normal * 0.5 + 0.5;",
"packedNormalGlossiness.w = clamp(1. - roughnessFactor, 0., 1.);",
" vec4 packedNormalGlossiness;",
" packedNormalGlossiness.xyz = normal * 0.5 + 0.5;",
" packedNormalGlossiness.w = clamp(1. - roughnessFactor, 0., 1.);",
"gl_FragColor = packedNormalGlossiness;",
" gl_FragColor = packedNormalGlossiness;",
"}"

@@ -412,9 +445,11 @@

"#include <envMap_pars_vert>",
"#include <morphtarget_pars_vert>",
"#include <skinning_pars_vert>",
"void main() {",
"#include <begin_vert>",
"#include <skinning_vert>",
"#include <pvm_vert>",
"#include <uv_vert>",
"#include <color_vert>",
" #include <begin_vert>",
" #include <morphtarget_vert>",
" #include <skinning_vert>",
" #include <pvm_vert>",
" #include <uv_vert>",
" #include <color_vert>",
"}"

@@ -432,18 +467,16 @@ ].join("\n"),

"#ifdef USE_METALNESSMAP",
"uniform sampler2D metalnessMap;",
" uniform sampler2D metalnessMap;",
"#endif",
"void main() {",
" vec4 outColor = vec4( u_Color, 1.0 );",
" #include <diffuseMap_frag>",
" vec3 diffuseColor = outColor.xyz * outColor.a;",
"vec4 outColor = vec4( u_Color, 1.0 );",
"#include <diffuseMap_frag>",
"vec3 diffuseColor = outColor.xyz * outColor.a;",
" float metalnessFactor = metalness;",
" #ifdef USE_METALNESSMAP",
" metalnessFactor *= texture2D( metalnessMap, v_Uv ).b;",
" #endif",
"float metalnessFactor = metalness;",
"#ifdef USE_METALNESSMAP",
"metalnessFactor *= texture2D( metalnessMap, v_Uv ).b;",
"#endif",
"gl_FragColor = vec4( diffuseColor.xyz, metalnessFactor );",
" gl_FragColor = vec4( diffuseColor.xyz, metalnessFactor );",
"}"

@@ -465,3 +498,2 @@

vertexShader: [
"#define USE_NORMAL",
"#include <common_vert>",

@@ -472,10 +504,14 @@ "#include <uv_pars_vert>",

"#include <envMap_pars_vert>",
"#include <morphtarget_pars_vert>",
"#include <skinning_pars_vert>",
"void main() {",
"#include <begin_vert>",
"#include <skinning_vert>",
"#include <pvm_vert>",
"#include <uv_vert>",
"#include <normal_vert>",
"#include <color_vert>",
" #include <begin_vert>",
" #include <morphtarget_vert>",
" #include <morphnormal_vert>",
" #include <skinning_vert>",
" #include <skinnormal_vert>",
" #include <pvm_vert>",
" #include <uv_vert>",
" #include <normal_vert>",
" #include <color_vert>",
"}"

@@ -493,4 +529,2 @@ ].join("\n"),

"#define USE_NORMAL",
"#include <packing>",

@@ -503,38 +537,38 @@ "#include <normal_pars_frag>",

"#ifdef USE_ROUGHNESSMAP",
"uniform sampler2D roughnessMap;",
" uniform sampler2D roughnessMap;",
"#endif",
"#ifdef USE_METALNESSMAP",
"uniform sampler2D metalnessMap;",
" uniform sampler2D metalnessMap;",
"#endif",
"void main() {",
"vec4 outColor = vec4( u_Color, 1.0 );",
"#include <diffuseMap_frag>",
"vec3 diffuseColor = outColor.xyz * outColor.a;",
" vec4 outColor = vec4( u_Color, 1.0 );",
" #include <diffuseMap_frag>",
" vec3 diffuseColor = outColor.xyz * outColor.a;",
"float metalnessFactor = metalness;",
"#ifdef USE_METALNESSMAP",
"metalnessFactor *= texture2D( metalnessMap, v_Uv ).b;",
"#endif",
" float metalnessFactor = metalness;",
" #ifdef USE_METALNESSMAP",
" metalnessFactor *= texture2D( metalnessMap, v_Uv ).b;",
" #endif",
"gl_FragData[1] = vec4( outColor.xyz, metalnessFactor );",
" gl_FragData[1] = vec4( outColor.xyz, metalnessFactor );",
"#if defined(USE_DIFFUSE_MAP) && defined(ALPHATEST)",
"float alpha = outColor.a * u_Opacity;",
"if(alpha < ALPHATEST) discard;",
"#endif",
" #if defined(USE_DIFFUSE_MAP) && defined(ALPHATEST)",
" float alpha = outColor.a * u_Opacity;",
" if(alpha < ALPHATEST) discard;",
" #endif",
"vec3 normal = normalize(v_Normal);",
" vec3 normal = normalize(v_Normal);",
"float roughnessFactor = roughness;",
"#ifdef USE_ROUGHNESSMAP",
"roughnessFactor *= texture2D( roughnessMap, v_Uv ).g;",
"#endif",
" float roughnessFactor = roughness;",
" #ifdef USE_ROUGHNESSMAP",
" roughnessFactor *= texture2D( roughnessMap, v_Uv ).g;",
" #endif",
"vec4 packedNormalGlossiness;",
"packedNormalGlossiness.xyz = normal * 0.5 + 0.5;",
"packedNormalGlossiness.w = clamp(1. - roughnessFactor, 0., 1.);",
" vec4 packedNormalGlossiness;",
" packedNormalGlossiness.xyz = normal * 0.5 + 0.5;",
" packedNormalGlossiness.w = clamp(1. - roughnessFactor, 0., 1.);",
"gl_FragData[0] = packedNormalGlossiness;",
" gl_FragData[0] = packedNormalGlossiness;",
"}"

@@ -573,3 +607,3 @@

"gl_Position = u_Projection * u_View * u_Model * vec4( a_Position, 1.0 );",
" gl_Position = u_Projection * u_View * u_Model * vec4( a_Position, 1.0 );",

@@ -603,45 +637,45 @@ "}"

"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
" vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
"vec4 texel1 = texture2D(normalGlossinessTexture, texCoord);",
"vec4 texel3 = texture2D(albedoMetalnessTexture, texCoord);",
" vec4 texel1 = texture2D(normalGlossinessTexture, texCoord);",
" vec4 texel3 = texture2D(albedoMetalnessTexture, texCoord);",
// Is empty
"if (dot(texel1.rgb, vec3(1.0)) == 0.0) {",
"discard;",
"}",
" if (dot(texel1.rgb, vec3(1.0)) == 0.0) {",
" discard;",
" }",
"float glossiness = texel1.a;",
"float metalness = texel3.a;",
" float glossiness = texel1.a;",
" float metalness = texel3.a;",
"vec3 N = texel1.rgb * 2.0 - 1.0;",
" vec3 N = texel1.rgb * 2.0 - 1.0;",
// Depth buffer range is 0.0 - 1.0
"float z = texture2D(depthTexture, texCoord).r * 2.0 - 1.0;",
" float z = texture2D(depthTexture, texCoord).r * 2.0 - 1.0;",
"vec2 xy = texCoord * 2.0 - 1.0;",
" vec2 xy = texCoord * 2.0 - 1.0;",
"vec4 projectedPos = vec4(xy, z, 1.0);",
"vec4 p4 = matProjViewInverse * projectedPos;",
" vec4 projectedPos = vec4(xy, z, 1.0);",
" vec4 p4 = matProjViewInverse * projectedPos;",
"vec3 position = p4.xyz / p4.w;",
" vec3 position = p4.xyz / p4.w;",
"vec3 albedo = texel3.rgb;",
" vec3 albedo = texel3.rgb;",
"vec3 diffuseColor = albedo * (1.0 - metalness);",
"vec3 specularColor = mix(vec3(0.04), albedo, metalness);",
" vec3 diffuseColor = albedo * (1.0 - metalness);",
" vec3 specularColor = mix(vec3(0.04), albedo, metalness);",
"if (debug == 0) {",
"gl_FragColor = vec4(N, 1.0);",
"} else if (debug == 1) {",
"gl_FragColor = vec4(vec3(z), 1.0);",
"} else if (debug == 2) {",
"gl_FragColor = vec4(position, 1.0);",
"} else if (debug == 3) {",
"gl_FragColor = vec4(vec3(glossiness), 1.0);",
"} else if (debug == 4) {",
"gl_FragColor = vec4(vec3(metalness), 1.0);",
"} else {",
"gl_FragColor = vec4(albedo, 1.0);",
"}",
" if (debug == 0) {",
" gl_FragColor = vec4(N, 1.0);",
" } else if (debug == 1) {",
" gl_FragColor = vec4(vec3(z), 1.0);",
" } else if (debug == 2) {",
" gl_FragColor = vec4(position, 1.0);",
" } else if (debug == 3) {",
" gl_FragColor = vec4(vec3(glossiness), 1.0);",
" } else if (debug == 4) {",
" gl_FragColor = vec4(vec3(metalness), 1.0);",
" } else {",
" gl_FragColor = vec4(albedo, 1.0);",
" }",

@@ -648,0 +682,0 @@ "}"

@@ -79,3 +79,2 @@ /**

var parent;
var breaked = false;
while (node.parent) {

@@ -148,3 +147,3 @@ parent = node.parent;

if (!boneMap[boneName]) {
console.log(boneName)
console.log(boneName);
continue;

@@ -245,3 +244,3 @@ }

var prop = json.properties;
var prop;

@@ -334,7 +333,5 @@ for (var key in json.properties) {

var bone, name, offset, weights, weight;
var bone, weights, weight;
for (var i = 0; i < bones.length; i++) {
bone = bones[i];
name = bone.name;
offset = bone.offsetmatrix;
weights = bone.weights;

@@ -341,0 +338,0 @@ for (var j = 0; j < weights.length; j++) {

@@ -119,3 +119,3 @@ /**

} else {
var errorMsg = 'zen3d.DRACOLoader: Unknown geometry type.'
var errorMsg = 'zen3d.DRACOLoader: Unknown geometry type.';
console.error(errorMsg);

@@ -307,4 +307,4 @@ throw new Error(errorMsg);

var stripsArray = new dracoDecoder.DracoInt32Array();
var numStrips = decoder.GetTriangleStripsFromMesh(
dracoGeometry, stripsArray);
// var numStrips = decoder.GetTriangleStripsFromMesh(
// dracoGeometry, stripsArray);
geometryBuffer.indices = new Array(stripsArray.size());

@@ -311,0 +311,0 @@ for (var i = 0; i < stripsArray.size(); ++i) {

@@ -471,6 +471,6 @@ /**

var meshReferences = this.json.meshReferences;
var meshUses = this.json.meshUses;
var meshReferences = json.meshReferences;
var meshUses = json.meshUses;
var nodeDef = this.json.nodes[nodeIndex];
var nodeDef = json.nodes[nodeIndex];

@@ -647,4 +647,19 @@ return this.getMultiDependencies([

var track = new TypedKeyframeTrack(node, PATH_PROPERTIES[target.path], input, output);
var targetNodes = [];
if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
node.traverse(function(object) {
if (object.type === zen3d.OBJECT_TYPE.MESH && object.morphTargetInfluences) {
targetNodes.push(object);
}
});
} else {
targetNodes.push(node);
}
for (var j = 0, jl = targetNodes.length; j < jl; j++) {
var track = new TypedKeyframeTrack(targetNodes[j], PATH_PROPERTIES[target.path], input, output);
tracks.push(track);
}
var maxTime = input[input.length - 1];

@@ -654,4 +669,2 @@ if (endFrame < maxTime) {

}
tracks.push(track);
}

@@ -681,3 +694,2 @@ }

var json = this.json;
var extensions = this.extensions;

@@ -1560,3 +1572,2 @@ var meshDef = json.meshes[meshIndex];

var BINARY_EXTENSION_BUFFER_NAME = 'binary_glTF';
var BINARY_EXTENSION_HEADER_MAGIC = 'glTF';

@@ -1563,0 +1574,0 @@ var BINARY_EXTENSION_HEADER_LENGTH = 12;

@@ -67,3 +67,3 @@ /*

return FLOAT_VIEW[0];
}
};
}(),

@@ -83,3 +83,2 @@

var sizeRandomness = 0;
var smoothPosition = false;

@@ -119,3 +118,3 @@ var maxVel = 2;

// convert turbulence rating to something we can pack into a vec4
var turbulence = Math.floor(turbulence * 254);
turbulence = Math.floor(turbulence * 254);

@@ -160,3 +159,3 @@ // clamp our value to between 0. and 1.

}
}
};
}(),

@@ -163,0 +162,0 @@

@@ -67,3 +67,3 @@ /**

return function updateMatrix() {
return function updateMatrix(force) {
var bones = this.bones;

@@ -100,4 +100,4 @@

zen3d.Mesh.prototype.updateMatrix.call(this);
zen3d.Mesh.prototype.updateMatrix.call(this, force);
};
}();

@@ -172,5 +172,3 @@ /**

"#include <common_vert>",
"#define USE_NORMAL",
"#include <morphtarget_pars_vert>",
"#include <skinning_pars_vert>",

@@ -183,3 +181,6 @@ "#include <normal_pars_vert>",

"#include <begin_vert>",
"#include <morphtarget_vert>",
"#include <morphnormal_vert>",
"#include <skinning_vert>",
"#include <skinnormal_vert>",
"#include <normal_vert>",

@@ -199,4 +200,2 @@ "#include <pvm_vert>",

"#define USE_NORMAL",
"#include <packing>",

@@ -695,5 +694,3 @@ "#include <normal_pars_frag>",

"#include <common_vert>",
"#define USE_NORMAL",
"#include <morphtarget_pars_vert>",
"#include <skinning_pars_vert>",

@@ -706,3 +703,6 @@ "#include <normal_pars_vert>",

"#include <begin_vert>",
"#include <morphtarget_vert>",
"#include <morphnormal_vert>",
"#include <skinning_vert>",
"#include <skinnormal_vert>",
"#include <normal_vert>",

@@ -721,5 +721,2 @@ "#include <pvm_vert>",

"#include <uv_pars_frag>",
"#define USE_NORMAL",
"#include <packing>",

@@ -726,0 +723,0 @@ "#include <normal_pars_frag>",

@@ -17,3 +17,3 @@ /**

this.matrixAutoUpdate && scene.updateMatrix();
this.lightsAutoupdate && scene.updateLights();
this.lightsAutoUpdate && scene.updateLights();

@@ -20,0 +20,0 @@ if (this.shadowAutoUpdate || this.shadowNeedsUpdate) {

@@ -92,3 +92,3 @@ /**

for (i = 0, il = faces2.length; i < il; i++) {
var face = faces2[i], faceCopy, normal, color;
var face = faces2[i], faceCopy;

@@ -213,6 +213,4 @@ faceCopy = new VOXFace3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);

var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0;
// var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0;
var index = 0;
for (var i = 0; i < faces.length; i++) {

@@ -219,0 +217,0 @@ var posArray, normalArray, colorArray, uvArray;

@@ -0,0 +0,0 @@ /**

@@ -72,3 +72,3 @@ /**

return false;
}
};

@@ -75,0 +75,0 @@ var tempVector = new Vector3();

@@ -8,2 +8,3 @@ /**

Matrix4,
OBJECT_TYPE,
RenderTarget2D,

@@ -31,2 +32,111 @@ SHADING_TYPE,

var MaterialCache = function() {
var normalGlossinessMaterials = new Map();
var albedoMetalnessMaterials = new Map();
var MRTMaterials = new Map();
var state = {};
function generateMaterialState(renderable, result) {
result.useFlatShading = !renderable.geometry.attributes["a_Normal"] || (renderable.material.shading === SHADING_TYPE.FLAT_SHADING);
result.useDiffuseMap = !!renderable.material.diffuseMap;
result.useRoughnessMap = !!renderable.material.roughnessMap;
result.useMetalnessMap = !!renderable.material.metalnessMap;
result.useSkinning = renderable.object.type === OBJECT_TYPE.SKINNED_MESH && renderable.object.skeleton;
result.morphTargets = !!renderable.object.morphTargetInfluences;
result.morphNormals = !!renderable.object.morphTargetInfluences && renderable.object.geometry.morphAttributes.normal;
}
function getMrtMaterial(renderable) {
generateMaterialState(renderable, state);
var material;
var code = state.useFlatShading +
"_" + state.useDiffuseMap +
"_" + state.useRoughnessMap +
"_" + state.useMetalnessMap +
"_" + state.useSkinning +
"_" + state.morphTargets +
"_" + state.morphNormals;
if (!MRTMaterials.has(code)) {
material = new ShaderMaterial(GBufferShader.MRT);
material.shading = state.useFlatShading ? SHADING_TYPE.FLAT_SHADING : SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = state.useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
MRTMaterials.set(code, material);
} else {
material = MRTMaterials.get(code);
}
material.diffuse.copy(renderable.material.diffuse);
material.diffuseMap = renderable.material.diffuseMap;
material.uniforms["roughness"] = renderable.material.roughness !== undefined ? renderable.material.roughness : 0.5;
material.roughnessMap = renderable.material.roughnessMap;
material.uniforms["metalness"] = renderable.material.metalness !== undefined ? renderable.material.metalness : 0.5;
material.metalnessMap = renderable.material.metalnessMap;
return material;
}
function getNormalGlossinessMaterial(renderable) {
generateMaterialState(renderable, state);
var material;
var code = state.useFlatShading +
"_" + state.useDiffuseMap +
"_" + state.useRoughnessMap +
"_" + state.useSkinning +
"_" + state.morphTargets +
"_" + state.morphNormals;
if (!normalGlossinessMaterials.has(code)) {
material = new ShaderMaterial(GBufferShader.normalGlossiness);
material.shading = state.useFlatShading ? SHADING_TYPE.FLAT_SHADING : SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = state.useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
normalGlossinessMaterials.set(code, material);
} else {
material = normalGlossinessMaterials.get(code);
}
material.diffuseMap = renderable.material.diffuseMap;
material.uniforms["roughness"] = renderable.material.roughness !== undefined ? renderable.material.roughness : 0.5;
material.roughnessMap = renderable.material.roughnessMap;
return material;
}
function getAlbedoMetalnessMaterial(renderable) {
generateMaterialState(renderable, state);
var material;
var code = state.useFlatShading +
"_" + state.useDiffuseMap +
"_" + state.useMetalnessMap +
"_" + state.useSkinning +
"_" + state.morphTargets +
"_" + state.morphNormals;
if (!albedoMetalnessMaterials.has(code)) {
material = new ShaderMaterial(GBufferShader.albedoMetalness);
material.shading = state.useFlatShading ? SHADING_TYPE.FLAT_SHADING : SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = state.useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
albedoMetalnessMaterials.set(code, material);
} else {
material = albedoMetalnessMaterials.get(code);
}
material.diffuse.copy(renderable.material.diffuse);
material.diffuseMap = renderable.material.diffuseMap;
material.uniforms["metalness"] = renderable.material.metalness !== undefined ? renderable.material.metalness : 0.5;
material.metalnessMap = renderable.material.metalnessMap;
return material;
}
return {
getMrtMaterial: getMrtMaterial,
getNormalGlossinessMaterial: getNormalGlossinessMaterial,
getAlbedoMetalnessMaterial: getAlbedoMetalnessMaterial
}
}
var materialCache = new MaterialCache();
function GBuffer(width, height) {

@@ -89,3 +199,2 @@ this._renderTarget1 = new RenderTarget2D(width, height);

var renderList = scene.getRenderList(camera);
var that = this;

@@ -129,12 +238,3 @@ // Use MRT if support

getMaterial: function(renderable) {
var mrtMaterial = that._getMrtMaterial(renderable);
mrtMaterial.diffuse.copy(renderable.material.diffuse);
mrtMaterial.diffuseMap = renderable.material.diffuseMap;
mrtMaterial.uniforms["roughness"] = renderable.material.roughness !== undefined ? renderable.material.roughness : 0.5;
mrtMaterial.roughnessMap = renderable.material.roughnessMap;
mrtMaterial.uniforms["metalness"] = renderable.material.metalness !== undefined ? renderable.material.metalness : 0.5;
mrtMaterial.metalnessMap = renderable.material.metalnessMap;
return mrtMaterial;
return materialCache.getMrtMaterial(renderable);
},

@@ -160,9 +260,3 @@ ifRender: function(renderable) {

getMaterial: function(renderable) {
var normalGlossinessMaterial = that._getNormalGlossinessMaterial(renderable);
normalGlossinessMaterial.diffuseMap = renderable.material.diffuseMap;
normalGlossinessMaterial.uniforms["roughness"] = renderable.material.roughness !== undefined ? renderable.material.roughness : 0.5;
normalGlossinessMaterial.roughnessMap = renderable.material.roughnessMap;
return normalGlossinessMaterial;
return materialCache.getNormalGlossinessMaterial(renderable);
},

@@ -186,10 +280,3 @@ ifRender: function(renderable) {

getMaterial: function(renderable) {
var albedoMetalnessMaterial = that._getAlbedoMetalnessMaterial(renderable);
albedoMetalnessMaterial.diffuse.copy(renderable.material.diffuse);
albedoMetalnessMaterial.diffuseMap = renderable.material.diffuseMap;
albedoMetalnessMaterial.uniforms["metalness"] = renderable.material.metalness !== undefined ? renderable.material.metalness : 0.5;
albedoMetalnessMaterial.metalnessMap = renderable.material.metalnessMap;
return albedoMetalnessMaterial;
return materialCache.getAlbedoMetalnessMaterial(renderable);
},

@@ -272,61 +359,9 @@ ifRender: function(renderable) {

this._MRTMaterials.forEach(material => material.dispose());
this._normalGlossinessMaterials.forEach(material => material.dispose());
this._albedoMetalnessMaterials.forEach(material => material.dispose());
materialCache.MRTMaterials.forEach(material => material.dispose());
materialCache.normalGlossinessMaterials.forEach(material => material.dispose());
materialCache.albedoMetalnessMaterials.forEach(material => material.dispose());
this._MRTMaterials.clear();
this._normalGlossinessMaterials.clear();
this._albedoMetalnessMaterials.clear();
},
// get materials from cache
// Avoid frequently updating materials
_getMrtMaterial: function(renderable) {
var useFlatShading = !renderable.geometry.attributes["a_Normal"];
var useDiffuseMap = renderable.material.diffuseMap;
var useRoughnessMap = !!renderable.material.roughnessMap;
var useMetalnessMap = !!renderable.material.metalnessMap;
var code = useFlatShading + "_" + useDiffuseMap + "_" + useRoughnessMap + "_" + useMetalnessMap;
if (!this._MRTMaterials.has(code)) {
var material = new ShaderMaterial(GBufferShader.MRT);
material.shading = useFlatShading ? SHADING_TYPE.FLAT_SHADING : SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
this._MRTMaterials.set(code, material);
}
return this._MRTMaterials.get(code);
},
_getNormalGlossinessMaterial: function(renderable) {
var useFlatShading = !renderable.geometry.attributes["a_Normal"];
var useDiffuseMap = renderable.material.diffuseMap;
var useRoughnessMap = !!renderable.material.roughnessMap;
var code = useFlatShading + "_" + useDiffuseMap + "_" + useRoughnessMap;
if (!this._normalGlossinessMaterials.has(code)) {
var material = new ShaderMaterial(GBufferShader.normalGlossiness);
material.shading = useFlatShading ? SHADING_TYPE.FLAT_SHADING : SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
this._normalGlossinessMaterials.set(code, material);
}
return this._normalGlossinessMaterials.get(code);
},
_getAlbedoMetalnessMaterial: function(renderable) {
var useFlatShading = !renderable.geometry.attributes["a_Normal"];
var useDiffuseMap = renderable.material.diffuseMap;
var useMetalnessMap = !!renderable.material.metalnessMap;
var code = useFlatShading + "_" + useDiffuseMap + "_" + useMetalnessMap;
if (!this._albedoMetalnessMaterials.has(code)) {
var material = new ShaderMaterial(GBufferShader.albedoMetalness);
material.shading = useFlatShading ? SHADING_TYPE.FLAT_SHADING : SHADING_TYPE.SMOOTH_SHADING;
material.alphaTest = useDiffuseMap ? 0.999 : 0; // ignore if alpha < 0.99
this._albedoMetalnessMaterials.set(code, material);
}
return this._albedoMetalnessMaterials.get(code);
materialCache.MRTMaterials.clear();
materialCache.normalGlossinessMaterials.clear();
materialCache.albedoMetalnessMaterials.clear();
}

@@ -349,5 +384,3 @@

"#include <common_vert>",
"#define USE_NORMAL",
"#include <morphtarget_pars_vert>",
"#include <skinning_pars_vert>",

@@ -357,7 +390,10 @@ "#include <normal_pars_vert>",

"void main() {",
"#include <uv_vert>",
"#include <begin_vert>",
"#include <skinning_vert>",
"#include <normal_vert>",
"#include <pvm_vert>",
" #include <uv_vert>",
" #include <begin_vert>",
" #include <morphtarget_vert>",
" #include <morphnormal_vert>",
" #include <skinning_vert>",
" #include <skinnormal_vert>",
" #include <normal_vert>",
" #include <pvm_vert>",
"}"

@@ -374,4 +410,2 @@

"#define USE_NORMAL",
"#include <packing>",

@@ -383,25 +417,25 @@ "#include <normal_pars_frag>",

"#ifdef USE_ROUGHNESSMAP",
"uniform sampler2D roughnessMap;",
" uniform sampler2D roughnessMap;",
"#endif",
"void main() {",
"#if defined(USE_DIFFUSE_MAP) && defined(ALPHATEST)",
"vec4 texelColor = texture2D( diffuseMap, v_Uv );",
" #if defined(USE_DIFFUSE_MAP) && defined(ALPHATEST)",
" vec4 texelColor = texture2D( diffuseMap, v_Uv );",
"float alpha = texelColor.a * u_Opacity;",
"if(alpha < ALPHATEST) discard;",
"#endif",
" float alpha = texelColor.a * u_Opacity;",
" if(alpha < ALPHATEST) discard;",
" #endif",
"vec3 normal = normalize(v_Normal);",
" vec3 normal = normalize(v_Normal);",
"float roughnessFactor = roughness;",
"#ifdef USE_ROUGHNESSMAP",
"roughnessFactor *= texture2D( roughnessMap, v_Uv ).g;",
"#endif",
" float roughnessFactor = roughness;",
" #ifdef USE_ROUGHNESSMAP",
" roughnessFactor *= texture2D( roughnessMap, v_Uv ).g;",
" #endif",
"vec4 packedNormalGlossiness;",
"packedNormalGlossiness.xyz = normal * 0.5 + 0.5;",
"packedNormalGlossiness.w = clamp(1. - roughnessFactor, 0., 1.);",
" vec4 packedNormalGlossiness;",
" packedNormalGlossiness.xyz = normal * 0.5 + 0.5;",
" packedNormalGlossiness.w = clamp(1. - roughnessFactor, 0., 1.);",
"gl_FragColor = packedNormalGlossiness;",
" gl_FragColor = packedNormalGlossiness;",
"}"

@@ -426,9 +460,11 @@

"#include <envMap_pars_vert>",
"#include <morphtarget_pars_vert>",
"#include <skinning_pars_vert>",
"void main() {",
"#include <begin_vert>",
"#include <skinning_vert>",
"#include <pvm_vert>",
"#include <uv_vert>",
"#include <color_vert>",
" #include <begin_vert>",
" #include <morphtarget_vert>",
" #include <skinning_vert>",
" #include <pvm_vert>",
" #include <uv_vert>",
" #include <color_vert>",
"}"

@@ -446,18 +482,16 @@ ].join("\n"),

"#ifdef USE_METALNESSMAP",
"uniform sampler2D metalnessMap;",
" uniform sampler2D metalnessMap;",
"#endif",
"void main() {",
" vec4 outColor = vec4( u_Color, 1.0 );",
" #include <diffuseMap_frag>",
" vec3 diffuseColor = outColor.xyz * outColor.a;",
"vec4 outColor = vec4( u_Color, 1.0 );",
"#include <diffuseMap_frag>",
"vec3 diffuseColor = outColor.xyz * outColor.a;",
" float metalnessFactor = metalness;",
" #ifdef USE_METALNESSMAP",
" metalnessFactor *= texture2D( metalnessMap, v_Uv ).b;",
" #endif",
"float metalnessFactor = metalness;",
"#ifdef USE_METALNESSMAP",
"metalnessFactor *= texture2D( metalnessMap, v_Uv ).b;",
"#endif",
"gl_FragColor = vec4( diffuseColor.xyz, metalnessFactor );",
" gl_FragColor = vec4( diffuseColor.xyz, metalnessFactor );",
"}"

@@ -479,3 +513,2 @@

vertexShader: [
"#define USE_NORMAL",
"#include <common_vert>",

@@ -486,10 +519,14 @@ "#include <uv_pars_vert>",

"#include <envMap_pars_vert>",
"#include <morphtarget_pars_vert>",
"#include <skinning_pars_vert>",
"void main() {",
"#include <begin_vert>",
"#include <skinning_vert>",
"#include <pvm_vert>",
"#include <uv_vert>",
"#include <normal_vert>",
"#include <color_vert>",
" #include <begin_vert>",
" #include <morphtarget_vert>",
" #include <morphnormal_vert>",
" #include <skinning_vert>",
" #include <skinnormal_vert>",
" #include <pvm_vert>",
" #include <uv_vert>",
" #include <normal_vert>",
" #include <color_vert>",
"}"

@@ -507,4 +544,2 @@ ].join("\n"),

"#define USE_NORMAL",
"#include <packing>",

@@ -517,38 +552,38 @@ "#include <normal_pars_frag>",

"#ifdef USE_ROUGHNESSMAP",
"uniform sampler2D roughnessMap;",
" uniform sampler2D roughnessMap;",
"#endif",
"#ifdef USE_METALNESSMAP",
"uniform sampler2D metalnessMap;",
" uniform sampler2D metalnessMap;",
"#endif",
"void main() {",
"vec4 outColor = vec4( u_Color, 1.0 );",
"#include <diffuseMap_frag>",
"vec3 diffuseColor = outColor.xyz * outColor.a;",
" vec4 outColor = vec4( u_Color, 1.0 );",
" #include <diffuseMap_frag>",
" vec3 diffuseColor = outColor.xyz * outColor.a;",
"float metalnessFactor = metalness;",
"#ifdef USE_METALNESSMAP",
"metalnessFactor *= texture2D( metalnessMap, v_Uv ).b;",
"#endif",
" float metalnessFactor = metalness;",
" #ifdef USE_METALNESSMAP",
" metalnessFactor *= texture2D( metalnessMap, v_Uv ).b;",
" #endif",
"gl_FragData[1] = vec4( outColor.xyz, metalnessFactor );",
" gl_FragData[1] = vec4( outColor.xyz, metalnessFactor );",
"#if defined(USE_DIFFUSE_MAP) && defined(ALPHATEST)",
"float alpha = outColor.a * u_Opacity;",
"if(alpha < ALPHATEST) discard;",
"#endif",
" #if defined(USE_DIFFUSE_MAP) && defined(ALPHATEST)",
" float alpha = outColor.a * u_Opacity;",
" if(alpha < ALPHATEST) discard;",
" #endif",
"vec3 normal = normalize(v_Normal);",
" vec3 normal = normalize(v_Normal);",
"float roughnessFactor = roughness;",
"#ifdef USE_ROUGHNESSMAP",
"roughnessFactor *= texture2D( roughnessMap, v_Uv ).g;",
"#endif",
" float roughnessFactor = roughness;",
" #ifdef USE_ROUGHNESSMAP",
" roughnessFactor *= texture2D( roughnessMap, v_Uv ).g;",
" #endif",
"vec4 packedNormalGlossiness;",
"packedNormalGlossiness.xyz = normal * 0.5 + 0.5;",
"packedNormalGlossiness.w = clamp(1. - roughnessFactor, 0., 1.);",
" vec4 packedNormalGlossiness;",
" packedNormalGlossiness.xyz = normal * 0.5 + 0.5;",
" packedNormalGlossiness.w = clamp(1. - roughnessFactor, 0., 1.);",
"gl_FragData[0] = packedNormalGlossiness;",
" gl_FragData[0] = packedNormalGlossiness;",
"}"

@@ -587,3 +622,3 @@

"gl_Position = u_Projection * u_View * u_Model * vec4( a_Position, 1.0 );",
" gl_Position = u_Projection * u_View * u_Model * vec4( a_Position, 1.0 );",

@@ -617,45 +652,45 @@ "}"

"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
" vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
"vec4 texel1 = texture2D(normalGlossinessTexture, texCoord);",
"vec4 texel3 = texture2D(albedoMetalnessTexture, texCoord);",
" vec4 texel1 = texture2D(normalGlossinessTexture, texCoord);",
" vec4 texel3 = texture2D(albedoMetalnessTexture, texCoord);",
// Is empty
"if (dot(texel1.rgb, vec3(1.0)) == 0.0) {",
"discard;",
"}",
" if (dot(texel1.rgb, vec3(1.0)) == 0.0) {",
" discard;",
" }",
"float glossiness = texel1.a;",
"float metalness = texel3.a;",
" float glossiness = texel1.a;",
" float metalness = texel3.a;",
"vec3 N = texel1.rgb * 2.0 - 1.0;",
" vec3 N = texel1.rgb * 2.0 - 1.0;",
// Depth buffer range is 0.0 - 1.0
"float z = texture2D(depthTexture, texCoord).r * 2.0 - 1.0;",
" float z = texture2D(depthTexture, texCoord).r * 2.0 - 1.0;",
"vec2 xy = texCoord * 2.0 - 1.0;",
" vec2 xy = texCoord * 2.0 - 1.0;",
"vec4 projectedPos = vec4(xy, z, 1.0);",
"vec4 p4 = matProjViewInverse * projectedPos;",
" vec4 projectedPos = vec4(xy, z, 1.0);",
" vec4 p4 = matProjViewInverse * projectedPos;",
"vec3 position = p4.xyz / p4.w;",
" vec3 position = p4.xyz / p4.w;",
"vec3 albedo = texel3.rgb;",
" vec3 albedo = texel3.rgb;",
"vec3 diffuseColor = albedo * (1.0 - metalness);",
"vec3 specularColor = mix(vec3(0.04), albedo, metalness);",
" vec3 diffuseColor = albedo * (1.0 - metalness);",
" vec3 specularColor = mix(vec3(0.04), albedo, metalness);",
"if (debug == 0) {",
"gl_FragColor = vec4(N, 1.0);",
"} else if (debug == 1) {",
"gl_FragColor = vec4(vec3(z), 1.0);",
"} else if (debug == 2) {",
"gl_FragColor = vec4(position, 1.0);",
"} else if (debug == 3) {",
"gl_FragColor = vec4(vec3(glossiness), 1.0);",
"} else if (debug == 4) {",
"gl_FragColor = vec4(vec3(metalness), 1.0);",
"} else {",
"gl_FragColor = vec4(albedo, 1.0);",
"}",
" if (debug == 0) {",
" gl_FragColor = vec4(N, 1.0);",
" } else if (debug == 1) {",
" gl_FragColor = vec4(vec3(z), 1.0);",
" } else if (debug == 2) {",
" gl_FragColor = vec4(position, 1.0);",
" } else if (debug == 3) {",
" gl_FragColor = vec4(vec3(glossiness), 1.0);",
" } else if (debug == 4) {",
" gl_FragColor = vec4(vec3(metalness), 1.0);",
" } else {",
" gl_FragColor = vec4(albedo, 1.0);",
" }",

@@ -662,0 +697,0 @@ "}"

@@ -0,0 +0,0 @@ /**

@@ -99,3 +99,2 @@ /**

var parent;
var breaked = false;
while (node.parent) {

@@ -168,3 +167,3 @@ parent = node.parent;

if (!boneMap[boneName]) {
console.log(boneName)
console.log(boneName);
continue;

@@ -265,3 +264,3 @@ }

var prop = json.properties;
var prop;

@@ -354,7 +353,5 @@ for (var key in json.properties) {

var bone, name, offset, weights, weight;
var bone, weights, weight;
for (var i = 0; i < bones.length; i++) {
bone = bones[i];
name = bone.name;
offset = bone.offsetmatrix;
weights = bone.weights;

@@ -361,0 +358,0 @@ for (var j = 0; j < weights.length; j++) {

@@ -126,3 +126,3 @@ /**

} else {
var errorMsg = 'zen3d.DRACOLoader: Unknown geometry type.'
var errorMsg = 'zen3d.DRACOLoader: Unknown geometry type.';
console.error(errorMsg);

@@ -314,4 +314,4 @@ throw new Error(errorMsg);

var stripsArray = new dracoDecoder.DracoInt32Array();
var numStrips = decoder.GetTriangleStripsFromMesh(
dracoGeometry, stripsArray);
// var numStrips = decoder.GetTriangleStripsFromMesh(
// dracoGeometry, stripsArray);
geometryBuffer.indices = new Array(stripsArray.size());

@@ -318,0 +318,0 @@ for (var i = 0; i < stripsArray.size(); ++i) {

@@ -518,6 +518,6 @@ /**

var meshReferences = this.json.meshReferences;
var meshUses = this.json.meshUses;
var meshReferences = json.meshReferences;
var meshUses = json.meshUses;
var nodeDef = this.json.nodes[nodeIndex];
var nodeDef = json.nodes[nodeIndex];

@@ -694,4 +694,19 @@ return this.getMultiDependencies([

var track = new TypedKeyframeTrack(node, PATH_PROPERTIES[target.path], input, output);
var targetNodes = [];
if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
node.traverse(function(object) {
if (object.type === OBJECT_TYPE.MESH && object.morphTargetInfluences) {
targetNodes.push(object);
}
});
} else {
targetNodes.push(node);
}
for (var j = 0, jl = targetNodes.length; j < jl; j++) {
var track = new TypedKeyframeTrack(targetNodes[j], PATH_PROPERTIES[target.path], input, output);
tracks.push(track);
}
var maxTime = input[input.length - 1];

@@ -701,4 +716,2 @@ if (endFrame < maxTime) {

}
tracks.push(track);
}

@@ -728,3 +741,2 @@ }

var json = this.json;
var extensions = this.extensions;

@@ -1607,3 +1619,2 @@ var meshDef = json.meshes[meshIndex];

var BINARY_EXTENSION_BUFFER_NAME = 'binary_glTF';
var BINARY_EXTENSION_HEADER_MAGIC = 'glTF';

@@ -1610,0 +1621,0 @@ var BINARY_EXTENSION_HEADER_LENGTH = 12;

@@ -79,3 +79,3 @@ /*

return FLOAT_VIEW[0];
}
};
}(),

@@ -95,3 +95,2 @@

var sizeRandomness = 0;
var smoothPosition = false;

@@ -131,3 +130,3 @@ var maxVel = 2;

// convert turbulence rating to something we can pack into a vec4
var turbulence = Math.floor(turbulence * 254);
turbulence = Math.floor(turbulence * 254);

@@ -172,3 +171,3 @@ // clamp our value to between 0. and 1.

}
}
};
}(),

@@ -175,0 +174,0 @@

@@ -78,3 +78,3 @@ /**

return function updateMatrix() {
return function updateMatrix(force) {
var bones = this.bones;

@@ -111,3 +111,3 @@

Mesh.prototype.updateMatrix.call(this);
Mesh.prototype.updateMatrix.call(this, force);
};

@@ -114,0 +114,0 @@ }();

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -174,5 +174,3 @@ /**

"#include <common_vert>",
"#define USE_NORMAL",
"#include <morphtarget_pars_vert>",
"#include <skinning_pars_vert>",

@@ -185,3 +183,6 @@ "#include <normal_pars_vert>",

"#include <begin_vert>",
"#include <morphtarget_vert>",
"#include <morphnormal_vert>",
"#include <skinning_vert>",
"#include <skinnormal_vert>",
"#include <normal_vert>",

@@ -201,4 +202,2 @@ "#include <pvm_vert>",

"#define USE_NORMAL",
"#include <packing>",

@@ -697,5 +696,3 @@ "#include <normal_pars_frag>",

"#include <common_vert>",
"#define USE_NORMAL",
"#include <morphtarget_pars_vert>",
"#include <skinning_pars_vert>",

@@ -708,3 +705,6 @@ "#include <normal_pars_vert>",

"#include <begin_vert>",
"#include <morphtarget_vert>",
"#include <morphnormal_vert>",
"#include <skinning_vert>",
"#include <skinnormal_vert>",
"#include <normal_vert>",

@@ -723,5 +723,2 @@ "#include <pvm_vert>",

"#include <uv_pars_frag>",
"#define USE_NORMAL",
"#include <packing>",

@@ -728,0 +725,0 @@ "#include <normal_pars_frag>",

@@ -21,3 +21,3 @@ /**

this.matrixAutoUpdate && scene.updateMatrix();
this.lightsAutoupdate && scene.updateLights();
this.lightsAutoUpdate && scene.updateLights();

@@ -24,0 +24,0 @@ if (this.shadowAutoUpdate || this.shadowNeedsUpdate) {

@@ -11,2 +11,3 @@ /**

} from "../../build/zen3d.module.js";
import { BlendShader } from "./shaders/BlendShader.js";

@@ -13,0 +14,0 @@ var SuperSampling = function(width, height, samplingSize) {

@@ -106,3 +106,3 @@ /**

for (i = 0, il = faces2.length; i < il; i++) {
var face = faces2[i], faceCopy, normal, color;
var face = faces2[i], faceCopy;

@@ -227,6 +227,4 @@ faceCopy = new VOXFace3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);

var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0;
// var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0;
var index = 0;
for (var i = 0; i < faces.length; i++) {

@@ -233,0 +231,0 @@ var posArray, normalArray, colorArray, uvArray;

{
"name": "zen-3d",
"version": "0.0.2",
"version": "0.0.3",
"description": "JavaScript 3D library",
"main": "build/zen3d.js",
"repository": "shawn0326/zen-3d",
"jsnext:main": "build/zen3d.module.js",
"module": "build/zen3d.module.js",
"repository": {
"type": "git",
"url": "https://github.com/shawn0326/zen-3d"
},
"files": [

@@ -28,4 +31,12 @@ "build/zen3d.js",

"zen-3d",
"javascript",
"3d",
"webgl"
"virtual-reality",
"augmented-reality",
"webgl",
"webgl2",
"webvr",
"webxr",
"canvas",
"html5"
],

@@ -39,8 +50,9 @@ "author": "shawn0326",

"devDependencies": {
"eslint": "^6.8.0",
"jsdoc": "^3.6.3",
"acorn": "^7.3.1",
"eslint": "^7.5.0",
"jsdoc": "^3.6.5",
"live-server": "^1.2.1",
"rollup": "^1.32.1",
"rollup": "^2.23.0",
"rollup-plugin-buble": "^0.19.8",
"uglify-js": "^3.8.1"
"uglify-js": "^3.10.0"
},

@@ -47,0 +59,0 @@ "scripts": {

zen-3d
========
[![Latest NPM release][npm-badge]][npm-badge-url]
[![NPM Package][npm]][npm-url]
[![Build Size][build-size]][build-size-url]
[![NPM Downloads][npm-downloads]][npmtrends-url]
[![License][license-badge]][license-badge-url]
[![Issues][issues-badge]][issues-badge-url]
![Dev Dependencies][devDependencies-badge]
[![Dev Dependencies][dev-dependencies]][dev-dependencies-url]
[![Language Grade][lgtm]][lgtm-url]

@@ -36,2 +39,76 @@ ### JavaScript 3D library ###

or import as es6 module:
````javascript
import * as zen3d from 'js/zen3d.module.js';
````
draw a simple cube:
````javascript
var width = window.innerWidth || 2;
var height = window.innerHeight || 2;
var canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
document.body.appendChild(canvas);
var gl = canvas.getContext("webgl2", {
antialias: true,
alpha: false,
stencil: true
});
var glCore = new zen3d.WebGLCore(gl);
glCore.state.colorBuffer.setClear(0.1, 0.1, 0.1, 1);
var backRenderTarget = new zen3d.RenderTargetBack(canvas);
var scene = new zen3d.Scene();
var geometry = new zen3d.CubeGeometry(8, 8, 8);
var material = new zen3d.PBRMaterial();
var mesh = new zen3d.Mesh(geometry, material);
scene.add(mesh);
var ambientLight = new zen3d.AmbientLight(0xffffff);
scene.add(ambientLight);
var directionalLight = new zen3d.DirectionalLight(0xffffff);
directionalLight.position.set(-5, 5, 5);
directionalLight.lookAt(new zen3d.Vector3(), new zen3d.Vector3(0, 1, 0));
scene.add(directionalLight);
var camera = new zen3d.Camera();
camera.position.set(0, 10, 30);
camera.lookAt(new zen3d.Vector3(0, 0, 0), new zen3d.Vector3(0, 1, 0));
camera.setPerspective(45 / 180 * Math.PI, width / height, 1, 1000);
scene.add(camera);
function loop(count) {
requestAnimationFrame(loop);
mesh.euler.y = count / 1000 * .5; // rotate cube
scene.updateMatrix();
scene.updateLights();
glCore.renderTarget.setRenderTarget(backRenderTarget);
glCore.clear(true, true, false);
glCore.render(scene, camera);
}
requestAnimationFrame(loop);
function onWindowResize() {
width = window.innerWidth || 2;
height = window.innerHeight || 2;
camera.setPerspective(45 / 180 * Math.PI, width / height, 1, 1000);
backRenderTarget.resize(width, height);
}
window.addEventListener("resize", onWindowResize, false);
````
### 3D Format Support ###

@@ -55,27 +132,2 @@

### Build ###
* install [Node.js](https://nodejs.org) (include NPM).
* install devDependencies packages.
````
npm install
````
* you can run the following scripts
````
// build shader & zen3d
npm run default
// build zen3d
npm run build
// build extensions
npm run extension
// start a server to run examples
npm run example
````
build path is `./build`.
### Projects ###

@@ -85,10 +137,13 @@

### About Me ###
### Change log ###
* Blog: [Half Lab](http://www.halflab.me)
* Email: shawn0326@163.com
* Weibo: [@谢帅shawn](http://weibo.com/shawn0326)
[Releases](https://github.com/shawn0326/zen-3d/releases)
[npm-badge]: https://img.shields.io/npm/v/zen-3d.svg
[npm-badge-url]: https://www.npmjs.com/package/zen-3d
[npm]: https://img.shields.io/npm/v/zen-3d
[npm-url]: https://www.npmjs.com/package/zen-3d
[build-size]: https://badgen.net/bundlephobia/minzip/zen-3d
[build-size-url]: https://bundlephobia.com/result?p=zen-3d
[npm-downloads]: https://img.shields.io/npm/dw/zen-3d
[npmtrends-url]: https://www.npmtrends.com/zen-3d
[license-badge]: https://img.shields.io/npm/l/zen-3d.svg

@@ -98,2 +153,5 @@ [license-badge-url]: ./LICENSE

[issues-badge-url]: https://github.com/shawn0326/zen-3d/issues
[devDependencies-badge]: https://img.shields.io/librariesio/github/shawn0326/zen-3d.svg
[dev-dependencies]: https://img.shields.io/david/dev/shawn0326/zen-3d
[dev-dependencies-url]: https://david-dm.org/shawn0326/zen-3d#info=devDependencies
[lgtm]: https://img.shields.io/lgtm/alerts/github/shawn0326/zen-3d
[lgtm-url]: https://lgtm.com/projects/g/shawn0326/zen-3d/
import { Matrix4 } from '../../math/Matrix4.js';
var _offsetMatrix = new Matrix4();
/**

@@ -67,16 +69,12 @@ * Use an array of bones to create a skeleton that can be used by a SkinnedMesh.

updateBones: function() {
var offsetMatrix = new Matrix4();
for (var i = 0; i < this.bones.length; i++) {
var bone = this.bones[i];
_offsetMatrix.multiplyMatrices(bone.worldMatrix, bone.offsetMatrix);
_offsetMatrix.toArray(this.boneMatrices, i * 16);
}
return function updateBones() {
for (var i = 0; i < this.bones.length; i++) {
var bone = this.bones[i];
offsetMatrix.multiplyMatrices(bone.worldMatrix, bone.offsetMatrix);
offsetMatrix.toArray(this.boneMatrices, i * 16);
}
if (this.boneTexture !== undefined) {
this.boneTexture.version++;
}
if (this.boneTexture !== undefined) {
this.boneTexture.version++;
}
}(),
},

@@ -83,0 +81,0 @@ /**

@@ -0,1 +1,6 @@

var _lut = [];
for (var i = 0; i < 256; i++) {
_lut[i] = (i < 16 ? '0' : '') + (i).toString(16);
}
/**

@@ -8,24 +13,17 @@ * Method for generate uuid.

*/
export var generateUUID = (function () {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
var uuid = new Array(36);
var rnd = 0, r;
export function generateUUID() {
// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
return function generateUUID() {
for (var i = 0; i < 36; i++) {
if (i === 8 || i === 13 || i === 18 || i === 23) {
uuid[i] = '-';
} else if (i === 14) {
uuid[i] = '4';
} else {
if (rnd <= 0x02) rnd = 0x2000000 + (Math.random() * 0x1000000) | 0;
r = rnd & 0xf;
rnd = rnd >> 4;
uuid[i] = chars[(i === 19) ? (r & 0x3) | 0x8 : r];
}
}
const d0 = Math.random() * 0xffffffff | 0;
const d1 = Math.random() * 0xffffffff | 0;
const d2 = Math.random() * 0xffffffff | 0;
const d3 = Math.random() * 0xffffffff | 0;
const uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' +
_lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' +
_lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] +
_lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff];
return uuid.join('');
};
})();
// .toUpperCase() here flattens concatenated strings to save heap memory space.
return uuid.toUpperCase();
}

@@ -32,0 +30,0 @@ /**

@@ -42,2 +42,3 @@ /**

PBR2: "pbr2",
MATCAP: 'matcap',
POINT: "point",

@@ -248,2 +249,18 @@ LINE: "line",

/**
* Enum for WebGL Operation.
* @name zen3d.WEBGL_OP
* @readonly
* @enum {number}
*/
export var WEBGL_OP = {
KEEP: 0x1E00,
REPLACE: 0x1E01,
INCR: 0x1E02,
DECR: 0x1E03,
INVERT: 0x150A,
INCR_WRAP: 0x8507,
DECR_WRAP: 0x8508
}
/**
* Enum for WebGL Uniform Type.

@@ -250,0 +267,0 @@ * Taken from the {@link http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14 WebGl spec}.

@@ -72,2 +72,9 @@ import { EventDispatcher } from '../EventDispatcher.js';

this.groups = [];
/**
* A version number, incremented every time the attribute object or index object changes to mark VAO drity.
* @type {Integer}
* @default 0
*/
this.version = 0;
}

@@ -74,0 +81,0 @@

@@ -14,3 +14,3 @@ import { FileLoader } from './FileLoader.js';

this.manager = (manager !== undefined) ? manager : DefaultLoadingManager;
this.type = zen3d.WEBGL_PIXEL_TYPE.UNSIGNED_BYTE;
this.type = WEBGL_PIXEL_TYPE.UNSIGNED_BYTE;
}

@@ -158,6 +158,6 @@

if (match = line.match(gamma_re)) {
header.gamma = parseFloat(match[1], 10);
header.gamma = parseFloat(match[1]);
}
if (match = line.match(exposure_re)) {
header.exposure = parseFloat(match[1], 10);
header.exposure = parseFloat(match[1]);
}

@@ -207,3 +207,3 @@ if (match = line.match(format_re)) {

if (!data_rgba || !data_rgba.length) {
if (!data_rgba.length) {
return rgbe_error(rgbe_memory_error, "unable to allocate buffer space");

@@ -210,0 +210,0 @@ }

@@ -68,2 +68,3 @@ /**

export { PBR2Material } from './material/PBR2Material.js';
export { MatcapMaterial } from './material/MatcapMaterial.js';
export { PointsMaterial } from './material/PointsMaterial.js';

@@ -70,0 +71,0 @@ export { LineMaterial } from './material/LineMaterial.js';

import { EventDispatcher } from '../EventDispatcher.js';
import { BLEND_TYPE, BLEND_EQUATION, BLEND_FACTOR, ENVMAP_COMBINE_TYPE, DRAW_SIDE, SHADING_TYPE, DRAW_MODE, WEBGL_COMPARE_FUNC, VERTEX_COLOR } from '../const.js';
import { BLEND_TYPE, BLEND_EQUATION, BLEND_FACTOR, ENVMAP_COMBINE_TYPE, DRAW_SIDE, SHADING_TYPE, DRAW_MODE, WEBGL_COMPARE_FUNC, WEBGL_OP, VERTEX_COLOR } from '../const.js';
import { Color3 } from '../math/Color3.js';

@@ -299,2 +299,115 @@ import { generateUUID } from '../base.js';

/**
* 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.
* @type {boolean}
* @default false
*/
this.stencilTest = false;
/**
* The bit mask to use when writing to the stencil buffer.
* @type {number}
* @default 0xFF
*/
this.stencilWriteMask = 0xff;
/**
* The stencil comparison function to use.
* See the {@link zen3d.WEBGL_COMPARE_FUNC} constants for all possible values.
* @type {zen3d.WEBGL_COMPARE_FUNC}
* @default zen3d.WEBGL_COMPARE_FUNC.ALWAYS
*/
this.stencilFunc = WEBGL_COMPARE_FUNC.ALWAYS;
/**
* The value to use when performing stencil comparisons or stencil operations.
* @type {number}
* @default 0
*/
this.stencilRef = 0;
/**
* The bit mask to use when comparing against the stencil buffer.
* @type {number}
* @default 0xFF
*/
this.stencilFuncMask = 0xff;
/**
* Which stencil operation to perform when the comparison function returns false.
* See the {@link zen3d.WEBGL_OP} constants for all possible values.
* @type {zen3d.WEBGL_OP}
* @default zen3d.WEBGL_OP.KEEP
*/
this.stencilFail = WEBGL_OP.KEEP;
/**
* Which stencil operation to perform when the comparison function returns true but the depth test fails.
* See the {@link zen3d.WEBGL_OP} constants for all possible values.
* @type {zen3d.WEBGL_OP}
* @default zen3d.WEBGL_OP.KEEP
*/
this.stencilZFail = WEBGL_OP.KEEP;
/**
* Which stencil operation to perform when the comparison function returns true and the depth test passes.
* See the {@link zen3d.WEBGL_OP} constants for all possible values.
* @type {zen3d.WEBGL_OP}
* @default zen3d.WEBGL_OP.KEEP
*/
this.stencilZPass = WEBGL_OP.KEEP;
/**
* The stencil comparison function to use.
* See the {@link zen3d.WEBGL_COMPARE_FUNC} constants for all possible values.
* You can explicitly specify the two-sided stencil function state by defining stencilFuncBack, stencilRefBack and stencilFuncMaskBack.
* @type {zen3d.WEBGL_COMPARE_FUNC|null}
* @default null
*/
this.stencilFuncBack = null;
/**
* The value to use when performing stencil comparisons or stencil operations.
* You can explicitly specify the two-sided stencil function state by defining stencilFuncBack, stencilRefBack and stencilFuncMaskBack.
* @type {number|null}
* @default null
*/
this.stencilRefBack = null;
/**
* The bit mask to use when comparing against the stencil buffer.
* You can explicitly specify the two-sided stencil function state by defining stencilFuncBack, stencilRefBack and stencilFuncMaskBack.
* @type {number|null}
* @default null
*/
this.stencilFuncMaskBack = null;
/**
* Which stencil operation to perform when the comparison function returns false.
* See the {@link zen3d.WEBGL_OP} constants for all possible values.
* You can explicitly specify the two-sided stencil op state by defining stencilFailBack, stencilZFailBack and stencilZPassBack.
* @type {zen3d.WEBGL_OP|null}
* @default null
*/
this.stencilFailBack = null;
/**
* Which stencil operation to perform when the comparison function returns true but the depth test fails.
* See the {@link zen3d.WEBGL_OP} constants for all possible values.
* You can explicitly specify the two-sided stencil op state by defining stencilFailBack, stencilZFailBack and stencilZPassBack.
* @type {zen3d.WEBGL_OP|null}
* @default null
*/
this.stencilZFailBack = null;
/**
* Which stencil operation to perform when the comparison function returns true and the depth test passes.
* See the {@link zen3d.WEBGL_OP} constants for all possible values.
* You can explicitly specify the two-sided stencil op state by defining stencilFailBack, stencilZFailBack and stencilZPassBack.
* @type {zen3d.WEBGL_OP|null}
* @default null
*/
this.stencilZPassBack = null;
/**
* Sets the alpha value to be used when running an alpha test.

@@ -301,0 +414,0 @@ * The material will not be renderered if the opacity is lower than this value.

@@ -1,4 +0,14 @@

import { Vector3 } from './Vector3.js';
var _points = [
new Vector3(),
new Vector3(),
new Vector3(),
new Vector3(),
new Vector3(),
new Vector3(),
new Vector3(),
new Vector3()
];
/**

@@ -138,34 +148,21 @@ * @constructor

*/
applyMatrix4: function() {
var points = [
new Vector3(),
new Vector3(),
new Vector3(),
new Vector3(),
new Vector3(),
new Vector3(),
new Vector3(),
new Vector3()
];
applyMatrix4: function(matrix) {
// transform of empty box is an empty box.
if (this.isEmpty()) return this;
return function applyMatrix4(matrix) {
// transform of empty box is an empty box.
if (this.isEmpty()) return this;
// NOTE: I am using a binary pattern to specify all 2^3 combinations below
_points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
_points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
_points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
_points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
_points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
_points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
_points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
_points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
// NOTE: I am using a binary pattern to specify all 2^3 combinations below
points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
this.setFromPoints(_points);
this.setFromPoints(points);
return this;
},
return this;
};
}(),
/**

@@ -172,0 +169,0 @@ *

@@ -20,2 +20,15 @@ /**

function euclideanModulo(n, m) {
return ((n % m) + m) % m;
}
function hue2rgb(p, q, t) {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1 / 6) return p + (q - p) * 6 * t;
if (t < 1 / 2) return q;
if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
return p;
}
Object.assign(Color3.prototype, /** @lends zen3d.Color3.prototype */{

@@ -77,36 +90,21 @@

*/
setHSL: function() {
function euclideanModulo(n, m) {
return ((n % m) + m) % m;
}
setHSL: function(h, s, l) {
// h,s,l ranges are in 0.0 - 1.0
h = euclideanModulo(h, 1);
s = Math.max(0, Math.min(1, s));
l = Math.max(0, Math.min(1, l));
function hue2rgb(p, q, t) {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1 / 6) return p + (q - p) * 6 * t;
if (t < 1 / 2) return q;
if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
return p;
if (s === 0) {
this.r = this.g = this.b = l;
} else {
var p = l <= 0.5 ? l * (1 + s) : l + s - (l * s);
var q = (2 * l) - p;
this.r = hue2rgb(q, p, h + 1 / 3);
this.g = hue2rgb(q, p, h);
this.b = hue2rgb(q, p, h - 1 / 3);
}
return this;
},
return function setHSL(h, s, l) {
// h,s,l ranges are in 0.0 - 1.0
h = euclideanModulo(h, 1);
s = Math.max(0, Math.min(1, s));
l = Math.max(0, Math.min(1, l));
if (s === 0) {
this.r = this.g = this.b = l;
} else {
var p = l <= 0.5 ? l * (1 + s) : l + s - (l * s);
var q = (2 * l) - p;
this.r = hue2rgb(q, p, h + 1 / 3);
this.g = hue2rgb(q, p, h);
this.b = hue2rgb(q, p, h - 1 / 3);
}
return this;
};
}(),
/**

@@ -113,0 +111,0 @@ *

import { Vector2 } from './Vector2.js';
var _A0 = new Vector2();
var _B0 = new Vector2();
var _A1 = new Vector2();
var _B1 = new Vector2();
/**

@@ -37,33 +42,22 @@ * @constructor

*/
calc: function () {
var A0 = new Vector2();
var B0 = new Vector2();
var A1 = new Vector2();
var B1 = new Vector2();
calc: function (t) {
_A0.copy(this.posPoints[this.posPoints.length - 1]);
_B0.copy(this.ctrlPoints[this.ctrlPoints.length - 1]);
_A1.copy(_A0);
_B1.copy(_B0);
return function calc(t) {
for (var i = 0; i < this.segCount; i++) {
if (t >= this.posPoints[i].x && t <= this.posPoints[i + 1].x) {
A0.copy(this.posPoints[i]);
A1.copy(this.posPoints[i + 1]);
B0.copy(this.ctrlPoints[i]);
B1.copy(this.ctrlPoints[i + 1]);
break;
}
for (var i = 0; i < this.segCount; i++) {
if (t >= this.posPoints[i].x && t <= this.posPoints[i + 1].x) {
_A0.copy(this.posPoints[i]);
_A1.copy(this.posPoints[i + 1]);
_B0.copy(this.ctrlPoints[i]);
_B1.copy(this.ctrlPoints[i + 1]);
break;
}
}
if (!A0) {
A0.copy(this.posPoints[this.posPoints.length - 1]);
}
if (!B0) {
B0.copy(this.ctrlPoints[this.ctrlPoints.length - 1]);
}
A1.copy(A1 || A0);
B1.copy(B1 || B0);
t = (t - _A0.x) / (_A1.x - _A0.x);
return this._cubic_bezier(_A0.y, _B0.y, _B1.y, _A1.y, t);
},
t = (t - A0.x) / (A1.x - A0.x);
return this._cubic_bezier(A0.y, B0.y, B1.y, A1.y, t);
}
}(),
/**

@@ -70,0 +64,0 @@ * Average x sampler.

import { Matrix4 } from './Matrix4.js';
var _matrix = new Matrix4();
/**

@@ -179,12 +181,7 @@ * a Euler class

*/
setFromQuaternion: function() {
var matrix = new Matrix4();
setFromQuaternion: function(q, order, update) {
q.toMatrix4(_matrix);
return this.setFromRotationMatrix(_matrix, order, update);
},
return function(q, order, update) {
q.toMatrix4(matrix);
return this.setFromRotationMatrix(matrix, order, update);
};
}(),
onChange: function(callback) {

@@ -191,0 +188,0 @@ this.onChangeCallback = callback;

import { Plane } from './Plane.js';
import { Vector3 } from './Vector3.js';
var _vec3_1 = new Vector3();
/**

@@ -86,33 +88,24 @@ * @constructor

intersectsBox: function() {
var p1 = new Vector3();
var p2 = new Vector3();
intersectsBox: function(box) {
var planes = this.planes;
return function intersectsBox(box) {
var planes = this.planes;
for (var i = 0; i < 6; i++) {
var plane = planes[i];
for (var i = 0; i < 6; i++) {
var plane = planes[i];
// corner at max distance
p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
_vec3_1.x = plane.normal.x > 0 ? box.max.x : box.min.x;
_vec3_1.y = plane.normal.y > 0 ? box.max.y : box.min.y;
_vec3_1.z = plane.normal.z > 0 ? box.max.z : box.min.z;
var d1 = plane.distanceToPoint(p1);
var d2 = plane.distanceToPoint(p2);
// if both outside plane, no intersection
// if both outside plane, no intersection
if (d1 < 0 && d2 < 0) {
return false;
}
if (plane.distanceToPoint(_vec3_1) < 0) {
return false;
}
return true;
}
}(),
return true;
},
clone: function () {

@@ -119,0 +112,0 @@ return new this.constructor().copy(this);

import { Vector3 } from './Vector3.js';
var _vec3_1 = new Vector3();
var _mat4_1 = new Matrix4();
var _x = new Vector3();
var _y = new Vector3();
var _z = new Vector3();
/**

@@ -267,35 +274,31 @@ * a 4x4 matrix class

*/
transform: function() {
var matrix = new Matrix4();
transform: function(pos, scale, rot) {
var rotMatrix = rot.toMatrix4(_mat4_1);
return function(pos, scale, rot) {
var rotMatrix = rot.toMatrix4(matrix);
var rele = rotMatrix.elements;
var ele = this.elements;
var rele = rotMatrix.elements;
var ele = this.elements;
ele[0] = rele[0] * scale.x;
ele[1] = rele[1] * scale.x;
ele[2] = rele[2] * scale.x;
ele[3] = 0;
ele[0] = rele[0] * scale.x;
ele[1] = rele[1] * scale.x;
ele[2] = rele[2] * scale.x;
ele[3] = 0;
ele[4] = rele[4] * scale.y;
ele[5] = rele[5] * scale.y;
ele[6] = rele[6] * scale.y;
ele[7] = 0;
ele[4] = rele[4] * scale.y;
ele[5] = rele[5] * scale.y;
ele[6] = rele[6] * scale.y;
ele[7] = 0;
ele[8] = rele[8] * scale.z;
ele[9] = rele[9] * scale.z;
ele[10] = rele[10] * scale.z;
ele[11] = 0;
ele[8] = rele[8] * scale.z;
ele[9] = rele[9] * scale.z;
ele[10] = rele[10] * scale.z;
ele[11] = 0;
ele[12] = pos.x;
ele[13] = pos.y;
ele[14] = pos.z;
ele[15] = 1;
ele[12] = pos.x;
ele[13] = pos.y;
ele[14] = pos.z;
ele[15] = 1;
return this;
},
return this;
}
}(),
/**

@@ -353,98 +356,123 @@ *

*/
lookAtRH: function() {
var x = new Vector3();
var y = new Vector3();
var z = new Vector3();
extractRotation: function(m) {
// this method does not support reflection matrices
return function lookAtRH(eye, target, up) {
var te = this.elements;
var te = this.elements;
var me = m.elements;
z.subVectors(eye, target);
var scaleX = 1 / _vec3_1.setFromMatrixColumn(m, 0).getLength();
var scaleY = 1 / _vec3_1.setFromMatrixColumn(m, 1).getLength();
var scaleZ = 1 / _vec3_1.setFromMatrixColumn(m, 2).getLength();
if (z.getLengthSquared() === 0) {
// eye and target are in the same position
te[0] = me[0] * scaleX;
te[1] = me[1] * scaleX;
te[2] = me[2] * scaleX;
te[3] = 0;
z.z = 1;
}
te[4] = me[4] * scaleY;
te[5] = me[5] * scaleY;
te[6] = me[6] * scaleY;
te[7] = 0;
z.normalize();
x.crossVectors(up, z);
te[8] = me[8] * scaleZ;
te[9] = me[9] * scaleZ;
te[10] = me[10] * scaleZ;
te[11] = 0;
if (x.getLengthSquared() === 0) {
// up and z are parallel
te[12] = 0;
te[13] = 0;
te[14] = 0;
te[15] = 1;
if (Math.abs(up.z) === 1) {
z.x += 0.0001;
} else {
z.z += 0.0001;
}
return this;
},
z.normalize();
x.crossVectors(up, z);
}
/**
* @method
*/
lookAtRH: function(eye, target, up) {
var te = this.elements;
x.normalize();
y.crossVectors(z, x);
_z.subVectors(eye, target);
te[0] = x.x; te[4] = y.x; te[8] = z.x;
te[1] = x.y; te[5] = y.y; te[9] = z.y;
te[2] = x.z; te[6] = y.z; te[10] = z.z;
if (_z.getLengthSquared() === 0) {
// eye and target are in the same position
return this;
_z.z = 1;
}
}(),
_z.normalize();
_x.crossVectors(up, _z);
if (_x.getLengthSquared() === 0) {
// up and z are parallel
if (Math.abs(up.z) === 1) {
_z.x += 0.0001;
} else {
_z.z += 0.0001;
}
_z.normalize();
_x.crossVectors(up, _z);
}
_x.normalize();
_y.crossVectors(_z, _x);
te[0] = _x.x; te[4] = _y.x; te[8] = _z.x;
te[1] = _x.y; te[5] = _y.y; te[9] = _z.y;
te[2] = _x.z; te[6] = _y.z; te[10] = _z.z;
return this;
},
/**
* @method
*/
decompose: function() {
var vector = new Vector3(), matrix = new Matrix4();
decompose: function(position, quaternion, scale) {
var te = this.elements;
return function(position, quaternion, scale) {
var te = this.elements;
var sx = _vec3_1.set(te[0], te[1], te[2]).getLength();
var sy = _vec3_1.set(te[4], te[5], te[6]).getLength();
var sz = _vec3_1.set(te[8], te[9], te[10]).getLength();
var sx = vector.set(te[0], te[1], te[2]).getLength();
var sy = vector.set(te[4], te[5], te[6]).getLength();
var sz = vector.set(te[8], te[9], te[10]).getLength();
// if determine is negative, we need to invert one scale
var det = this.determinant();
if (det < 0) {
sx = -sx;
}
// if determine is negative, we need to invert one scale
var det = this.determinant();
if (det < 0) {
sx = -sx;
}
position.x = te[12];
position.y = te[13];
position.z = te[14];
position.x = te[12];
position.y = te[13];
position.z = te[14];
// scale the rotation part
_mat4_1.copy(this);
// scale the rotation part
var invSX = 1 / sx;
var invSY = 1 / sy;
var invSZ = 1 / sz;
matrix.elements.set(this.elements); // at this point matrix is incomplete so we can't use .copy()
_mat4_1.elements[0] *= invSX;
_mat4_1.elements[1] *= invSX;
_mat4_1.elements[2] *= invSX;
var invSX = 1 / sx;
var invSY = 1 / sy;
var invSZ = 1 / sz;
_mat4_1.elements[4] *= invSY;
_mat4_1.elements[5] *= invSY;
_mat4_1.elements[6] *= invSY;
matrix.elements[0] *= invSX;
matrix.elements[1] *= invSX;
matrix.elements[2] *= invSX;
_mat4_1.elements[8] *= invSZ;
_mat4_1.elements[9] *= invSZ;
_mat4_1.elements[10] *= invSZ;
matrix.elements[4] *= invSY;
matrix.elements[5] *= invSY;
matrix.elements[6] *= invSY;
quaternion.setFromRotationMatrix(_mat4_1);
matrix.elements[8] *= invSZ;
matrix.elements[9] *= invSZ;
matrix.elements[10] *= invSZ;
scale.x = sx;
scale.y = sy;
scale.z = sz;
quaternion.setFromRotationMatrix(matrix);
return this;
},
scale.x = sx;
scale.y = sy;
scale.z = sz;
return this;
}
}(),
/**

@@ -451,0 +479,0 @@ * @method

import { Vector3 } from './Vector3.js';
import { Matrix3 } from './Matrix3.js';
var _vec3_1 = new Vector3();
var _mat4_1 = new Matrix3();
/**

@@ -40,2 +43,12 @@ * @constructor

*/
setFromNormalAndCoplanarPoint: function (normal, point) {
this.normal.copy(normal);
this.constant = -point.dot(this.normal);
return this;
},
/**
*
*/
normalize: function() {

@@ -79,21 +92,16 @@ // Note: will lead to a divide by zero if the plane is invalid.

*/
applyMatrix4: function() {
var v1 = new Vector3();
var m1 = new Matrix3();
applyMatrix4: function(matrix, optionalNormalMatrix) {
var normalMatrix = optionalNormalMatrix || _mat4_1.setFromMatrix4(matrix).inverse().transpose();
return function applyMatrix4(matrix, optionalNormalMatrix) {
var normalMatrix = optionalNormalMatrix || m1.setFromMatrix4(matrix).inverse().transpose();
var referencePoint = this.coplanarPoint(_vec3_1).applyMatrix4(matrix);
var referencePoint = this.coplanarPoint(v1).applyMatrix4(matrix);
var normal = this.normal.applyMatrix3(normalMatrix).normalize();
var normal = this.normal.applyMatrix3(normalMatrix).normalize();
this.constant = -referencePoint.dot(normal);
this.constant = -referencePoint.dot(normal);
return this;
}
return this;
}
}()
});
export { Plane };

@@ -1,2 +0,1 @@

import { Vector3 } from './Vector3.js';
import { Matrix4 } from './Matrix4.js';

@@ -103,3 +102,2 @@

if (dot < 0) {
dot = -dot;
w2 = -w2;

@@ -300,3 +298,3 @@ x2 = -x2;

*/
setFromUnitVectors: function () {
setFromUnitVectors: function (vFrom, vTo) {
// http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final

@@ -306,32 +304,31 @@

var v1 = new Vector3();
var r;
var EPS = 0.000001;
return function setFromUnitVectors(vFrom, vTo) {
if (v1 === undefined) v1 = new Vector3();
var r = vFrom.dot(vTo) + 1;
r = vFrom.dot(vTo) + 1;
if (r < EPS) {
r = 0;
if (r < EPS) {
r = 0;
if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
v1.set(-vFrom.y, vFrom.x, 0);
} else {
v1.set(0, -vFrom.z, vFrom.y);
}
if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
this._x = -vFrom.y;
this._y = vFrom.x;
this._z = 0;
this._w = r;
} else {
v1.crossVectors(vFrom, vTo);
this._x = 0;
this._y = -vFrom.z;
this._z = vFrom.y;
this._w = r;
}
} else {
// crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
this._x = v1.x;
this._y = v1.y;
this._z = v1.z;
this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
this._w = r;
}
return this.normalize();
};
}(),
return this.normalize();
},

@@ -338,0 +335,0 @@ /**

import { Vector3 } from './Vector3.js';
var _vec3_1 = new Vector3();
var _diff = new Vector3();
var _edge1 = new Vector3();
var _edge2 = new Vector3();
var _normal = new Vector3();
/**

@@ -36,38 +43,34 @@ * @constructor

*/
intersectsSphere: function() {
var v1 = new Vector3();
intersectsSphere: function(sphere, optionalTarget) {
_vec3_1.subVectors(sphere.center, this.origin);
var tca = _vec3_1.dot(this.direction);
var d2 = _vec3_1.dot(_vec3_1) - tca * tca;
var radius2 = sphere.radius * sphere.radius;
if (d2 > radius2) {
return null;
}
return function intersectSphere(sphere, optionalTarget) {
v1.subVectors(sphere.center, this.origin);
var tca = v1.dot(this.direction);
var d2 = v1.dot(v1) - tca * tca;
var radius2 = sphere.radius * sphere.radius;
if (d2 > radius2) {
return null;
}
var thc = Math.sqrt(radius2 - d2);
var thc = Math.sqrt(radius2 - d2);
// t0 = first intersect point - entrance on front of sphere
var t0 = tca - thc;
// t0 = first intersect point - entrance on front of sphere
var t0 = tca - thc;
// t1 = second intersect point - exit point on back of sphere
var t1 = tca + thc;
// console.log(t0, t1);
// test to see if both t0 and t1 are behind the ray - if so, return null
if (t0 < 0 && t1 < 0) {
return null;
}
// test to see if t0 is behind the ray:
// if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
// in order to always return an intersect point that is in front of the ray.
if (t0 < 0) {
return this.at(t1, optionalTarget);
}
// t1 = second intersect point - exit point on back of sphere
var t1 = tca + thc;
// console.log(t0, t1);
// test to see if both t0 and t1 are behind the ray - if so, return null
if (t0 < 0 && t1 < 0) {
return null;
}
// test to see if t0 is behind the ray:
// if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
// in order to always return an intersect point that is in front of the ray.
if (t0 < 0) {
return this.at(t1, optionalTarget);
}
// else t0 is in front of the ray, so return the first collision point scaled by t0
return this.at(t0, optionalTarget);
},
// else t0 is in front of the ray, so return the first collision point scaled by t0
return this.at(t0, optionalTarget);
};
}(),
/**

@@ -134,66 +137,60 @@ *

*/
intersectTriangle: function() {
intersectTriangle: function(a, b, c, backfaceCulling, optionalTarget) {
// Compute the offset origin, edges, and normal.
var diff = new Vector3();
var edge1 = new Vector3();
var edge2 = new Vector3();
var normal = new Vector3();
return function intersectTriangle(a, b, c, backfaceCulling, optionalTarget) {
// from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
// from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
edge1.subVectors(b, a);
edge2.subVectors(c, a);
normal.crossVectors(edge1, edge2);
_edge1.subVectors(b, a);
_edge2.subVectors(c, a);
_normal.crossVectors(_edge1, _edge2);
// Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
// E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
// |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
// |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
// |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
var DdN = this.direction.dot(normal);
var sign;
if (DdN > 0) {
if (backfaceCulling) return null;
sign = 1;
} else if (DdN < 0) {
sign = -1;
DdN = -DdN;
} else {
return null;
}
// Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
// E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
// |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
// |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
// |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
var DdN = this.direction.dot(_normal);
var sign;
if (DdN > 0) {
if (backfaceCulling) return null;
sign = 1;
} else if (DdN < 0) {
sign = -1;
DdN = -DdN;
} else {
return null;
}
diff.subVectors(this.origin, a);
var DdQxE2 = sign * this.direction.dot(edge2.crossVectors(diff, edge2));
_diff.subVectors(this.origin, a);
var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2));
// b1 < 0, no intersection
if (DdQxE2 < 0) {
return null;
}
// b1 < 0, no intersection
if (DdQxE2 < 0) {
return null;
}
var DdE1xQ = sign * this.direction.dot(edge1.cross(diff));
var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff));
// b2 < 0, no intersection
if (DdE1xQ < 0) {
return null;
}
// b2 < 0, no intersection
if (DdE1xQ < 0) {
return null;
}
// b1+b2 > 1, no intersection
if (DdQxE2 + DdE1xQ > DdN) {
return null;
}
// b1+b2 > 1, no intersection
if (DdQxE2 + DdE1xQ > DdN) {
return null;
}
// Line intersects triangle, check if ray does.
var QdN = -sign * diff.dot(normal);
// Line intersects triangle, check if ray does.
var QdN = -sign * _diff.dot(_normal);
// t < 0, no intersection
if (QdN < 0) {
return null;
}
// Ray intersects triangle.
return this.at(QdN / DdN, optionalTarget);
// t < 0, no intersection
if (QdN < 0) {
return null;
}
}(),
// Ray intersects triangle.
return this.at(QdN / DdN, optionalTarget);
},
/**

@@ -200,0 +197,0 @@ *

import { Vector3 } from './Vector3.js';
import { Box3 } from './Box3.js';
var _box3_1 = new Box3();
var _vec3_1 = new Vector3();
/**

@@ -30,31 +33,21 @@ * @constructor

*/
setFromArray: function() {
var box = new Box3();
var point = new Vector3();
setFromArray: function(array, gap) {
var _gap = (gap !== undefined ? gap : 3);
return function setFromArray(array, gap) {
var _gap = (gap !== undefined ? gap : 3);
var center = this.center;
var center = this.center;
_box3_1.setFromArray(array, _gap).getCenter(center);
box.setFromArray(array, _gap).getCenter(center);
var maxRadiusSq = 0;
var maxRadiusSq = 0;
for (var i = 0, l = array.length; i < l; i += _gap) {
_vec3_1.fromArray(array, i);
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vec3_1));
}
for (var i = 0, l = array.length; i < l; i += _gap) {
var x = array[i];
var y = array[i + 1];
var z = array[i + 2];
this.radius = Math.sqrt(maxRadiusSq);
point.set(x, y, z);
return this;
},
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(point));
}
this.radius = Math.sqrt(maxRadiusSq);
return this;
}
}(),
/**

@@ -61,0 +54,0 @@ *

import { Vector3 } from './Vector3.js';
var _v0 = new Vector3();
var _v1 = new Vector3();
var _v2 = new Vector3();
var _v3 = new Vector3();
/**

@@ -34,21 +39,17 @@ * @constructor

*/
Triangle.normal = function() {
var v0 = new Vector3();
Triangle.normal = function(a, b, c, optionalTarget) {
var result = optionalTarget || new Vector3();
return function normal(a, b, c, optionalTarget) {
var result = optionalTarget || new Vector3();
result.subVectors(c, b);
_v0.subVectors(a, b);
result.cross(_v0);
result.subVectors(c, b);
v0.subVectors(a, b);
result.cross(v0);
var resultLengthSq = result.getLengthSquared();
if (resultLengthSq > 0) {
return result.multiplyScalar(1 / Math.sqrt(resultLengthSq));
}
var resultLengthSq = result.getLengthSquared();
if (resultLengthSq > 0) {
return result.multiplyScalar(1 / Math.sqrt(resultLengthSq));
}
return result.set(0, 0, 0);
};
return result.set(0, 0, 0);
};
}();
/**

@@ -59,51 +60,40 @@ * static/instance method to calculate barycentric coordinates.

*/
Triangle.barycoordFromPoint = function() {
var v0 = new Vector3();
var v1 = new Vector3();
var v2 = new Vector3();
Triangle.barycoordFromPoint = function(point, a, b, c, optionalTarget) {
_v0.subVectors(c, a);
_v1.subVectors(b, a);
_v2.subVectors(point, a);
return function barycoordFromPoint(point, a, b, c, optionalTarget) {
v0.subVectors(c, a);
v1.subVectors(b, a);
v2.subVectors(point, a);
var dot00 = _v0.dot(_v0);
var dot01 = _v0.dot(_v1);
var dot02 = _v0.dot(_v2);
var dot11 = _v1.dot(_v1);
var dot12 = _v1.dot(_v2);
var dot00 = v0.dot(v0);
var dot01 = v0.dot(v1);
var dot02 = v0.dot(v2);
var dot11 = v1.dot(v1);
var dot12 = v1.dot(v2);
var denom = (dot00 * dot11 - dot01 * dot01);
var denom = (dot00 * dot11 - dot01 * dot01);
var result = optionalTarget || new Vector3();
var result = optionalTarget || new Vector3();
// collinear or singular triangle
if (denom === 0) {
// arbitrary location outside of triangle?
// not sure if this is the best idea, maybe should be returning undefined
return result.set(-2, -1, -1);
}
// collinear or singular triangle
if (denom === 0) {
// arbitrary location outside of triangle?
// not sure if this is the best idea, maybe should be returning undefined
return result.set(-2, -1, -1);
}
var invDenom = 1 / denom;
var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
var v = (dot00 * dot12 - dot01 * dot02) * invDenom;
var invDenom = 1 / denom;
var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
var v = (dot00 * dot12 - dot01 * dot02) * invDenom;
// barycentric coordinates must always sum to 1
return result.set(1 - u - v, v, u);
};
// barycentric coordinates must always sum to 1
return result.set(1 - u - v, v, u);
};
}();
/**
* @method
*/
Triangle.containsPoint = function() {
var v1 = new Vector3();
Triangle.containsPoint = function(point, a, b, c) {
Triangle.barycoordFromPoint(point, a, b, c, _v3);
return (_v3.x >= 0) && (_v3.y >= 0) && ((_v3.x + _v3.y) <= 1);
};
return function containsPoint(point, a, b, c) {
var result = Triangle.barycoordFromPoint(point, a, b, c, v1);
return (result.x >= 0) && (result.y >= 0) && ((result.x + result.y) <= 1);
};
}();
export { Triangle };

@@ -0,1 +1,3 @@

var _vector = new Vector3();
/**

@@ -144,2 +146,13 @@ * a vector 3 class

*/
negate: function () {
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
return this;
},
/**
*
*/
dot: function(a) {

@@ -405,2 +418,12 @@ return this.x * a.x + this.y * a.y + this.z * a.z;

*/
reflect: function (normal) {
// reflect incident vector off plane orthogonal to normal
// normal is assumed to have unit length
return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
},
/**
*
*/
equals: function(v) {

@@ -407,0 +430,0 @@ return ((v.x === this.x) && (v.y === this.y) && (v.z === this.z));

@@ -60,2 +60,9 @@ /**

*/
dot: function (v) {
return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
},
/**
*
*/
getLengthSquared: function () {

@@ -121,14 +128,2 @@ return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;

*/
multiplyScalar: function(scalar) {
this.x *= scalar;
this.y *= scalar;
this.z *= scalar;
this.w *= scalar;
return this;
},
/**
*
*/
subVectors: function(a, b) {

@@ -135,0 +130,0 @@ this.x = a.x - b.x;

@@ -6,5 +6,6 @@ import { OBJECT_TYPE, TEXEL_ENCODING_TYPE } from '../../const.js';

import { Vector4 } from '../../math/Vector4.js';
import { Quaternion } from '../../math/Quaternion.js';
import { Vector3 } from '../../math/Vector3.js';
var _mat4_1 = new Matrix4();
/**

@@ -86,11 +87,7 @@ * The camera used for rendering a 3D scene.

*/
lookAt: function() {
var m = new Matrix4();
lookAt: function(target, up) {
_mat4_1.lookAtRH(this.position, target, up);
this.quaternion.setFromRotationMatrix(_mat4_1);
},
return function lookAt(target, up) {
m.lookAtRH(this.position, target, up);
this.quaternion.setFromRotationMatrix(m);
};
}(),
/**

@@ -132,32 +129,17 @@ * Set orthographic projection matrix.

getWorldDirection: function() {
var position = new Vector3();
var quaternion = new Quaternion();
var scale = new Vector3();
getWorldDirection: function(optionalTarget) {
optionalTarget = optionalTarget || new Vector3();
var e = this.worldMatrix.elements;
return optionalTarget.set(-e[8], -e[9], -e[10]).normalize();
},
return function getWorldDirection(optionalTarget) {
var result = optionalTarget || new Vector3();
updateMatrix: function(force) {
Object3D.prototype.updateMatrix.call(this, force);
this.worldMatrix.decompose(position, quaternion, scale);
this.viewMatrix.getInverse(this.worldMatrix); // update view matrix
// -z
result.set(0, 0, -1).applyQuaternion(quaternion);
_mat4_1.multiplyMatrices(this.projectionMatrix, this.viewMatrix); // get PV matrix
this.frustum.setFromMatrix(_mat4_1); // update frustum
},
return result;
};
}(),
updateMatrix: function() {
var matrix = new Matrix4();
return function updateMatrix() {
Object3D.prototype.updateMatrix.call(this);
this.viewMatrix.getInverse(this.worldMatrix); // update view matrix
matrix.multiplyMatrices(this.projectionMatrix, this.viewMatrix); // get PV matrix
this.frustum.setFromMatrix(matrix); // update frustum
}
}(),
copy: function (source, recursive) {

@@ -164,0 +146,0 @@ Object3D.prototype.copy.call(this, source, recursive);

@@ -11,2 +11,20 @@ import { OBJECT_TYPE, DRAW_SIDE } from '../const.js';

var _sphere = new Sphere();
var _box = new Box3();
var _inverseMatrix = new Matrix4();
var _ray = new Ray();
var _barycoord = new Vector3();
var _vA = new Vector3();
var _vB = new Vector3();
var _vC = new Vector3();
var _uvA = new Vector2();
var _uvB = new Vector2();
var _uvC = new Vector2();
var _intersectionPoint = new Vector3();
var _intersectionPointWorld = new Vector3();
/**

@@ -53,113 +71,55 @@ * Class representing triangular polygon mesh based objects.

*/
raycast: function() {
var sphere = new Sphere();
var box = new Box3();
var inverseMatrix = new Matrix4();
var ray = new Ray();
raycast: function(raycaster, intersects) {
var geometry = this.geometry;
var worldMatrix = this.worldMatrix;
var barycoord = new Vector3();
var vA = new Vector3();
var vB = new Vector3();
var vC = new Vector3();
var uvA = new Vector2();
var uvB = new Vector2();
var uvC = new Vector2();
var intersectionPoint = new Vector3();
var intersectionPointWorld = new Vector3();
function uvIntersection(point, p1, p2, p3, uv1, uv2, uv3) {
Triangle.barycoordFromPoint(point, p1, p2, p3, barycoord);
uv1.multiplyScalar(barycoord.x);
uv2.multiplyScalar(barycoord.y);
uv3.multiplyScalar(barycoord.z);
uv1.add(uv2).add(uv3);
return uv1.clone();
// Sphere test
_sphere.copy(geometry.boundingSphere);
_sphere.applyMatrix4(worldMatrix);
if (!raycaster.ray.intersectsSphere(_sphere)) {
return;
}
function checkIntersection(object, raycaster, ray, pA, pB, pC, point) {
var intersect;
var material = object.material;
if (material.side === DRAW_SIDE.BACK) {
intersect = ray.intersectTriangle(pC, pB, pA, true, point);
} else {
intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DRAW_SIDE.DOUBLE, point);
}
if (intersect === null) return null;
intersectionPointWorld.copy(point);
intersectionPointWorld.applyMatrix4(object.worldMatrix);
var distance = raycaster.ray.origin.distanceTo(intersectionPointWorld);
if (distance < raycaster.near || distance > raycaster.far) return null;
return {
distance: distance,
point: intersectionPointWorld.clone(),
object: object
};
// Box test
_box.copy(geometry.boundingBox);
_box.applyMatrix4(worldMatrix);
if (!raycaster.ray.intersectsBox(_box)) {
return;
}
return function raycast(raycaster, intersects) {
var geometry = this.geometry;
var worldMatrix = this.worldMatrix;
// Vertex test
_inverseMatrix.getInverse(worldMatrix);
_ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix);
// sphere test
sphere.copy(geometry.boundingSphere);
sphere.applyMatrix4(worldMatrix);
if (!raycaster.ray.intersectsSphere(sphere)) {
return;
}
var index = geometry.index.array;
var position = geometry.getAttribute("a_Position");
var uv = geometry.getAttribute("a_Uv");
var a, b, c;
// box test
box.copy(geometry.boundingBox);
box.applyMatrix4(worldMatrix);
if (!raycaster.ray.intersectsBox(box)) {
return;
}
for (var i = 0; i < index.length; i += 3) {
a = index[i];
b = index[i + 1];
c = index[i + 2];
// vertex test
inverseMatrix.getInverse(worldMatrix);
ray.copy(raycaster.ray).applyMatrix4(inverseMatrix);
_vA.fromArray(position.array, a * 3);
_vB.fromArray(position.array, b * 3);
_vC.fromArray(position.array, c * 3);
var index = geometry.index.array;
var position = geometry.getAttribute("a_Position");
var uv = geometry.getAttribute("a_Uv");
var a, b, c;
var intersection = checkIntersection(this, raycaster, _ray, _vA, _vB, _vC, _intersectionPoint);
for (var i = 0; i < index.length; i += 3) {
a = index[i];
b = index[i + 1];
c = index[i + 2];
if (intersection) {
// uv
_uvA.fromArray(uv.array, a * 2);
_uvB.fromArray(uv.array, b * 2);
_uvC.fromArray(uv.array, c * 2);
vA.fromArray(position.array, a * 3);
vB.fromArray(position.array, b * 3);
vC.fromArray(position.array, c * 3);
intersection.uv = uvIntersection(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC);
var intersection = checkIntersection(this, raycaster, ray, vA, vB, vC, intersectionPoint);
intersection.face = [a, b, c];
intersection.faceIndex = a;
if (intersection) {
// uv
uvA.fromArray(uv.array, a * 2);
uvB.fromArray(uv.array, b * 2);
uvC.fromArray(uv.array, c * 2);
intersection.uv = uvIntersection(intersectionPoint, vA, vB, vC, uvA, uvB, uvC);
intersection.face = [a, b, c];
intersection.faceIndex = a;
intersects.push(intersection);
}
intersects.push(intersection);
}
}
}(),
},

@@ -180,2 +140,40 @@ copy: function(source) {

function uvIntersection(point, p1, p2, p3, uv1, uv2, uv3) {
Triangle.barycoordFromPoint(point, p1, p2, p3, _barycoord);
uv1.multiplyScalar(_barycoord.x);
uv2.multiplyScalar(_barycoord.y);
uv3.multiplyScalar(_barycoord.z);
uv1.add(uv2).add(uv3);
return uv1.clone();
}
function checkIntersection(object, raycaster, ray, pA, pB, pC, point) {
var intersect;
var material = object.material;
if (material.side === DRAW_SIDE.BACK) {
intersect = ray.intersectTriangle(pC, pB, pA, true, point);
} else {
intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DRAW_SIDE.DOUBLE, point);
}
if (intersect === null) return null;
_intersectionPointWorld.copy(point);
_intersectionPointWorld.applyMatrix4(object.worldMatrix);
var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
if (distance < raycaster.near || distance > raycaster.far) return null;
return {
distance: distance,
point: _intersectionPointWorld.clone(),
object: object
};
}
export { Mesh };

@@ -8,4 +8,6 @@ import { generateUUID } from '../base.js';

var object3DId = 0;
var _object3DId = 0;
var _mat4_1 = new Matrix4();
/**

@@ -18,3 +20,3 @@ * This is the base class for most objects in zen3d

function Object3D() {
Object.defineProperty(this, 'id', { value: object3DId++ });
Object.defineProperty(this, 'id', { value: _object3DId++ });

@@ -157,2 +159,23 @@ /**

this.userData = {};
/**
* When this is set, it calculates the matrix of position, (rotation or quaternion) and scale every frame and also recalculates the worldMatrix property.
* @type {boolean}
* @default true
*/
this.matrixAutoUpdate = true;
/**
* When this is set, it calculates the matrix in that frame and resets this property to false.
* @type {boolean}
* @default true
*/
this.matrixNeedsUpdate = true;
/**
* When this is set, it calculates the world matrix in that frame and resets this property to false.
* @type {boolean}
* @default true
*/
this.worldMatrixNeedsUpdate = true;
}

@@ -179,4 +202,15 @@

add: function(object) {
if (object === this) {
console.error("Object3D.add: object can't be added as a child of itself.", object);
return;
}
if (object.parent !== null) {
object.parent.remove(object);
}
object.parent = this;
this.children.push(object);
object.parent = this;
object.worldMatrixNeedsUpdate = true;
},

@@ -191,5 +225,7 @@

if (index !== -1) {
object.parent = null;
this.children.splice(index, 1);
object.worldMatrixNeedsUpdate = true;
}
object.parent = null;
},

@@ -232,10 +268,20 @@

*/
updateMatrix: function() {
var matrix = this.matrix.transform(this.position, this.scale, this.quaternion);
updateMatrix: function(force) {
if (this.matrixAutoUpdate || this.matrixNeedsUpdate) {
this.matrix.transform(this.position, this.scale, this.quaternion);
this.worldMatrix.copy(matrix);
this.matrixNeedsUpdate = false;
this.worldMatrixNeedsUpdate = true;
}
if (this.parent) {
var parentMatrix = this.parent.worldMatrix;
this.worldMatrix.premultiply(parentMatrix);
if (this.worldMatrixNeedsUpdate || force) {
this.worldMatrix.copy(this.matrix);
if (this.parent) {
var parentMatrix = this.parent.worldMatrix;
this.worldMatrix.premultiply(parentMatrix);
}
this.worldMatrixNeedsUpdate = false;
force = true;
}

@@ -245,3 +291,3 @@

for (var i = 0, l = children.length; i < l; i++) {
children[i].updateMatrix();
children[i].updateMatrix(force);
}

@@ -257,18 +303,8 @@ },

*/
getWorldDirection: function() {
var position = new Vector3();
var quaternion = new Quaternion();
var scale = new Vector3();
getWorldDirection: function(optionalTarget) {
optionalTarget = optionalTarget || new Vector3();
var e = this.worldMatrix.elements;
return optionalTarget.set(e[8], e[9], e[10]).normalize();
},
return function getWorldDirection(optionalTarget) {
var result = optionalTarget || new Vector3();
this.worldMatrix.decompose(position, quaternion, scale);
result.set(0, 0, 1).applyQuaternion(quaternion);
return result;
};
}(),
/**

@@ -280,11 +316,7 @@ * Rotates the object to face a point in local space.

*/
lookAt: function() {
var m = new Matrix4();
lookAt: function(target, up) {
_mat4_1.lookAtRH(target, this.position, up);
this.quaternion.setFromRotationMatrix(_mat4_1);
},
return function lookAt(target, up) {
m.lookAtRH(target, this.position, up);
this.quaternion.setFromRotationMatrix(m);
};
}(),
/**

@@ -291,0 +323,0 @@ * Method to get intersections between a casted ray and this object.

@@ -68,4 +68,4 @@ import { OBJECT_TYPE } from '../const.js';

updateMatrix: function() {
Mesh.prototype.updateMatrix.call(this);
updateMatrix: function(force) {
Mesh.prototype.updateMatrix.call(this, force);

@@ -72,0 +72,0 @@ if (this.bindMode === 'attached') {

@@ -10,2 +10,3 @@ import { Camera } from '../../objects/camera/Camera.js';

* @memberof zen3d
* @param {zen3d.RenderTargetCube} [renderTarget=] - The environment render is done to the renderTarget (if specified).
*/

@@ -12,0 +13,0 @@ function EnvironmentMapPass(renderTarget) {

@@ -56,3 +56,3 @@ import { RenderTargetBack } from './RenderTargetBack.js';

*/
this.lightsAutoupdate = true;
this.lightsAutoUpdate = true;

@@ -77,3 +77,3 @@ /**

this.matrixAutoUpdate && scene.updateMatrix();
this.lightsAutoupdate && scene.updateLights();
this.lightsAutoUpdate && scene.updateLights();

@@ -80,0 +80,0 @@ if (this.shadowAutoUpdate || this.shadowNeedsUpdate) {

@@ -56,2 +56,3 @@ import alphaTest_frag from './shaderChunk/alphaTest_frag.glsl';

import skinning_vert from './shaderChunk/skinning_vert.glsl';
import skinnormal_vert from './shaderChunk/skinnormal_vert.glsl';
import specularMap_frag from './shaderChunk/specularMap_frag.glsl';

@@ -125,2 +126,3 @@ import specularMap_pars_frag from './shaderChunk/specularMap_pars_frag.glsl';

skinning_vert: skinning_vert,
skinnormal_vert: skinnormal_vert,
specularMap_frag: specularMap_frag,

@@ -127,0 +129,0 @@ specularMap_pars_frag: specularMap_pars_frag,

@@ -16,2 +16,4 @@ import basic_frag from './shaderLib/basic_frag.glsl';

import pbr_vert from './shaderLib/pbr_vert.glsl';
import matcap_frag from './shaderLib/matcap_frag.glsl';
import matcap_vert from './shaderLib/matcap_vert.glsl';
import phong_frag from './shaderLib/phong_frag.glsl';

@@ -39,2 +41,4 @@ import phong_vert from './shaderLib/phong_vert.glsl';

pbr2_vert: pbr_vert,
matcap_frag: matcap_frag,
matcap_vert: matcap_vert,
phong_frag: phong_frag,

@@ -41,0 +45,0 @@ phong_vert: phong_vert,

@@ -15,2 +15,3 @@ import { CULL_FACE_TYPE, BLEND_TYPE, DRAW_SIDE, OBJECT_TYPE, WEBGL_PIXEL_TYPE, WEBGL_PIXEL_FORMAT, WEBGL_TEXTURE_FILTER } from '../../const.js';

import { WebGLGeometry } from './WebGLGeometry.js';
import { WebGLVertexArrayBindings } from './WebGLVertexArrayBindings.js';

@@ -33,21 +34,20 @@ var helpVector3 = new Vector3();

var getClippingPlanesData = function() {
var planesData;
var plane = new Plane();
return function getClippingPlanesData(planes, camera) {
if (!planesData || planesData.length < planes.length * 4) {
planesData = new Float32Array(planes.length * 4);
}
var planesData;
var helpPlane = new Plane();
for (var i = 0; i < planes.length; i++) {
plane.copy(planes[i]);// .applyMatrix4(camera.viewMatrix);
planesData[i * 4 + 0] = plane.normal.x;
planesData[i * 4 + 1] = plane.normal.y;
planesData[i * 4 + 2] = plane.normal.z;
planesData[i * 4 + 3] = plane.constant;
}
return planesData;
function getClippingPlanesData(planes, camera) {
if (!planesData || planesData.length < planes.length * 4) {
planesData = new Float32Array(planes.length * 4);
}
}();
for (var i = 0; i < planes.length; i++) {
helpPlane.copy(planes[i]);// .applyMatrix4(camera.viewMatrix);
planesData[i * 4 + 0] = helpPlane.normal.x;
planesData[i * 4 + 1] = helpPlane.normal.y;
planesData[i * 4 + 2] = helpPlane.normal.z;
planesData[i * 4 + 3] = helpPlane.constant;
}
return planesData;
}
/**

@@ -76,2 +76,5 @@ * Core render methods by WebGL.

var vertexArrayBindings = new WebGLVertexArrayBindings(gl, properties, capabilities);
this.vertexArrayBindings = vertexArrayBindings;
var texture = new WebGLTexture(gl, state, properties, capabilities);

@@ -84,3 +87,3 @@ this.texture = texture;

this.geometry = new WebGLGeometry(gl, state, properties, capabilities);
this.geometry = new WebGLGeometry(gl, state, vertexArrayBindings, properties, capabilities);

@@ -90,4 +93,2 @@ this.programs = new WebGLPrograms(gl, state, capabilities);

this._usedTextureUnits = 0;
this._currentGeometryProgram = "";
}

@@ -161,3 +162,2 @@

var state = this.state;
var vaoExt = this.capabilities.getExtension("OES_vertex_array_object");

@@ -240,3 +240,3 @@ var getMaterial = config.getMaterial || defaultGetMaterial;

var geometryProperties = this.geometry.setGeometry(geometry);
this.geometry.setGeometry(geometry);

@@ -248,29 +248,3 @@ // update morph targets

if (object.morphTargetInfluences) {
this.setupVertexAttributes(program, geometry);
this._currentGeometryProgram = "";
} else if (this.capabilities.version >= 2) { // use VAO
if (!geometryProperties._vaos[program.id]) {
geometryProperties._vaos[program.id] = gl.createVertexArray();
gl.bindVertexArray(geometryProperties._vaos[program.id]);
this.setupVertexAttributes(program, geometry);
} else {
gl.bindVertexArray(geometryProperties._vaos[program.id]);
}
} else if (vaoExt) { // use VAO extension
if (!geometryProperties._vaos[program.id]) {
geometryProperties._vaos[program.id] = vaoExt.createVertexArrayOES();
vaoExt.bindVertexArrayOES(geometryProperties._vaos[program.id]);
this.setupVertexAttributes(program, geometry);
} else {
vaoExt.bindVertexArrayOES(geometryProperties._vaos[program.id]);
}
} else {
var geometryProgram = program.id + "_" + geometry.id;
if (geometryProgram !== this._currentGeometryProgram) {
this.setupVertexAttributes(program, geometry);
this._currentGeometryProgram = geometryProgram;
}
this._currentGeometryProgram = geometryProgram;
}
this.vertexArrayBindings.setup(object, geometry, program);

@@ -425,2 +399,5 @@ // update uniforms

break;
case "matcap":
uniform.set(material.matcap, this);
break;
case "clippingPlanes":

@@ -499,7 +476,3 @@ var planesData = getClippingPlanesData(scene.clippingPlanes || [], camera);

if (this.capabilities.version >= 2) {
gl.bindVertexArray(null);
} else if (vaoExt) {
vaoExt.bindVertexArrayOES(null);
}
this.vertexArrayBindings.resetBinding();

@@ -524,3 +497,13 @@ // reset used tex Unit

// set blend
// set draw side
state.setCullFace(
(material.side === DRAW_SIDE.DOUBLE) ? CULL_FACE_TYPE.NONE : CULL_FACE_TYPE.BACK
);
var flipSided = (material.side === DRAW_SIDE.BACK);
if (frontFaceCW) flipSided = !flipSided;
state.setFlipSided(flipSided);
// set blend state
if (material.transparent) {

@@ -532,3 +515,3 @@ state.setBlend(material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha);

// set buffers
// set buffers state
state.depthBuffer.setFunc(material.depthFunc);

@@ -539,12 +522,13 @@ state.depthBuffer.setTest(material.depthTest);

// set draw side
state.setCullFace(
(material.side === DRAW_SIDE.DOUBLE) ? CULL_FACE_TYPE.NONE : CULL_FACE_TYPE.BACK
);
// set stencil buffers
var stencilTest = material.stencilTest;
state.stencilBuffer.setTest(stencilTest);
if (stencilTest) {
state.stencilBuffer.setMask(material.stencilWriteMask);
state.stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask, material.stencilFuncBack, material.stencilRefBack, material.stencilFuncMaskBack);
state.stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass, material.stencilFailBack, material.stencilZFailBack, material.stencilZPassBack);
}
var flipSided = (material.side === DRAW_SIDE.BACK);
if (frontFaceCW) flipSided = !flipSided;
state.setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
state.setFlipSided(flipSided);
// set line width

@@ -554,4 +538,2 @@ if (material.lineWidth !== undefined) {

}
state.setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
},

@@ -775,85 +757,2 @@

setupVertexAttributes: function(program, geometry) {
var gl = this.gl;
var attributes = program.attributes;
var properties = this.properties;
var capabilities = this.capabilities;
for (var key in attributes) {
var programAttribute = attributes[key];
var geometryAttribute = geometry.getAttribute(key);
if (geometryAttribute) {
var normalized = geometryAttribute.normalized;
var size = geometryAttribute.size;
if (programAttribute.count !== size) {
console.warn("WebGLCore: attribute " + key + " size not match! " + programAttribute.count + " : " + size);
}
var attribute;
if (geometryAttribute.isInterleavedBufferAttribute) {
attribute = properties.get(geometryAttribute.data);
} else {
attribute = properties.get(geometryAttribute);
}
var buffer = attribute.buffer;
var type = attribute.type;
if (programAttribute.format !== type) {
// console.warn("WebGLCore: attribute " + key + " type not match! " + programAttribute.format + " : " + type);
}
var bytesPerElement = attribute.bytesPerElement;
if (geometryAttribute.isInterleavedBufferAttribute) {
var data = geometryAttribute.data;
var stride = data.stride;
var offset = geometryAttribute.offset;
gl.enableVertexAttribArray(programAttribute.location);
if (data && data.isInstancedInterleavedBuffer) {
if (capabilities.version >= 2) {
gl.vertexAttribDivisor(programAttribute.location, data.meshPerAttribute);
} else if (capabilities.getExtension('ANGLE_instanced_arrays')) {
capabilities.getExtension('ANGLE_instanced_arrays').vertexAttribDivisorANGLE(programAttribute.location, data.meshPerAttribute);
} else {
console.warn("vertexAttribDivisor not supported");
}
if (geometry.maxInstancedCount === undefined) {
geometry.maxInstancedCount = data.meshPerAttribute * data.count;
}
}
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.vertexAttribPointer(programAttribute.location, programAttribute.count, type, normalized, bytesPerElement * stride, bytesPerElement * offset);
} else {
gl.enableVertexAttribArray(programAttribute.location);
if (geometryAttribute && geometryAttribute.isInstancedBufferAttribute) {
if (capabilities.version >= 2) {
gl.vertexAttribDivisor(programAttribute.location, geometryAttribute.meshPerAttribute);
} else if (capabilities.getExtension('ANGLE_instanced_arrays')) {
capabilities.getExtension('ANGLE_instanced_arrays').vertexAttribDivisorANGLE(programAttribute.location, geometryAttribute.meshPerAttribute);
} else {
console.warn("vertexAttribDivisor not supported");
}
if (geometry.maxInstancedCount === undefined) {
geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
}
}
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.vertexAttribPointer(programAttribute.location, programAttribute.count, type, normalized, 0, 0);
}
} else {
// console.warn("WebGLCore: geometry attribute " + key + " not found!");
}
}
// bind index if could
if (geometry.index) {
var indexProperty = properties.get(geometry.index);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexProperty.buffer);
}
},
onMaterialDispose: function(event) {

@@ -860,0 +759,0 @@ var material = event.target;

@@ -36,3 +36,3 @@ function createBuffer(gl, data, attribute, bufferType) {

function updateBuffer(gl, buffer, attribute, bufferType) {
function updateBuffer(gl, capabilities, buffer, attribute, bufferType) {
var array = attribute.array;

@@ -51,4 +51,9 @@ var updateRange = attribute.updateRange;

} else {
gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
if (capabilities.version >= 2) {
gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
array, updateRange.offset, updateRange.count);
} else {
gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
}

@@ -59,3 +64,3 @@ updateRange.count = -1; // reset range

function updateAttribute(gl, properties, attribute, bufferType) {
function updateAttribute(gl, properties, capabilities, attribute, bufferType) {
// if isInterleavedBufferAttribute, get InterleavedBuffer as data.

@@ -70,3 +75,3 @@ // else get BufferAttribute as data

} else if (data.version < attribute.version) {
updateBuffer(gl, data.buffer, attribute, bufferType);
updateBuffer(gl, capabilities, data.buffer, attribute, bufferType);
data.version = attribute.version;

@@ -88,3 +93,3 @@ }

function WebGLGeometry(gl, state, properties, capabilities) {
function WebGLGeometry(gl, state, vertexArrayBindings, properties, capabilities) {
this.gl = gl;

@@ -94,2 +99,4 @@

this.vertexArrayBindings = vertexArrayBindings;
this.properties = properties;

@@ -106,2 +113,3 @@

var properties = this.properties;
var capabilities = this.capabilities;

@@ -116,7 +124,7 @@ var geometryProperties = this.properties.get(geometry);

if (geometry.index !== null) {
updateAttribute(gl, properties, geometry.index, gl.ELEMENT_ARRAY_BUFFER);
updateAttribute(gl, properties, capabilities, geometry.index, gl.ELEMENT_ARRAY_BUFFER);
}
for (var name in geometry.attributes) {
updateAttribute(gl, properties, geometry.attributes[name], gl.ARRAY_BUFFER);
updateAttribute(gl, properties, capabilities, geometry.attributes[name], gl.ARRAY_BUFFER);
}

@@ -128,3 +136,3 @@

for (var i = 0, l = array.length; i < l; i++) {
updateAttribute(gl, properties, array[i], gl.ARRAY_BUFFER);
updateAttribute(gl, properties, capabilities, array[i], gl.ARRAY_BUFFER);
}

@@ -163,7 +171,3 @@ }

if (vao) {
if (this.capabilities.version >= 2) {
gl.deleteVertexArray(vao);
} else {
gl.deleteVertexArrayOES(vao);
}
this.vertexArrayBindings.disposeVAO(vao.object);
}

@@ -170,0 +174,0 @@ }

@@ -99,6 +99,5 @@ import { MATERIAL_TYPE, TEXEL_ENCODING_TYPE, SHADOW_TYPE, SHADING_TYPE, VERTEX_COLOR, FOG_TYPE, DRAW_SIDE, OBJECT_TYPE } from '../../const.js';

(props.pointLightNum > 0 || props.directLightNum > 0 || props.ambientLightNum > 0 || props.spotLightNum > 0) ? '#define USE_LIGHT' : '',
(props.pointLightNum > 0 || props.directLightNum > 0 || props.spotLightNum > 0) ? '#define USE_NORMAL' : '',
((props.pointLightNum > 0 || props.directLightNum > 0 || props.spotLightNum > 0) && props.useNormalMap) ? '#define USE_NORMAL_MAP' : '',
((props.pointLightNum > 0 || props.directLightNum > 0 || props.spotLightNum > 0) && props.useBumpMap) ? '#define USE_BUMPMAP' : '',
((props.pointLightNum > 0 || props.directLightNum > 0 || props.spotLightNum > 0) && props.useSpecularMap) ? '#define USE_SPECULARMAP' : '',
props.useNormalMap ? '#define USE_NORMAL_MAP' : '',
props.useBumpMap ? '#define USE_BUMPMAP' : '',
props.useSpecularMap ? '#define USE_SPECULARMAP' : '',
props.useEmissiveMap ? ('#define USE_EMISSIVEMAP ' + props.useEmissiveMap) : '',

@@ -118,2 +117,3 @@ props.useShadow ? '#define USE_SHADOW' : '',

props.useVertexTangents ? '#define USE_TANGENT' : '',
props.useVertexUvs ? '#define USE_UV' : '',

@@ -171,6 +171,5 @@ props.morphTargets ? '#define USE_MORPHTARGETS' : '',

(props.pointLightNum > 0 || props.directLightNum > 0 || props.ambientLightNum > 0 || props.spotLightNum > 0) ? '#define USE_LIGHT' : '',
(props.pointLightNum > 0 || props.directLightNum > 0 || props.spotLightNum > 0) ? '#define USE_NORMAL' : '',
((props.pointLightNum > 0 || props.directLightNum > 0 || props.spotLightNum > 0) && props.useNormalMap) ? '#define USE_NORMAL_MAP' : '',
((props.pointLightNum > 0 || props.directLightNum > 0 || props.spotLightNum > 0) && props.useBumpMap) ? '#define USE_BUMPMAP' : '',
((props.pointLightNum > 0 || props.directLightNum > 0 || props.spotLightNum > 0) && props.useSpecularMap) ? '#define USE_SPECULARMAP' : '',
props.useNormalMap ? '#define USE_NORMAL_MAP' : '',
props.useBumpMap ? '#define USE_BUMPMAP' : '',
props.useSpecularMap ? '#define USE_SPECULARMAP' : '',
props.useEmissiveMap ? ('#define USE_EMISSIVEMAP ' + props.useEmissiveMap) : '',

@@ -204,10 +203,14 @@ props.useShadow ? '#define USE_SHADOW' : '',

'#define GAMMA_FACTOR ' + props.gammaFactor,
props.useMatcap ? '#define USE_MATCAP' : '',
props.useVertexUvs ? '#define USE_UV' : '',
props.dithering ? '#define DITHERING' : '',
(props.diffuseMapEncoding || props.envMapEncoding || props.emissiveMapEncoding || props.outputEncoding) ? ShaderChunk["encodings_pars_frag"] : '',
props.diffuseMapEncoding ? getTexelDecodingFunction("mapTexelToLinear", props.diffuseMapEncoding) : '',
props.envMapEncoding ? getTexelDecodingFunction("envMapTexelToLinear", props.envMapEncoding) : '',
props.emissiveMapEncoding ? getTexelDecodingFunction("emissiveMapTexelToLinear", props.emissiveMapEncoding) : '',
props.outputEncoding ? getTexelEncodingFunction("linearToOutputTexel", props.outputEncoding) : '',
ShaderChunk["encodings_pars_frag"],
getTexelDecodingFunction("mapTexelToLinear", props.diffuseMapEncoding),
props.useEnvMap ? getTexelDecodingFunction("envMapTexelToLinear", props.envMapEncoding) : '',
props.useEmissiveMap ? getTexelDecodingFunction("emissiveMapTexelToLinear", props.emissiveMapEncoding) : '',
props.useMatcap ? getTexelDecodingFunction("matcapTexelToLinear", props.matcapEncoding) : '',
getTexelEncodingFunction("linearToOutputTexel", props.outputEncoding),

@@ -364,2 +367,4 @@ props.packDepthToRGBA ? '#define DEPTH_PACKING_RGBA' : '',

props.useAOMap = !!material.aoMap ? (material.aoMapCoord + 1) : 0;
props.useMatcap = !!material.matcap;
props.useVertexUvs = !!material.diffuseMap || !!material.alphaMap || !!material.normalMap || !!material.bumpMap || !!material.specularMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.glossinessMap || !!material.aoMap;
// lights

@@ -376,3 +381,3 @@ props.ambientLightNum = !!lights ? lights.ambientsNum : 0;

console.warn("WebGL 1.0 not support PCSS soft shadow, fallback to POISSON_SOFT");
props.shadowType = SHADOW_TYPE.POISSON_SOFT
props.shadowType = SHADOW_TYPE.POISSON_SOFT;
} else {

@@ -389,2 +394,3 @@ props.shadowType = object.shadowType;

props.emissiveMapEncoding = getTextureEncodingFromMap(material.emissiveMap);
props.matcapEncoding = getTextureEncodingFromMap(material.matcap);
// other

@@ -391,0 +397,0 @@ props.alphaTest = material.alphaTest;

@@ -129,2 +129,8 @@ import { BLEND_TYPE, CULL_FACE_TYPE, WEBGL_COMPARE_FUNC } from '../../const.js';

var currentStencilZPass = null;
var currentStencilFuncBack = null;
var currentStencilRefBack = null;
var currentStencilFuncMaskBack = null;
var currentStencilFailBack = null;
var currentStencilZFailBack = null;
var currentStencilZPassBack = null;
var currentStencilClear = null;

@@ -149,7 +155,15 @@

setFunc: function (stencilFunc, stencilRef, stencilMask) {
setFunc: function (stencilFunc, stencilRef, stencilMask, stencilFuncBack, stencilRefBack, stencilMaskBack) {
if (currentStencilFunc !== stencilFunc ||
currentStencilRef !== stencilRef ||
currentStencilFuncMask !== stencilMask) {
gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
currentStencilRef !== stencilRef ||
currentStencilFuncMask !== stencilMask ||
currentStencilFuncBack !== stencilFuncBack ||
currentStencilRefBack !== stencilRefBack ||
currentStencilFuncMaskBack !== stencilMaskBack) {
if (stencilFuncBack === null || stencilRefBack === null || stencilMaskBack === null) {
gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
} else {
gl.stencilFuncSeparate(gl.FRONT, stencilFunc, stencilRef, stencilMask);
gl.stencilFuncSeparate(gl.BACK, stencilFuncBack, stencilRefBack, stencilMaskBack);
}

@@ -159,10 +173,21 @@ currentStencilFunc = stencilFunc;

currentStencilFuncMask = stencilMask;
currentStencilFuncBack = stencilFuncBack;
currentStencilRefBack = stencilRefBack;
currentStencilFuncMaskBack = stencilMaskBack;
}
},
setOp: function (stencilFail, stencilZFail, stencilZPass) {
setOp: function (stencilFail, stencilZFail, stencilZPass, stencilFailBack, stencilZFailBack, stencilZPassBack) {
if (currentStencilFail !== stencilFail ||
currentStencilZFail !== stencilZFail ||
currentStencilZPass !== stencilZPass) {
gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
currentStencilZFail !== stencilZFail ||
currentStencilZPass !== stencilZPass ||
currentStencilFailBack !== stencilFailBack ||
currentStencilZFailBack !== stencilZFailBack ||
currentStencilZPassBack !== stencilZPassBack) {
if (stencilFailBack === null || stencilZFailBack === null || stencilZPassBack === null) {
gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
} else {
gl.stencilOpSeparate(gl.FRONT, stencilFail, stencilZFail, stencilZPass);
gl.stencilOpSeparate(gl.BACK, stencilFailBack, stencilZFailBack, stencilZPassBack);
}

@@ -172,2 +197,5 @@ currentStencilFail = stencilFail;

currentStencilZPass = stencilZPass;
currentStencilFailBack = stencilFailBack;
currentStencilZFailBack = stencilZFailBack;
currentStencilZPassBack = stencilZPassBack;
}

@@ -174,0 +202,0 @@ },

@@ -432,8 +432,8 @@ import { WEBGL_UNIFORM_TYPE, WEBGL_PIXEL_TYPE, WEBGL_PIXEL_FORMAT, WEBGL_TEXTURE_FILTER, WEBGL_COMPARE_FUNC } from '../../const.js';

if (u !== undefined) u.set(value, glCore);
}
};
WebGLUniforms.prototype.has = function(name) {
return !!this.map[name];
}
};
export { WebGLUniforms };

@@ -20,3 +20,3 @@ import { TextureBase } from './TextureBase.js';

*/
this.image = { data: new Uint8Array(255, 255, 255, 255, 255, 255, 255, 255), width: 2, height: 2, depth: 2 };
this.image = { data: new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255]), width: 2, height: 2, depth: 2 };

@@ -23,0 +23,0 @@ /**

@@ -308,4 +308,4 @@ import { Canvas2DMaterial } from './Canvas2DMaterial.js';

// override
updateMatrix() {
zen3d.Object3D.prototype.updateMatrix.call(this);
updateMatrix(force) {
zen3d.Object3D.prototype.updateMatrix.call(this, force);

@@ -312,0 +312,0 @@ this.sprites = [];

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc