反应threejs导入json问题

时间:2017-07-10 03:11:19

标签: json reactjs model

我有一个基于reactjs的项目构建,使用threejs https://github.com/toxicFork/react-three-renderer

当我导入从blender工具导出的json文件时,我收到一个响应作为我的index.html文件,不是我导入的json文件。你能帮我解决一下吗?

我的代码:

let parsedModel = new ParsedModel()
    parsedModel.load('./shelf.json')

class parserModel:

import * as THREE from 'three'
import OBJLoader from 'three-obj-loader'
OBJLoader(THREE)

export default class ParsedModel {
 constructor (settings) {
    this._objectLoader = new THREE.OBJLoader()
  }
 loadJSON (url, settings) {
    if (typeof settings !== 'undefined') {
      this._parseSettings(settings)
    }

    return new Promise((resolve, reject) => {
      this._objectLoader.load(
        url,
        // success callback
        (data) => {
          this.parse(data)
          resolve()
        },
        // progress callback
        () => {},
        // error callback
        (error) => {
          reject(error)
        }
      )
    })
  }
}

1 个答案:

答案 0 :(得分:0)

使用npmjs.com/package/copy-webpack-plugin

 /*
     * Plugin: CopyWebpackPlugin
     * Description: Copy files and directories in webpack.
     *
     * Copies project static assets.
     *
     * See: https://www.npmjs.com/package/copy-webpack-plugin
     */
    new CopyWebpackPlugin([{
      from: 'src/assets',
      to: 'assets'
    }]),

然后将文件json三个对象复制到资产文件夹