简体   繁体   English

如何将3D model加载到三个JS(JSON格式)

[英]How to load 3D model to Three JS (JSON Format)

I need to import a JSON file which contains information about a 3D model for Three JS.我需要导入一个 JSON 文件,其中包含有关三个 JS 的 3D model 的信息。 I have the boiler code for Three JS, I also have a loader function:我有三个 JS 的锅炉代码,我还有一个加载器 function:

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' );
    }
);

While running this code I don't get any errors or warnings, but the model doesn't show.运行此代码时,我没有收到任何错误或警告,但 model 没有显示。

The content of the JSON File if required: 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"
    }
}

What can I do to make my model show on the page.我该怎么做才能让我的 model 显示在页面上。

I'm afraid your JSON file uses an outdated JSON format which can't be loaded anymore.恐怕您的 JSON 文件使用了无法再加载的过时 JSON 格式。 You have to go back to r98 to load the JSON and then export it again with Scene.toJSON() .您必须将 go 重新加载到r98以加载 JSON ,然后使用Scene.toJSON()再次将其导出。 The resulting JSON is in the Object/Scene format 4 which can be loaded with the latest ObjectLoader again.生成的 JSON 采用对象/场景格式 4,可以再次使用最新的ObjectLoader加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM