xslasd / step2glb

step2glb Introduction Convert 3d model (STL/IGES/STEP/OBJ/FBX) to gltf and other Theoretical supported file formats Import: obj, 3ds, stl, ply, gltf, glb, off, 3dm, fbx, dae, wrl, 3mf, ifc, brep, step, iges, fcstd, bim. Export: obj, stl, ply, gltf, glb, off, 3dm, bim.
Apache License 2.0
20 stars 4 forks source link

How to get converted model file? #3

Closed TRYOKETHEPEN closed 6 days ago

TRYOKETHEPEN commented 1 week ago

Thanks for this project, I wonder how to get converted model file?

In "debug.js", defaultly use "LogStorage", it only print logs. So I changed "debug.js" as follow, to get the converted model file:

// import { LogStorage } from "./logstorage.js";
import { ExporterWorker } from "./handler.js";
import { Storage } from './storage.js';

// const logStorage = new LogStorage()
// const exporterWorker = new ExporterWorker(logStorage)

const myCfg = {
    "callback_url": "http://127.0.0.1:1901/test1",
    "callback_file": true,
    "s3_upload_config": {
        "endPoint": "127.0.0.1",
        "port": 9010,
        "useSSL": false,
        "accessKey": "xxxx",
        "secretKey": "xxxxx",
        "bucketName": "xxx-asset"
    }
}
const myStorage = new Storage(myCfg)
const exporterWorker = new ExporterWorker(myStorage)

var data = {
    gid: "debug",
    request_id: "1",
    urlType: 2,
    url: "./testfiles/stp/test.stp",
    file_name: "test.stp",
    convert_type: "glb",
    save_path: "./",
}
exporterWorker.export(data)

Then I build a http server at localhost, listening to "http://127.0.0.1:1901/test1", and the method is "POST". Then I excute "node debug.js":

TypeError: source.on is not a function at Function.DelayedStream.create (/home/projects/step2glb/node_modules/delayed-stream/lib/delayed_stream.js:33:10) at FormData.CombinedStream.append (/home/projects/step2glb/node_modules/combined-stream/lib/combined_stream.js:45:37) at FormData.append (/home/projects/step2glb/node_modules/form-data/lib/form_data.js:75:3) at file:///home/projects/step2glb/storage.js:61:26 at ObjectUploader. (/home/projects/step2glb/node_modules/minio/dist/main/object-uploader.js:65:7) at ObjectUploader.emit (node:events:377:35) at emitErrorNT (node:internal/streams/destroy:193:8) at emitErrorCloseNT (node:internal/streams/destroy:158:3) at processTicksAndRejections (node:internal/process/task_queues:83:21)

My nodejs & npm info is:

root@AIServer:/home/projects/step2glb# npm list demo@1.0.0 /home/projects/step2glb ├── axios@1.3.4 ├── draco3d@1.5.6 ├── express@4.18.2 ├── fflate@0.7.4 ├── formidable@2.1.1 ├── minio@7.0.33 ├── multer@1.4.5-lts.1 ├── occt-import-js@0.0.15 ├── rhino3dm@7.15.0 ├── three@0.150.1 └── web-ifc@0.0.39

root@AIServer:/home/projects/step2glb# node -v v16.2.0

xslasd commented 1 week ago

const myStorage = new Storage(myCfg) and const logStorage = new LogStorage() are my implementations. You can look at the LogStorage code and implement your own corresponding methods.

TRYOKETHEPEN commented 1 week ago

const myStorage = new Storage(myCfg) and const logStorage = new LogStorage() are my implementations. You can look at the LogStorage code and implement your own corresponding methods.

Thanks for reply! I'm new to JS, it's hard to me to develop new implement. I just want to use this project to convert model format for now.

From a cursory analysis of the code, I get that: (maybe useful for others)

  1. The api /convertwork/v1/importfile finally excute exportWorker.export(data), which equals what happened in "debug.js".
  2. The converted model, as http request form data, is generated in Storge.executionSuccess() .
  3. If _cfg.callbackfile is set to false, the export use minio (I don't know its details), otherwise use axios to POST.
  4. In data: 4.1. The gid & _requestid are just for identify. 4.2. The urlType is determined by input model's source type (file or url). 4.3. The url means input model's data path. 4.4. The _filename is always neccessary whatever urlType is. But actually it can be split from url or file, so its a little bit confusing with these similar params (file/file_name/url). 4.5. The _savepath is only used when _cfg.callbackfile is set to false.
  5. This project actually only support binary _converttype such as glb, because "OV.FileFormat.Binary" is fixed in "handler.js".

Now my "debug.js" is simplified as:

import { ExporterWorker } from "./handler.js";
import { Storage } from './storage.js';
import { FileSource } from "./engine/main.js";

const myCfg = {
    "callback_url": "http://127.0.0.1:1901/test1", //the converted model data POST to this url
    "callback_file": true //use axios to POST
}
const myStorage = new Storage(myCfg)
const exporterWorker = new ExporterWorker(myStorage)

var data = {
    gid: "debug", // use to identify, can be random
    request_id: "1", // use to identify, can be random
    urlType: FileSource.File, //input model's source
    url: "./testfiles/stp/test.stp", //input model's data
    file_name: "test.stp", //input model's name
    convert_type: "glb", //convert type
}
exporterWorker.export(data)

Now my problem is: After "node debug.js", I get req.file=undefined at http server. The server is:

const express = require("express");
const multer = require("multer");
const cors = require("cors"); 
const app = express();
const upload = multer({ dest: "uploads/" });

app.use(cors());

app.post("/test1", upload.single("file"), (req, res) => {
  const file = req.file;
  console.log("recv file: ", file);

  res.send({
    code: 200,
    data: "ok",
  });
});

app.listen(1901, () => {
  console.log("listen 1901");
});

It seems that form.append("file", file) has some problem unexpected:
howtogetfile howtogetfile2

I also tried to save converted model file locally. And I've checked the "model.glb" file I got, it is OK: savefilelocally

xslasd commented 1 week ago

I have fixed the code 'form.append("file", file, gid + ".glb")'. Please try again

TRYOKETHEPEN commented 6 days ago

I have fixed the code 'form.append("file", file, gid + ".glb")'. Please try again

Thanks! The problem is resolved