mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-05 07:43:49 +01:00
polyfill both tank model and armor
This commit is contained in:
5 files changed
+61
-62
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
# BlitzKit 1.33.2
|
||||||
|
|
||||||
|
Fixed an issue that caused the armor of some tanks like the Type 71 to crash BlitzKit.
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "blitzkit",
|
"name": "blitzkit",
|
||||||
"version": "1.33.1",
|
"version": "1.33.2",
|
||||||
"license": "BlitzKit License",
|
"license": "BlitzKit License",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import type {
|
||||||
|
Accessor,
|
||||||
|
Buffer,
|
||||||
|
Document,
|
||||||
|
TypedArray,
|
||||||
|
} from "@gltf-transform/core";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The website batches primitives into BatchedMeshes, which need every
|
||||||
|
* primitive in them to have the same attributes. Batches cross materials (the
|
||||||
|
* armor view batches wheels with tracks), so a primitive missing an attribute
|
||||||
|
* any other in the document has (say TEXCOORD_1) gets it zero-filled, which is
|
||||||
|
* what the shader read for the missing attribute anyway.
|
||||||
|
*/
|
||||||
|
export function polyfillAttributes(document: Document, buffer: Buffer) {
|
||||||
|
const primitives = document
|
||||||
|
.getRoot()
|
||||||
|
.listMeshes()
|
||||||
|
.flatMap((mesh) => mesh.listPrimitives());
|
||||||
|
const references = new Map<string, Accessor>();
|
||||||
|
|
||||||
|
for (const primitive of primitives) {
|
||||||
|
for (const name of primitive.listSemantics()) {
|
||||||
|
if (!references.has(name)) {
|
||||||
|
references.set(name, primitive.getAttribute(name)!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const primitive of primitives) {
|
||||||
|
const count = primitive.getAttribute("POSITION")!.getCount();
|
||||||
|
|
||||||
|
for (const [name, reference] of references) {
|
||||||
|
if (primitive.getAttribute(name) !== null) continue;
|
||||||
|
|
||||||
|
const Array = reference.getArray()!.constructor as new (
|
||||||
|
length: number,
|
||||||
|
) => TypedArray;
|
||||||
|
|
||||||
|
primitive.setAttribute(
|
||||||
|
name,
|
||||||
|
document
|
||||||
|
.createAccessor(name)
|
||||||
|
.setType(reference.getType())
|
||||||
|
.setNormalized(reference.getNormalized())
|
||||||
|
.setArray(new Array(count * reference.getElementSize()))
|
||||||
|
.setBuffer(buffer),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
import type { AbstractVFS } from "@blitzkit/core/src/blitzkit/vfs/abstract";
|
import type { AbstractVFS } from "@blitzkit/core/src/blitzkit/vfs/abstract";
|
||||||
import { Accessor, Document, Node, NodeIO, Scene } from "@gltf-transform/core";
|
import { Accessor, Document, Node, NodeIO, Scene } from "@gltf-transform/core";
|
||||||
import type { APIContext } from "astro";
|
import type { APIContext } from "astro";
|
||||||
|
import { polyfillAttributes } from "../../../core/blitzkit/polyfillAttributes";
|
||||||
import { vfs } from "../../../core/blitzkit/vfs";
|
import { vfs } from "../../../core/blitzkit/vfs";
|
||||||
|
|
||||||
export { getStaticPaths } from "./_index";
|
export { getStaticPaths } from "./_index";
|
||||||
@@ -163,6 +164,8 @@ async function extractArmor(vfs: AbstractVFS, fileName: string) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
polyfillAttributes(document, buffer);
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ import {
|
|||||||
Node,
|
Node,
|
||||||
NodeIO,
|
NodeIO,
|
||||||
Scene,
|
Scene,
|
||||||
type Accessor,
|
|
||||||
type Primitive,
|
|
||||||
type Skin,
|
type Skin,
|
||||||
type TypedArray,
|
|
||||||
} from "@gltf-transform/core";
|
} from "@gltf-transform/core";
|
||||||
import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
|
import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
|
||||||
import { dedup, prune } from "@gltf-transform/functions";
|
import { dedup, prune } from "@gltf-transform/functions";
|
||||||
@@ -31,6 +28,7 @@ import type { APIContext } from "astro";
|
|||||||
import { isEqual, times } from "lodash-es";
|
import { isEqual, times } from "lodash-es";
|
||||||
import { dirname } from "path";
|
import { dirname } from "path";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
|
import { polyfillAttributes } from "../../../core/blitzkit/polyfillAttributes";
|
||||||
import type { Motion } from "../../../core/blitzkit/skinAnimations/motion";
|
import type { Motion } from "../../../core/blitzkit/skinAnimations/motion";
|
||||||
import {
|
import {
|
||||||
bindSocket,
|
bindSocket,
|
||||||
@@ -373,64 +371,8 @@ export async function extractModel(
|
|||||||
|
|
||||||
await document.transform(prune({ keepAttributes: true }), dedup());
|
await document.transform(prune({ keepAttributes: true }), dedup());
|
||||||
|
|
||||||
/**
|
// parts aren't batched so their bones can animate
|
||||||
* The website batches a model's primitives by material, and a batch needs
|
if (!isPart) polyfillAttributes(document, buffer);
|
||||||
* every primitive to have the same attributes. A primitive missing one that
|
|
||||||
* another of its material has (say TEXCOORD_1) gets it zero-filled, which is
|
|
||||||
* what the shader read for the missing attribute anyway. Parts aren't
|
|
||||||
* batched so their bones can animate.
|
|
||||||
*/
|
|
||||||
if (!isPart) {
|
|
||||||
const groups = new Map<Material | null, Primitive[]>();
|
|
||||||
|
|
||||||
for (const mesh of document.getRoot().listMeshes()) {
|
|
||||||
for (const primitive of mesh.listPrimitives()) {
|
|
||||||
const material = primitive.getMaterial();
|
|
||||||
let group = groups.get(material);
|
|
||||||
|
|
||||||
if (!group) {
|
|
||||||
group = [];
|
|
||||||
groups.set(material, group);
|
|
||||||
}
|
|
||||||
|
|
||||||
group.push(primitive);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const primitives of groups.values()) {
|
|
||||||
const references = new Map<string, Accessor>();
|
|
||||||
|
|
||||||
for (const primitive of primitives) {
|
|
||||||
for (const name of primitive.listSemantics()) {
|
|
||||||
if (!references.has(name)) {
|
|
||||||
references.set(name, primitive.getAttribute(name)!);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const primitive of primitives) {
|
|
||||||
const count = primitive.getAttribute("POSITION")!.getCount();
|
|
||||||
|
|
||||||
for (const [name, reference] of references) {
|
|
||||||
if (primitive.getAttribute(name) !== null) continue;
|
|
||||||
|
|
||||||
const Array = reference.getArray()!.constructor as new (
|
|
||||||
length: number,
|
|
||||||
) => TypedArray;
|
|
||||||
|
|
||||||
primitive.setAttribute(
|
|
||||||
name,
|
|
||||||
document
|
|
||||||
.createAccessor(name)
|
|
||||||
.setType(reference.getType())
|
|
||||||
.setNormalized(reference.getNormalized())
|
|
||||||
.setArray(new Array(count * reference.getElementSize()))
|
|
||||||
.setBuffer(buffer),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user