Live2D

obj格式转换成gltf (obj2gltf 本地nodejs用法)

下载obj2gltf 

 https://files.cnblogs.com/files/kiyomi7/obj2gltf-master.zip

 

用Nodejs写的服务器 (生成的地址路径自行修改)

const http = require('http'); //1. 导入 http 模块
const fs = require('fs'); //5. 导入/加载/引入 文件模块

//2. 创建服务器对象
const server = http.createServer((req,res)=>{
    res.setHeader("Access-Control-Allow-Origin", "*");
});

//3. 开启服务器,3000为端口号
server.listen(3000, () => {
    console.log('Server is running...');
});

//4. 监听浏览器请求并进行处理
server.on('request', (req, res) => {
    //6. req对象的url属性中保存了当前请求的url地址
    const url = req.url;
        const obj2gltf = require('obj2gltf');
        const names = url.split(",");
        const path = require('path');
        console.log(__dirname);
        const modelpath = path.resolve(__dirname , '../uploads/earth3d/');
        console.log(modelpath);
        const options = {
            binary : true
        }
        obj2gltf( modelpath+'/orimodel'+names[0]+'.obj', options)
            .then(function(glb) {
                fs.writeFileSync(modelpath+"/"+names[1], glb);
                res.end(url);
            });
});

前端请求

$.ajax({
   url: 'http://127.0.0.1:3000/'+rename[0]+","+path,
   type: 'get',
   headers: {"Content-Type": "application/x-www-form-urlencoded", "Accept": "text/plain"},
   success: function (data) {
                   
   },
   error: function (XMLHttpRequest, textStatus, errorThrown) {
       console.log(XMLHttpRequest.status);
       console.log(XMLHttpRequest.readyState);
   ,
   complete: function(XMLHttpRequest, status) {
       Fast.api.close();
   } // 请求完成后最终执行参数
});

 

posted @ 2021-04-01 18:03  kikiy-  阅读(1124)  评论(0编辑  收藏  举报