Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli export (WIP) #107

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,8 @@ web_modules/

# Optional eslint cache
.eslintcache
<<<<<<< HEAD
lerna-debug.log
.vscode
=======
<<<<<<< HEAD

# Microbundle cache
.rpt2_cache/
Expand Down
34 changes: 34 additions & 0 deletions 134_attributes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ "name": "134", "attributes": [
{
"trait_type": "BODY",
"value": "Feminine"
},
{
"trait_type": "CLOTHING",
"value": "Tech_Jacket_and_Gambler_Outfit"
},
{
"trait_type": "HAIR",
"value": "Long_BlondeBrown"
},
{
"trait_type": "TYPE",
"value": "Human"
},
{
"trait_type": "GLASSES",
"value": "Bleeding_Heart_Glasses"
},
{
"trait_type": "EARRING",
"value": "Earring_Cylinder"
},
{
"trait_type": "NECK",
"value": "Belt_Choker"
},
{
"trait_type": "WEAPON",
"value": "Assault_Rifle"
}
] }
93 changes: 93 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env node

import fs from "fs/promises";
import {program} from "commander";
import { JSDOM } from "jsdom";
import path from "path";

import * as THREE from 'three';
import { Buffer } from "buffer";

async function setup() {
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>',{
pretendToBeVisual: true,
});

globalThis.document = dom.window.document;
//globalThis.window = dom.window;
//window.isNode = true;
globalThis.navigator = dom.window.navigator;
globalThis.Buffer = Buffer;

const { CharacterManager } = await import("./src/library/characterManager.js");

const scene = new THREE.Scene()
const sceneElements = new THREE.Object3D();
scene.add(sceneElements);

const characterManager = await new CharacterManager({parentModel: scene, createAnimationManager : false});

const manifestRelativePath = "./public/character-assets/anata/manifest.json";
const testNFTRelativePath = "./134_attributes.json";
const manifestPath = path.resolve(process.cwd(), manifestRelativePath);
const NFTObjectPath = path.resolve(process.cwd(), testNFTRelativePath);

// Verify if the file exists
try {
await fs.access(manifestPath, fs.constants.R_OK);
console.log(`Manifest file exists at: ${manifestPath}`);
} catch (err) {
console.error(`Error accessing manifest file: ${err.message}`);
process.exit(1);
}
console.log(NFTObjectPath);
// Read the manifest file content using fs
const manifestContent = await fs.readFile(manifestPath, 'utf-8');
const nftContent = await fs.readFile(NFTObjectPath, 'utf-8');

// Parse the JSON content of the manifest file
const manifestObject = JSON.parse(manifestContent);

const newPath = path.resolve("./public/" + manifestObject.assetsLocation)
manifestObject.assetsLocation = newPath;
const nftObject = JSON.parse(nftContent);

await characterManager.setManifestObject(manifestObject);
await characterManager.loadTraitsFromNFTObject(nftObject, true, null, true);
console.log("finished")

//characterManager.downloadVRM("Test_download");
program
.version('1.0.0')
.description('Simple CLI to create a text file')
.option('-f, --filename <filename>', 'Specify the filename')
.option('-c, --content <content>', 'Specify the content for the file');

program.parse(process.argv);

const opts = program.opts()

console.log('Filename:', opts.filename);
console.log('Content:', opts.content);

if (!opts.filename || !opts.content) {
console.error('Both filename and content are required.');
process.exit(1);
}

const { filename, content } = opts;

fs.writeFile(filename, content, (err) => {
if (err) {
console.error(`Error creating file: ${err.message}`);
process.exit(1);
}
console.log(`File '${filename}' created successfully.`);
});
}

setup().catch(error => {
console.error('Error during setup:', error);
process.exit(1); // Terminate the process if there's an error
});

Loading