The error in three.js occurs when an object is not a valid instance of THREE.Object3D

When attempting to utilize three.js OBJLoader - (docs) with vue-threejs and Webpack, I encountered some challenges.

var OBJLoader = require('three-obj-loader')
OBJLoader(THREE)
var loader = new THREE.OBJLoader()

loader.load( require('./sphere.obj'), function ( geometry ) {
    var material =  new THREE.MeshBasicMaterial( { color: 0xffffff } )
    var mesh = new THREE.Mesh( geometry, material )
    return mesh
})

Despite my efforts of delaying mesh creation following this answer and employing webpack raw-loader and file-loader, the issue persists.

Answer â„–1

Special thanks to fritx for providing this insightful answer originally posted on: https://github.com/fritx/vue-threejs/issues/2

We appreciate you making use of the library!

Currently, a component like

<object3d :obj="mesh"></object3d>
assumes that the mesh already exists upon creation.

If you are utilizing asynchronous loaders, your code may resemble the following:

<template>
  <object3d v-if="mesh" :obj="mesh"></object3d>
</template>

<script>
export default {
  data () {
    return {
      mesh: null // <----
    }
  },
  methods: {
    createBox () {
      objLoader.load(xxx, geometry => {
        let mesh = new THREE.Mesh(geometry, material)
        this.mesh = mesh // <----
      })
    }
  }
}
</script>

For more snippets related to the keyword user:fritx "Loader.load(":

(including code from both vue-threejs and react-threejs)

https://github.com/search?q=user%3Afritx+%22Loader%28%29.load%28%22&ref=opensearch&type=Code

In "ExSpaceFighter.js", there is also a snippet featuring MTLLoader and OBJLoader:

https://github.com/fritx/react-threejs/blob/6e2317d1e616ed5562f889de6b885deffb14d18a/example/ExSpaceFighter.js#L18-L31

I hope this information proves helpful.

var mtlLoader = new MTLLoader();
mtlLoader.setBaseUrl( 'SpaceFighter03/' )
mtlLoader.setPath( 'SpaceFighter03/' )
mtlLoader.load( 'SpaceFighter03.mtl', ( materials ) => {
  materials.preload();
  var objLoader = new OBJLoader();
  objLoader.setMaterials( materials );
  objLoader.setPath( 'SpaceFighter03/' )
  objLoader.load( 'SpaceFighter03.obj', ( group ) => {
    const body = group.children[0]
    body.material.color.set(0xffffff)
    this.setState({ body })
  })
})

If any part of this explanation is inaccurate, please feel free to inform me ;)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Executing a function within another function using Vue.js (axios)

When I make a call to this.func1() within func2, func1 returns undefined. Can anyone offer some assistance? It seems like the function is returning nothing because axios is not finished yet. How can I resolve this issue? func1:function(val){ if(val.x == ...

npm ERROR: 404 - The package '@reactivex/rxjs' cannot be found in the npm registry

Encountering problems with the installation of this package through NPM. Attempting to install as it is a dependency of Angular2. Error: npm ERR! Darwin 15.0.0 npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "@reactivex/<a href="/cd ...

Is there a way to retrieve JSON data using Vue and Axios?

I'm facing an issue trying to retrieve product data from a JSON file. Despite attempting different methods and searching for solutions online, I have not been able to find one that fits my specific scenario. As I am new to both Vue and axios, I apprec ...

When I disable the select box, I prefer that nothing is currently selected

There is a form where users can input numbers and select the unit of measurement. I need to prevent users from selecting a unit if no number has been entered, and clear the unit value if the number is erased after a unit has been selected. <div> ...

What is the best way to execute Laravel mix using a custom URL?

I am currently working on an application that needs to be deployed on a staging server due to its dependencies on other servers within the network. Building it locally is not feasible in this case. The application is developed using Vue.js and Laravel. Du ...

Is there a way to make my modal appear only when the "New" option is clicked?

Is there a way to make my modal in VueJS open only when I click on the "New" option? <select v-model="input.des" @change="$refs.modalName.openModal()"> <option value="A">A</opt ...

Struggling with Running the Webpack serve Command

Struggling to set up a React app using Webpack and Babel. After following various tutorials on YouTube and other websites, I keep encountering the same error whenever I run the webpack serve command, even if my index.js file is empty. [ERROR]: ERROR in .. ...

What is the most efficient way to restrict multiple input fields, each using v-model, to only accept numeric values in Vue.js without duplicating code for every input field?

I have several input fields in Vue.js that I want to restrict to only accept numbers. I want to prevent users from entering any characters except digits from 0-9. I managed to achieve this successfully with a solution that is resistant to copy-paste: C ...

Tips for asynchronously modifying data array elements by adding and slicing

I am facing an issue in my vuejs application where I need to modify an array of items after the app has finished loading. My current setup looks like this: var n = 100; var myData = []; function loadMovies(n){ // async ajax requests // add items to ...

Is it considered poor practice for two components to both utilize the same module within the Vuex store?

Imagine you've created a brand new Vue component called BComponent, along with a fresh store module named BModule. Now, you find yourself in the situation where you need to utilize some state logic that's already been implemented in AModule for u ...

The process of downloading an image from Spring Boot using VueJs and displaying it within an <img> tag

I have created a Spring Boot backend with a Vue frontend. I am having issues when trying to download and display an image from Google Cloud Storage in my application. Sometimes the downloaded image appears to be cut off, as if not all bytes were sent. Howe ...

Troubleshooting Vue Single File Components Displaying Missing Styles

I'm currently attempting to incorporate styles into a vuejs single file component. I've successfully achieved this in a node app previously, but now I am working with a python/flask backend (not that it should make a difference). The Vue componen ...

The issue with the v date picker is that it is not triggering the change event when a single

I am having some trouble detecting the change event of a date picker. It was working perfectly when the user selected multiple days from the calendar, but if they only select a single date, the change method does not get triggered. Here is my attempt: < ...

Nuxt.js encountered an unexpected keyword 'export' causing a parsing error

Within my index.js file in the 'store' section, I am encountering the following code: import Vuex from 'vuex' // import axios from 'axios' const createStore = () => { return new Vuex.Store({ state: { loadedPost ...

Unleash the power of a module by exposing it to the global Window object using the dynamic

In my development process, I am utilizing webpack to bundle and manage my TypeScript modules. However, I am facing a challenge where I need certain modules or chunks to be accessible externally. Can anyone guide me on how to achieve this? Additional conte ...

How can I send an error message from a Laravel controller and handle it in InertiaJS using the form helper?

I am facing an issue where I need to handle errors in the controller, but they are not Laravel validation errors. This prevents me from accessing them using the inertiajs form helper without using props.errors. How can I return the error in a way that allo ...

VueJS in collaboration with Quasar framework

Incorporating VueJS with Quasar framework, I created a data table. Here is my implementation: <template> <div class="q-pa-md"> <q-table title="Task List Of The Day" :columns="columns" row-key="name" :pagination ...

Tips for integrating UIkit into a Vue.js project

I added uikit to my project using yarn. yarn add uikit Additionally, I included less-loader, less, and css-loader based on recommendations from this website. Now I attempted to use UIkit in my App.vue component like this: <template> < ...

Incorporate images into ReactJS Components without the need to save them locally as files

<img src={BASENAME+"/src/images/cabecera_CE.jpg"} id="idImgCabecera" alt="Universidad Politécnica de Cartagena" class="img-responsive"/> and I am looking to do the following: import PHOTO from './../images/cabecera_CE.jpg' <img src= ...

Encountering TypeScript error in the beforeRouteUpdate hook with Vue and vue-property-decorator

I am developing an application using Vue 2 with TypeScript and vue-property-decorator. Within my component, I am utilizing the beforeRouteEnter/beforeRouteUpdate hooks. One of the methods in my component is findProjects, which I want to call within the bef ...