mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: read stream
This commit is contained in:
1 parent
016fe1c3d3
commit
93e405c370
11 files changed
+36
-36
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
import { Accessor, Document, Node, Scene } from '@gltf-transform/core';
|
import { Accessor, Document, Node, Scene } from '@gltf-transform/core';
|
||||||
import { times } from 'lodash';
|
import { times } from 'lodash';
|
||||||
import { Hierarchy, Sc2Stream } from '../streams/sc2';
|
import { Hierarchy, Sc2ReadStream } from '../streams/sc2';
|
||||||
import { ScgStream } from '../streams/scg';
|
import { ScgReadStream } from '../streams/scg';
|
||||||
import { VertexAttribute } from '../streams/scpg';
|
import { VertexAttribute } from '../streams/scpg';
|
||||||
import {
|
import {
|
||||||
vertexAttributeGLTFName,
|
vertexAttributeGLTFName,
|
||||||
@@ -16,8 +16,8 @@ Buffer.prototype.toJSON = function () {
|
|||||||
export async function extractArmor(data: string, fileName: string) {
|
export async function extractArmor(data: string, fileName: string) {
|
||||||
const sc2Path = `${data}/3d/Tanks/CollisionMeshes/${fileName}.sc2.dvpl`;
|
const sc2Path = `${data}/3d/Tanks/CollisionMeshes/${fileName}.sc2.dvpl`;
|
||||||
const scgPath = `${data}/3d/Tanks/CollisionMeshes/${fileName}.scg.dvpl`;
|
const scgPath = `${data}/3d/Tanks/CollisionMeshes/${fileName}.scg.dvpl`;
|
||||||
const sc2 = new Sc2Stream(await readDVPLFile(sc2Path)).sc2();
|
const sc2 = new Sc2ReadStream(await readDVPLFile(sc2Path)).sc2();
|
||||||
const scg = new ScgStream(await readDVPLFile(scgPath)).scg();
|
const scg = new ScgReadStream(await readDVPLFile(scgPath)).scg();
|
||||||
const document = new Document();
|
const document = new Document();
|
||||||
const scene = document.createScene();
|
const scene = document.createScene();
|
||||||
const buffer = document.createBuffer();
|
const buffer = document.createBuffer();
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import {
|
|||||||
Vector4Tuple,
|
Vector4Tuple,
|
||||||
} from 'three';
|
} from 'three';
|
||||||
import { TextureMutation, readTexture } from '../blitzkrieg/readTexture';
|
import { TextureMutation, readTexture } from '../blitzkrieg/readTexture';
|
||||||
import { Hierarchy, Sc2Stream, Textures } from '../streams/sc2';
|
import { Hierarchy, Sc2ReadStream, Textures } from '../streams/sc2';
|
||||||
import { ScgStream, vertexAttributeVectorSizes } from '../streams/scg';
|
import { ScgReadStream, vertexAttributeVectorSizes } from '../streams/scg';
|
||||||
import { VertexAttribute } from '../streams/scpg';
|
import { VertexAttribute } from '../streams/scpg';
|
||||||
import { readDVPLFile } from './readDVPLFile';
|
import { readDVPLFile } from './readDVPLFile';
|
||||||
|
|
||||||
@@ -48,8 +48,8 @@ export async function extractModel(
|
|||||||
) {
|
) {
|
||||||
const sc2Path = `${data}/3d/${path}.sc2.dvpl`;
|
const sc2Path = `${data}/3d/${path}.sc2.dvpl`;
|
||||||
const scgPath = `${data}/3d/${path}.scg.dvpl`;
|
const scgPath = `${data}/3d/${path}.scg.dvpl`;
|
||||||
const sc2 = new Sc2Stream(await readDVPLFile(sc2Path)).sc2();
|
const sc2 = new Sc2ReadStream(await readDVPLFile(sc2Path)).sc2();
|
||||||
const scg = new ScgStream(await readDVPLFile(scgPath)).scg();
|
const scg = new ScgReadStream(await readDVPLFile(scgPath)).scg();
|
||||||
const document = new Document();
|
const document = new Document();
|
||||||
const scene = document.createScene();
|
const scene = document.createScene();
|
||||||
const buffer = document.createBuffer();
|
const buffer = document.createBuffer();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { existsSync } from "fs";
|
import { existsSync } from 'fs';
|
||||||
import sharp from "sharp";
|
import sharp from 'sharp';
|
||||||
import { Vector3Tuple } from "three";
|
import { Vector3Tuple } from 'three';
|
||||||
import { readDVPLFile } from "../blitz/readDVPLFile";
|
import { readDVPLFile } from '../blitz/readDVPLFile';
|
||||||
import { DdsStream } from "../streams/dds";
|
import { DdsReadStream } from '../streams/dds';
|
||||||
import { PvrStream } from "../streams/pvr";
|
import { PvrReadStream } from '../streams/pvr';
|
||||||
|
|
||||||
export enum TextureMutation {
|
export enum TextureMutation {
|
||||||
Normal,
|
Normal,
|
||||||
@@ -28,16 +28,16 @@ type ReadTextureOptions =
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function readTexture(path: string, options?: ReadTextureOptions) {
|
export async function readTexture(path: string, options?: ReadTextureOptions) {
|
||||||
const ddsTexturePath = path.replace(".tex", ".dx11.dds.dvpl");
|
const ddsTexturePath = path.replace('.tex', '.dx11.dds.dvpl');
|
||||||
const isDds = existsSync(ddsTexturePath);
|
const isDds = existsSync(ddsTexturePath);
|
||||||
const resolvedTexturePath = isDds
|
const resolvedTexturePath = isDds
|
||||||
? ddsTexturePath
|
? ddsTexturePath
|
||||||
: ddsTexturePath.replace(".dds", ".pvr");
|
: ddsTexturePath.replace('.dds', '.pvr');
|
||||||
const decompressedDvpl = await readDVPLFile(resolvedTexturePath);
|
const decompressedDvpl = await readDVPLFile(resolvedTexturePath);
|
||||||
|
|
||||||
const raw = isDds
|
const raw = isDds
|
||||||
? await new DdsStream(decompressedDvpl).dds()
|
? await new DdsReadStream(decompressedDvpl).dds()
|
||||||
: new PvrStream(decompressedDvpl).pvr();
|
: new PvrReadStream(decompressedDvpl).pvr();
|
||||||
const channels = 4 * raw.width * raw.height;
|
const channels = 4 * raw.width * raw.height;
|
||||||
|
|
||||||
switch (options?.mutation) {
|
switch (options?.mutation) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { times } from 'lodash';
|
import { times } from 'lodash';
|
||||||
import { BufferStream } from './buffer';
|
import { ReadStream } from './buffer';
|
||||||
|
|
||||||
enum ValueType {
|
enum ValueType {
|
||||||
Null,
|
Null,
|
||||||
@@ -29,7 +29,7 @@ type Value =
|
|||||||
| Value[]
|
| Value[]
|
||||||
| { [key: string]: Value };
|
| { [key: string]: Value };
|
||||||
|
|
||||||
export class BkonStream extends BufferStream {
|
export class BkonReadStream extends ReadStream {
|
||||||
bkon() {
|
bkon() {
|
||||||
this.magic();
|
this.magic();
|
||||||
const header = this.header();
|
const header = this.header();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export class BufferStream {
|
export class ReadStream {
|
||||||
public index = 0;
|
public index = 0;
|
||||||
constructor(public buffer: Buffer) {}
|
constructor(public buffer: Buffer) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { times } from 'lodash';
|
import { times } from 'lodash';
|
||||||
import { Vector3Tuple, Vector4Tuple } from 'three';
|
import { Vector3Tuple, Vector4Tuple } from 'three';
|
||||||
import { WindowsStream } from './windows';
|
import { WindowsReadStream } from './windows';
|
||||||
|
|
||||||
enum DxgiFormat {
|
enum DxgiFormat {
|
||||||
UNKNOWN = 0,
|
UNKNOWN = 0,
|
||||||
@@ -171,7 +171,7 @@ enum DdsCaps2 {
|
|||||||
VOLUME = 0x200000,
|
VOLUME = 0x200000,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DdsStream extends WindowsStream {
|
export class DdsReadStream extends WindowsReadStream {
|
||||||
async dds() {
|
async dds() {
|
||||||
this.magicNumber();
|
this.magicNumber();
|
||||||
const header = this.header();
|
const header = this.header();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { clamp, isEqual, times } from 'lodash';
|
import { clamp, isEqual, times } from 'lodash';
|
||||||
import { BufferStream } from './buffer';
|
import { ReadStream } from './buffer';
|
||||||
|
|
||||||
export enum PvrFlags {
|
export enum PvrFlags {
|
||||||
NoFlag = 0,
|
NoFlag = 0,
|
||||||
@@ -91,7 +91,7 @@ enum ResolvedBitRatePixelFormat {
|
|||||||
R5G6B5A0,
|
R5G6B5A0,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PvrStream extends BufferStream {
|
export class PvrReadStream extends ReadStream {
|
||||||
pvr() {
|
pvr() {
|
||||||
const header = this.header();
|
const header = this.header();
|
||||||
this.metadata();
|
this.metadata();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Vector3Tuple, Vector4Tuple } from 'three';
|
import { Vector3Tuple, Vector4Tuple } from 'three';
|
||||||
import { ScpgStream } from './scpg';
|
import { ScpgReadStream } from './scpg';
|
||||||
|
|
||||||
export interface SC2 {
|
export interface SC2 {
|
||||||
'#dataNodes': DataNode[];
|
'#dataNodes': DataNode[];
|
||||||
@@ -288,7 +288,7 @@ interface SceneComponents {
|
|||||||
count: number;
|
count: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Sc2Stream extends ScpgStream {
|
export class Sc2ReadStream extends ScpgReadStream {
|
||||||
header() {
|
header() {
|
||||||
return {
|
return {
|
||||||
name: this.ascii(4),
|
name: this.ascii(4),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ScpgStream, VertexAttribute } from './scpg';
|
import { ScpgReadStream, VertexAttribute } from './scpg';
|
||||||
|
|
||||||
interface PolygonGroupRaw {
|
interface PolygonGroupRaw {
|
||||||
'##name': 'PolygonGroup';
|
'##name': 'PolygonGroup';
|
||||||
@@ -50,7 +50,7 @@ export const vertexAttributeVectorSizes = {
|
|||||||
[VertexAttribute.JOINTWEIGHT]: 4,
|
[VertexAttribute.JOINTWEIGHT]: 4,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export class ScgStream extends ScpgStream {
|
export class ScgReadStream extends ScpgReadStream {
|
||||||
header() {
|
header() {
|
||||||
return {
|
return {
|
||||||
name: this.ascii(4),
|
name: this.ascii(4),
|
||||||
@@ -71,7 +71,7 @@ export class ScgStream extends ScpgStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
polygonGroupsRaw.forEach((polygonGroupRaw) => {
|
polygonGroupsRaw.forEach((polygonGroupRaw) => {
|
||||||
const indicesStream = new ScpgStream(polygonGroupRaw.indices);
|
const indicesStream = new ScpgReadStream(polygonGroupRaw.indices);
|
||||||
const indices: number[] = [];
|
const indices: number[] = [];
|
||||||
|
|
||||||
for (let index = 0; index < polygonGroupRaw.indexCount; index++) {
|
for (let index = 0; index < polygonGroupRaw.indexCount; index++) {
|
||||||
@@ -82,9 +82,9 @@ export class ScgStream extends ScpgStream {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const verticesStream = new ScpgStream(polygonGroupRaw.vertices);
|
const verticesStream = new ScpgReadStream(polygonGroupRaw.vertices);
|
||||||
const vertices: BlitzkriegVertex[] = [];
|
const vertices: BlitzkriegVertex[] = [];
|
||||||
const { format, stride } = ScgStream.parseVertexFormat(
|
const { format, stride } = ScgReadStream.parseVertexFormat(
|
||||||
polygonGroupRaw.vertexFormat,
|
polygonGroupRaw.vertexFormat,
|
||||||
);
|
);
|
||||||
const strideBasedSize = stride * polygonGroupRaw.vertexCount;
|
const strideBasedSize = stride * polygonGroupRaw.vertexCount;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { times } from 'lodash';
|
import { times } from 'lodash';
|
||||||
import { BufferStream } from './buffer';
|
import { ReadStream } from './buffer';
|
||||||
|
|
||||||
enum KAType {
|
enum KAType {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
@@ -55,7 +55,7 @@ export enum VertexAttribute {
|
|||||||
CUBETEXCOORD3 = 19,
|
CUBETEXCOORD3 = 19,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ScpgStream extends BufferStream {
|
export class ScpgReadStream extends ReadStream {
|
||||||
vectorN(size: number) {
|
vectorN(size: number) {
|
||||||
return times(size, () => this.float32());
|
return times(size, () => this.float32());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BufferStream } from './buffer';
|
import { ReadStream } from './buffer';
|
||||||
|
|
||||||
export class WindowsStream extends BufferStream {
|
export class WindowsReadStream extends ReadStream {
|
||||||
dword() {
|
dword() {
|
||||||
return this.uint32();
|
return this.uint32();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user