Three.js - include mesh data in code

前端 未结 1 965
心在旅途
心在旅途 2021-01-28 13:59

I have this Three.js code with JSON loader loading mesh from file /models/mountain.json:

var Three = new function () {
    this.scene = new THREE.Scene()

    th         


        
相关标签:
1条回答
  • 2021-01-28 14:51

    Here is the pattern to follow if you want to load a model by parsing a JSON data structure.

    Modify your mountain.json file and give your data structure a name.

    var mountain = {
    
        "metadata": {
            "formatVersion" : 3.1,
            "generatedBy"   : "Blender 2.7 Exporter",
    
            ... etc ...
    
    }
    

    Include the following code in your source:

    <script src="mountain.js"></script>
    

    Now you can load your model like so:

    var loader = new THREE.JSONLoader();
    
    var model = loader.parse( mountain );
    
    mesh = new THREE.Mesh( model.geometry, model.materials[ 0 ] );
    
    scene.add( mesh );
    

    three.js r.70

    0 讨论(0)
提交回复
热议问题