我将Webpack与Babylonjs结合使用,但无法使用importMesh方法加载模型

时间:2018-09-27 13:45:25

标签: javascript webpack babylonjs

我正在使用webpack,我尝试为babylonjs加载3d模型,这是我编写代码的方式,我需要它后也需要它,图像文件也无法显示,我已经尝试过了,而且SceneLoader.loader或SceneLoader.ImportMesh,我安装了npm -也可以保存babylongjs-loaders,但是我无法加载3D模型,我被困在这里帮助

 BABYLON.SceneLoader.ImportMesh("him",require('./Dude/dude.babylon'), scene, function (newMeshes, particleSystems, skeletons) {

    newMeshes[0].position = new BABYLON.Vector3(0, 0, 5);  // The original dude
    scene.beginAnimation(skeletons[0], 0, 120, 1.0, true);


})

错误日志为

         Uncaught TypeError: o._addPendingData is not a function
      at Function.i.ImportMesh (babylon.js?0ab6:35)
at createScene2 (app.js?11ea:42)
at Object.module.exports.Game (app.js?11ea:22)
at eval (index.js?9bdc:58)
at Object.<anonymous> (shanli.bundle.js?e7156e9c7a7b9cbf4463:1)
at m (shanli.bundle.js?e7156e9c7a7b9cbf4463:1)
at l (shanli.bundle.js?e7156e9c7a7b9cbf4463:1)
at Object.<anonymous> (shanli.bundle.js?e7156e9c7a7b9cbf4463:1)
       at m (shanli.bundle.js?e7156e9c7a7b9cbf4463:1)
           at shanli.bundle.js?e7156e9c7a7b9cbf4463:1

我的webpack是webpack 2.7.0 我也有npm install --save babylon-file-loader

我的webpack.config.js

 const path = require('path');
 const HtmlWebpackPlugin = require('html-webpack-plugin');
  const ExtractTextPlugin = require('extract-text-webpack-plugin');
  const webpack = require('webpack');
  const autoprefixer = require('autoprefixer');
  const PurifyCSSPlugin = require('purifycss-webpack');
   const glob = require('glob-all');
  module.exports = {
  devtool: 'inline-source-map',
  context: path.resolve(__dirname, './src'),
entry: {

    shanli: ["./app/index.js"]
        // 'vendor': ['./app/index.js']


},
output: {
    path: path.join(__dirname, 'public', 'assets'),
    filename: 'js/[name].bundle.js',
    publicPath: '/public/assets/'
},
externals:{
     oimo:'OIMO',
     cannon:'CANNON',
     earcut:'EARCUT'
},
module: {
    rules: [{
            test: /\.css$/,
            loader: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use: ['css-loader', 'postcss-loader'],
            }),




        },
        // {
        //     test: /\.(scss)$/,
        //     use: [{
        //       loader: 'style-loader', // inject CSS to page
        //     }, {
        //       loader: 'css-loader', // translates CSS into CommonJS modules
        //     }, {
        //       loader: 'postcss-loader', // Run post css actions
        //       options: {
        //         plugins: function () { // post css plugins, can be exported to postcss.config.js
        //           return [
        //             require('precss'),
        //             require('autoprefixer')
        //           ];
        //         }
        //       }
        //     }, {
        //       loader: 'sass-loader' // compiles SASS to CSS
        //     }]
        //   },
        {
            test: /\.scss$/,
            loader: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use: ['css-loader', 'sass-loader', 'postcss-loader'],


            })
        }, {
            test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            use: [{
                loader: 'babel-loader',
                options: {
                    presets: [
                        ['es2015']
                    ]
                }
            }]
        }, {
            test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp3|wav|mp4)(\?.*)?$/,
            use:[
                {
                    loader: 'file-loader',
                query: {
                    name: 'images/[name].[ext]?[hash]'
                }
            },{
                loader:'img-loader'
            }
            ],


        },{
            test: /\.babylon$/,
            use: [
              {
                loader: 'babylon-file-loader',

                query:{
                    name:'models/[name].[ext]?[hash]'
                }  
              }
            ]
          }, {
            test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
            loader: 'url-loader',
            query: {
                limit: 10000,
                name: 'media/[name].[ext]?[hash]'
            }

        }, {
            test: /\.json$/,
            loader: 'json-loader',
            query: {
                name: 'models/[name].[ext]?[hash]'

            },
        },
    ]
},

devServer: {
    overlay: true,
    proxy: {
      '/web': {
        target: 'http://localhost:8000',
        pathRewrite: {'^/web': ''}
      }
    },
    contentBase:path.resolve(__dirname,'./public/assets/html'),
    headers:{
        'Access-Control-Allow-Origin':'*',
        'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
  'Access-Control-Allow-Headers': 'X-Requested-With, content-type'
    }
},
    node:{
        fs:'empty'
    },
plugins: [

    new webpack.LoaderOptionsPlugin({
        options: {
            minimize: true,
            postcss: [
                autoprefixer({
                    browsers: ['last 2 version', 'Chrome >=49', 'Firefox >=49', 'Edge >= 11', 'ie >= 9']
                }),
            ]
        }

    }),



    new HtmlWebpackPlugin({
        title: 'shanli',
        minify: {
            removeComments: true,
            collapseWhitespace: true,
            removeRedundantAttributes: true,
            useShortDoctype: true,
            removeEmptyAttributes: true,
            removeStyleLinkTypeAttributes: true,
            keepClosingSlash: true,
            minifyJS: true,
            minifyCSS: true,
            minifyURLs: true,
            collapseWhitespace: true
        },
        hash: true,
        inject: true,
        template: './template/index.html', //load custom template .ejs by default.
        filename: 'html/index.html',
        chunks: ['shanli']
    }),

    new webpack.optimize.UglifyJsPlugin({
        test: /(\.jsx|\.js)$/,
        minimize: true,
        sourceMap: true,
        compress: {
            sequences: true,
            dead_code: true,
            unused: true,
            warnings: false,
            screw_ie8: true,
            conditionals: true,

            comparisons: true,
            evaluate: true,
            if_return: true,
            join_vars: true
        },
        compressor: {
            warnings: false
        },
        output: {
            comments: false
        }
    }),
    new ExtractTextPlugin({
        filename: 'css/[name].bundle.css',
        disable: false,
        allChunks: true,

    }),

    new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "window.jQuery": "jquery"
            // Popper:['Popper.js', 'defalut']
            // in case you imported plugins individually, you must also require them there ;

    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin()
]

}

0 个答案:

没有答案