Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | 1647x 7565x 7341x 1647x 7090x 7090x 1647x 1718x 1831x 1831x 115x 115x 115x 115x 1647x 5021x 5021x 5021x 5021x 4825x 4825x 4825x 1647x 1773x 1773x 1773x 1746x 1746x 1647x 1788x 1788x 1788x 1788x 1788x 1788x 1788x 1788x 1788x 1788x 1788x 1788x 1788x 1788x 1661x 1661x 1661x 1661x 1661x 1788x 1788x 7x 7x 7x 7x 1647x 130x 413x 1647x 1647x 2229x 2229x 411x 411x 411x 1818x 1647x 248x 248x 1647x 1647x 1647x 1647x 130x 413x 413x 413x 413x 407x 1647x 8693x 395x | import addToArray from "./addToArray.js";
import ForEach from "./ForEach.js";
import getAccessorByteStride from "./getAccessorByteStride.js";
import defined from "../../Core/defined.js";
import WebGLConstants from "../../Core/WebGLConstants.js";
/**
* Adds default glTF values if they don't exist.
*
* @param {object} gltf A javascript object containing a glTF asset.
* @returns {object} The modified glTF.
*
* @private
*/
function addDefaults(gltf) {
ForEach.accessor(gltf, function (accessor) {
if (defined(accessor.bufferView)) {
accessor.byteOffset = accessor.byteOffset ?? 0;
}
});
ForEach.bufferView(gltf, function (bufferView) {
Eif (defined(bufferView.buffer)) {
bufferView.byteOffset = bufferView.byteOffset ?? 0;
}
});
ForEach.mesh(gltf, function (mesh) {
ForEach.meshPrimitive(mesh, function (primitive) {
primitive.mode = primitive.mode ?? WebGLConstants.TRIANGLES;
if (!defined(primitive.material)) {
Eif (!defined(gltf.materials)) {
gltf.materials = [];
}
const defaultMaterial = {
name: "default",
};
primitive.material = addToArray(gltf.materials, defaultMaterial);
}
});
});
ForEach.accessorContainingVertexAttributeData(gltf, function (accessorId) {
const accessor = gltf.accessors[accessorId];
const bufferViewId = accessor.bufferView;
accessor.normalized = accessor.normalized ?? false;
if (defined(bufferViewId)) {
const bufferView = gltf.bufferViews[bufferViewId];
bufferView.byteStride = getAccessorByteStride(gltf, accessor);
bufferView.target = WebGLConstants.ARRAY_BUFFER;
}
});
ForEach.accessorContainingIndexData(gltf, function (accessorId) {
const accessor = gltf.accessors[accessorId];
const bufferViewId = accessor.bufferView;
if (defined(bufferViewId)) {
const bufferView = gltf.bufferViews[bufferViewId];
bufferView.target = WebGLConstants.ELEMENT_ARRAY_BUFFER;
}
});
ForEach.material(gltf, function (material) {
const extensions = material.extensions ?? {};
const materialsCommon = extensions.KHR_materials_common;
Iif (defined(materialsCommon)) {
const technique = materialsCommon.technique;
const values = defined(materialsCommon.values)
? materialsCommon.values
: {};
materialsCommon.values = values;
values.ambient = defined(values.ambient)
? values.ambient
: [0.0, 0.0, 0.0, 1.0];
values.emission = defined(values.emission)
? values.emission
: [0.0, 0.0, 0.0, 1.0];
values.transparency = values.transparency ?? 1.0;
if (technique !== "CONSTANT") {
values.diffuse = defined(values.diffuse)
? values.diffuse
: [0.0, 0.0, 0.0, 1.0];
if (technique !== "LAMBERT") {
values.specular = defined(values.specular)
? values.specular
: [0.0, 0.0, 0.0, 1.0];
values.shininess = values.shininess ?? 0.0;
}
}
// These actually exist on the extension object, not the values object despite what's shown in the spec
materialsCommon.transparent = materialsCommon.transparent ?? false;
materialsCommon.doubleSided = materialsCommon.doubleSided ?? false;
return;
}
material.emissiveFactor = material.emissiveFactor ?? [0.0, 0.0, 0.0];
material.alphaMode = material.alphaMode ?? "OPAQUE";
material.doubleSided = material.doubleSided ?? false;
Iif (material.alphaMode === "MASK") {
material.alphaCutoff = material.alphaCutoff ?? 0.5;
}
const techniquesExtension = extensions.KHR_techniques_webgl;
Iif (defined(techniquesExtension)) {
ForEach.materialValue(material, function (materialValue) {
// Check if material value is a TextureInfo object
if (defined(materialValue.index)) {
addTextureDefaults(materialValue);
}
});
}
addTextureDefaults(material.emissiveTexture);
addTextureDefaults(material.normalTexture);
addTextureDefaults(material.occlusionTexture);
const pbrMetallicRoughness = material.pbrMetallicRoughness;
if (defined(pbrMetallicRoughness)) {
pbrMetallicRoughness.baseColorFactor =
pbrMetallicRoughness.baseColorFactor ?? [1.0, 1.0, 1.0, 1.0];
pbrMetallicRoughness.metallicFactor =
pbrMetallicRoughness.metallicFactor ?? 1.0;
pbrMetallicRoughness.roughnessFactor =
pbrMetallicRoughness.roughnessFactor ?? 1.0;
addTextureDefaults(pbrMetallicRoughness.baseColorTexture);
addTextureDefaults(pbrMetallicRoughness.metallicRoughnessTexture);
}
const pbrSpecularGlossiness =
extensions.KHR_materials_pbrSpecularGlossiness;
if (defined(pbrSpecularGlossiness)) {
pbrSpecularGlossiness.diffuseFactor =
pbrSpecularGlossiness.diffuseFactor ?? [1.0, 1.0, 1.0, 1.0];
pbrSpecularGlossiness.specularFactor =
pbrSpecularGlossiness.specularFactor ?? [1.0, 1.0, 1.0];
pbrSpecularGlossiness.glossinessFactor =
pbrSpecularGlossiness.glossinessFactor ?? 1.0;
addTextureDefaults(pbrSpecularGlossiness.specularGlossinessTexture);
}
});
ForEach.animation(gltf, function (animation) {
ForEach.animationSampler(animation, function (sampler) {
sampler.interpolation = sampler.interpolation ?? "LINEAR";
});
});
const animatedNodes = getAnimatedNodes(gltf);
ForEach.node(gltf, function (node, id) {
const animated = defined(animatedNodes[id]);
if (
animated ||
defined(node.translation) ||
defined(node.rotation) ||
defined(node.scale)
) {
node.translation = node.translation ?? [0.0, 0.0, 0.0];
node.rotation = node.rotation ?? [0.0, 0.0, 0.0, 1.0];
node.scale = node.scale ?? [1.0, 1.0, 1.0];
} else {
node.matrix = node.matrix ?? [
1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0,
0.0, 1.0,
];
}
});
ForEach.sampler(gltf, function (sampler) {
sampler.wrapS = sampler.wrapS ?? WebGLConstants.REPEAT;
sampler.wrapT = sampler.wrapT ?? WebGLConstants.REPEAT;
});
Iif (defined(gltf.scenes) && !defined(gltf.scene)) {
gltf.scene = 0;
}
return gltf;
}
function getAnimatedNodes(gltf) {
const nodes = {};
ForEach.animation(gltf, function (animation) {
ForEach.animationChannel(animation, function (channel) {
const target = channel.target;
const nodeId = target.node;
const path = target.path;
// Ignore animations that target 'weights'
if (path === "translation" || path === "rotation" || path === "scale") {
nodes[nodeId] = true;
}
});
});
return nodes;
}
function addTextureDefaults(texture) {
if (defined(texture)) {
texture.texCoord = texture.texCoord ?? 0;
}
}
export default addDefaults;
|