New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

libxmodel-js

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libxmodel-js

JS library for parsing and reading XModel files from the Call of Duty franchise

latest
Source
npmnpm
Version
0.8.0
Version published
Maintainers
0
Created
Source

LibXModel-js

This library allows you to load Call of Duty XModel files in Javascript.

The code was translated to JS from: https://github.com/mauserzjeh/cod-asset-importer

I've only tested this with xmodel files from Call of Duty 1 and Call of Duty: United Offensive.

Example Usage

async function getFileBytes(path: string): Promise<Uint8Array> {
    const response = await fetch(path)
    const buffer = await response.arrayBuffer()
    return new Uint8Array(buffer);
}

const xmodelBytes = await getFileBytes('xmodel/my-model-file')
const xmodelLoader = new XModelLoader(xmodelBytes)
const model = await xmodelLoader.load('my-model-file', GameVersion.CoD)

const firstLod = model.lods[0]
const xmodelPartBytes = await getFileBytes(`xmodelparts/${firstLod.name}`)
const xmodelPartLoader = new XModelPartLoader(xmodelPartBytes)
const modelPart = xmodelPartLoader.load(firstLod.name)

for (let lod of model.lods) {
    console.log(lod.name, 'LOD textures:')
    for (let texturePath of lod.materials) {
        console.log(`- skins/${texturePath}`)
    }
    
    const surfBytes = await getFileBytes(`xmodelsurfs/${lod.name}`)
    const surfLoader = new XModelSurfLoader(surfBytes)
    const surf = await surfLoader.load(lod.name, modelPart)

    for (let surface of surf.surfaces) {
        console.log(surface)

        /*
         * mesh.positions = surface.vertices.flatMap(x => x.position)
         * mesh.normals = surface.vertices.flatMap(x => x.normal)
         * mesh.uvs = surface.vertices.flatMap(x => x.uv)
         * mesh.colors = surface.vertices.flatMap(x => x.color)
         * mesh.indices = surface.triangles
         */
    }
}

console.log('Collision LOD index: ', model.collisionLodIndex)

Keywords

xmodel

FAQs

Package last updated on 22 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts