【问题标题】:How to load 3D model to Three JS (JSON Format)如何将 3D 模型加载到三个 JS(JSON 格式)
【发布时间】:2021-07-13 21:08:33
【问题描述】:

我需要导入一个 JSON 文件,其中包含有关 Three JS 的 3D 模型的信息。 我有三个 JS 的锅炉代码,我还有一个加载器功能:

const loader = new THREE.ObjectLoader();

loader.load(
    // resource URL
    "modell.json",

    // onLoad callback
    // Here the loaded data is assumed to be an object
    function ( obj ) {
        // Add the loaded object to the scene
        scene.add( obj );
        console.log(scene)
    },

    // onProgress callback
    function ( xhr ) {
        console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
    },

    // onError callback
    function ( err ) {
        console.error( 'An error happened' );
    }
);

运行此代码时,我没有收到任何错误或警告,但模型没有显示。

JSON 文件的内容(如果需要):

{
    "metadata": {
        "version": 4.4,
        "generator": "io_three",
        "type": "Object"
    },
    "animations": [{
        "fps": 29,
        "tracks": [],
        "name": "default"
    }],
    "images": [],
    "textures": [],
    "geometries": [{
        "uuid": "EC53DCE4-C690-3888-9701-2800E0AFBE11",
        "data": {
            "skinWeights": [],
            "influencesPerVertex": 2,
            "normals": [],
            "vertices": [],
            "skinIndices": [],
            "faces": [],
            "metadata": {
                "version": 3,
                "generator": "io_three",
                "bones": 0,
                "uvs": 0,
                "normals": 0,
                "morphTargets": 0,
                "materials": 0,
                "vertices": 0
            },
            "animations": [],
            "morphTargets": [],
            "name": "defaultGeometry",
            "bones": [],
            "uvs": []
        },
        "materials": [],
        "type": "Geometry"
    }],
    "materials": [{
        "uuid": "7F7EA3D4-7ACA-326E-BEE4-3EA415B8E912",
        "blending": "NormalBlending",
        "type": "MeshPhongMaterial",
        "shininess": 50,
        "emissive": 0,
        "specular": 131586,
        "color": 8355711,
        "ambient": 8355711,
        "depthTest": true,
        "depthWrite": true,
        "vertexColors": false,
        "name": "armadillo_default"
    }],
    "object": {
        "uuid": "A4515F76-5125-492C-9CF8-7B3B0E15D8BE",
        "children": [{
            "name": "armadillo2",
            "uuid": "8AD86B53-F2E6-3978-A91C-657CCBEC6D8E",
            "matrix": [-1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1],
            "visible": true,
            "type": "Object",
            "children": [{
                "name": "default",
                "uuid": "E918B3CA-7846-3104-8C4D-FEB016A9E618",
                "matrix": [0.972172,0,0,0,0,-0,-0.972172,0,0,0.972172,-0,0,-0.015785,0.021605,0,1],
                "visible": false,
                "type": "Mesh",
                "material": "7F7EA3D4-7ACA-326E-BEE4-3EA415B8E912",
                "castShadow": true,
                "receiveShadow": true,
                "geometry": "EC53DCE4-C690-3888-9701-2800E0AFBE11"
            }]
        }],
        "matrix": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
        "type": "Scene"
    }
}

如何使我的模型显示在页面上。

【问题讨论】:

标签: javascript html three.js 3d gpu


【解决方案1】:

恐怕您的 JSON 文件使用了无法再加载的过时 JSON 格式。您必须返回r98 来加载 JSON,然后使用Scene.toJSON() 再次导出它。生成的 JSON 为对象/场景格式 4,可以再次加载最新的 ObjectLoader

【讨论】:

    猜你喜欢
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 2012-08-12
    • 1970-01-01
    • 2016-03-12
    • 1970-01-01
    • 2020-06-10
    相关资源
    最近更新 更多