【问题标题】:Importing blender JSON in Three.js在 Three.js 中导入搅拌机 JSON
【发布时间】:2015-08-24 16:28:36
【问题描述】:

您好,我在从 blender 导入模型时遇到问题。

此时我正在使用three.js (R71) 的最新版本。我在 blender 中安装了 three.js 的导出器,并且导出正常。

这是HTML的代码。

<body>
    <font size="+6"><b>TFG</b></font><br>
    <a href="../index.html">Volver a atrás</a>
    <hr>
    <div id='container'></div>      
    <script src="libs/ThreeJSV71/build/three.min.js"></script>
    <script src="libs/OrbitControls.js"></script>
    <script src="libs/Coordinates.js"></script>
    <script src="libs/dat.gui.min.js"></script>
    <script src="libs/stats.min.js"></script>   
    <script src="libs/ColladaLoader.js"></script>   

    <script src="threejs/tfg2.js"></script>
    <br>
</body>

下一个文件是我加载模型的 tfg2.js。

var width = window.innerWitdh,
    height = window.innerHeight,
    clock = new THREE.Clock(),
    scene,
    camera,
    renderer,
    ambientLight,
    directionalLight,
    loader,
    modelo = new THREE.Object3D();

init();
function init()
{
    scene =new THREE.Scene();

    camera = new THREE.PerspectiveCamera(40, width/height, 1000);
    camera.position.set(0,1,5);

    renderer = new THREE.WebGLRenderer({antialias: true});
    renderer.setSize(width,height); 
    renderer.setClearColor(new THREE.Color(0x0000AA));
    document.getElementById('container').appendChild(renderer.domElement);

    ambientLight = new THREE.AmbientLight(0xffffff);
    scene.add(ambientLight);

    directionalLight = new THREE.DirectionalLight(0xffffff);
    directionalLight.position.set(0,1,0);
    scene.add(directionalLight);

    scene.add(new THREE.GridHelper(10,1));
    loader = new THREE.JSONLoader();
    loader.load('blender/json/camara.json', function(geometry,materials)
    {
        modelo = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
        scene.add(modelo);
    });
}

当我尝试查看结果时,网页中没有显示任何内容,并且 de JavaScript 控制台也没有显示任何错误。如果我以 collada 格式和我拥有的另一个 .js 导出模型,我可以看到模型,但我需要使用 JSON。

我做错了什么?编辑:

在回调中添加:modelo.position.set(0,0,0) 以确保模型在原点。

【问题讨论】:

    标签: javascript json three.js blender


    【解决方案1】:

    既然没有错误,你可以做什么:

    1. 从搅拌机导出对象时,将对象转换为原点。转到原点>> 选择原点到几何体>> 将对象转换为 x、y、z 为零。 现在您的相机分别看到@位置 0,1,5 xyz 可能是你的对象相机没有看到的地方

    2. 或者将场景的子节点翻译成原点

    这可能会解决您的问题。正如我所见,日志中没有错误和警告。

    【讨论】:

    • 对不起,我试过了,但没有改变任何东西。如果有帮助,该网页将具有蓝色背景。当我加载另一个不使用任何 json 模型但绘制正方形的脚本时,背景变为黑色。当我使用加载 json 模型的脚本时,背景仍然是蓝色的。也许它可以帮助找到问题
    • 蓝色背景是因为我们有渲染器清除颜色蓝色:renderer.setClearColor(new THREE.Color(0x0000AA));没有 json 时出现黑色,因为任何一个对象都太大并且我们没有从外面看,尝试缩放对象。Jsfiddle 或压缩共享,否则你可以在场景中看到你的对象,孩子们尝试在那里调试。
    • 嗯,这很奇怪。您的解决方案帮助了我,但这不是问题。问题是相机。我将相机更改为camera = new THREE.PerspectiveCamera(45, aspectRatio,0.1,100); 并添加camera.lookAt(new THREE.Vector3(0,0,0)); 以确保相机正在寻找原点。现在工作正常,但继续做一些奇怪的事情,当我按 F12 打开 de javascript 控制台时才加载 JSON 模型。嗯,这又是一个问题。非常感谢您的帮助^^
    猜你喜欢
    • 2017-04-18
    • 2013-09-28
    • 1970-01-01
    • 2015-08-16
    • 2014-08-19
    • 2013-02-21
    • 2019-04-02
    • 1970-01-01
    • 2017-09-03
    相关资源
    最近更新 更多