Decreased Performance in Vue Threejs with Larger JSON Data Sets

I am currently upgrading a legacy Three.js project from Angular 1.5 to Vue 2.6. The project is used for visualizing objects in JSON file format and I'm experiencing a drop in frame rate, going from ~60FPS in Angular to ~12FPS in Vue when loading larger files. Specifically, the example compares the performance of large_object (3.6mb) with small_object (84kb).

The reason behind this decrease could be due to my use of three.js version 85, as the old THREE.json loader has been deprecated in newer versions. One potential solution might involve re-exporting the models in the newer standard. However, there remains the question of why the frame rate is significantly lower in Vue compared to Angular, despite loading the exact same files.

App.js

<template>
  <div id="app">
    <div id="modelView"></div>
  </div>
</template>
<script>
import Stats from "stats.js";
import * as THREE from 'three'
const OrbitControls = require('three-orbit-controls')(THREE)

export default {
  data(){
    return {
      camera: null,
      scene: new THREE.Scene(),
      renderer: null,
      controls: null, 
      loader: new THREE.ObjectLoader(),
      context: null,
      animationFrameID: null,
      stats: null
    }
  },
  mounted(){
    this.init()
    this.loader.load("./large_object.json", this.loadModel,this.onProgress, this.onError)
    this.animate();
  },
  methods:{
    init: function(){
      this.container = document.getElementById('modelView')

      this.stats = new Stats();
      this.stats.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom
      document.body.appendChild( this.stats.dom );

      var ambient = new THREE.AmbientLight(0xe8ecff, 1.4)
      ambient.name = 'ambientLight'
      this.scene.add(ambient)
      // set up renderer
      this.renderer = new THREE.WebGLRenderer({ antialias: true })
      this.renderer.setPixelRatio(window.devicePixelRatio)
      this.renderer.setSize(window.innerWidth, window.innerHeight )
      // this.renderer.shadowMap.enabled = true
      // this.renderer.shadowMap.type = THREE.PCFSoftShadowMap
      this.scene.background = new THREE.Color('rgb(255, 255, 255)')
      this.scene.fog = new THREE.Fog(0x1a2050, 10000, 10000)

      this.container.appendChild(this.renderer.domElement)

      // set up camera and controls
      this.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 20, 15000)
      this.camera.position.set(300, 400, 900)

      this.controls = new OrbitControls(this.camera, this.renderer.domElement)
      this.controls.update()
    },
    animate: function () {
      this.animationFrameID = requestAnimationFrame(this.animate)
      this.renderer.render(this.scene, this.camera)
      this.stats.update()
    },
    loadModel: function(obj){
      this.scene.add(obj)
    },
    // callback function for loadlayers function while parsing json
    onProgress: function (xhr) {
      console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
    },
    // callback function for loadlayers function while parsing json
    onError: function (err) {
      console.error('An error happened')
    },
  }
}
</script>
<style lang="scss">
body{
  margin:0;
  padding:0;
}
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
#modelView{
  height: 100vh;
  width: 100vw;
}
</style>

Answer №1

Switching the geometry file to Buffer Geometry significantly boosted the frame rate to 60FPS. It should be noted that this improvement addresses only a portion of the problem, as Vue's reactivity can lead to increased memory usage in larger applications. Visit this source for further details on optimizing component performance.

Current Version:

Three.js r.112

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

Issue with custom Javascript not executing in Internet Explorer versions 9 and 10

Initially, this script is found in the document's head section. <script> document.addEventListener("DOMContentLoaded", function () { var e, t = document.querySelectorAll("div.bounceInDown"); for (var n = 0, r = t.length; n & ...

Ways to split up array objects in an axios GET request

Hello, I recently implemented an AXIOS GET request that returns an array of objects. However, the current example I am using retrieves the entire array at once, and I need to separate the objects so that I can work with them individually. class CryptoAP ...

Prevent Vuetify dropdown v-menu with submenu from closing upon selection

Dealing with a Vuetify issue related to submenus in a dropdown menu. Everything is functioning correctly, except for the main dropdown menu not closing when clicking on a submenu item. The submenu closes properly. 1. Dropdown menu opens on click 2. Submenu ...

VueApp requires 'v-bind:key' directives for elements in iteration to function properly

Help needed with this error message: [vue/require-v-for-key] Elements in an iteration require 'v-bind:key' directives to be included. View the code on Codepen - here If you have a solution for this issue, please share! ...

Challenges with incrementing in Jquery's each loop and setTimeout

http://jsfiddle.net/fxLcy/ - an example showcasing the use of setTimeout. http://jsfiddle.net/fxLcy/1/ - this demo does not include setTimeout. Although all elements are correctly positioned, I am in need of that delayed animation =/ My goal is to arrang ...

Discover and transform any strings that begin with http & https into clickable links

Can I use jQuery to search a paragraph for all strings that begin with http & https and turn them into clickable links? I have my Twitter feed displayed on my website, but any lines starting with http & https are shown as regular text. Is it feasible to t ...

Simulating a function while testing a different function within a Vue composable

In my scenario, there is a case that involves the following: A composable function named useTreeData(), which incorporates several other functions A function called onNodeChange() which is returned as a result of destructuring the useTreeData Other functi ...

Arrange the select default option using AngularJS as the first option

I've been working on a project using Angular where I fetch data from a JSON file and push it to an array object. This data is then displayed in the options of a select element. My issue is: The default option with selection appears first, but I only ...

The map's content shifts with every scroll of the mouse, rather than being controlled by the

After creating a custom control in leaflet, I noticed that when interacting with it using scroll or click, the underlying map is affected instead of the control itself. <CustomMapControl> <div className="custom-c ...

Discover the route followed by an object containing a specific key within an array of objects

Imagine having an array of dictionaries like the one below. How can I locate the object with id: 121 using JavaScript? I've been struggling to figure this out and would appreciate any hints or algorithms on how to achieve this. The desired result sho ...

Unable to get the Gtranslate function to function properly within the drop-down menu

Currently, I am using Gtranslate.io languages on my website with flags displayed without a drop-down menu. Everything is running smoothly but now I am looking to enhance the user experience by placing the flags inside a drop-down list. I want English to ...

Nuxt: Configure Axios requests to have their origin set based on the current domain

Currently, I am utilizing @nuxtjs/proxy for making proxy requests. The setup in nuxt.config.js is working perfectly fine. nuxt.config.js proxy: { '/api/': { target: 'api.example.com', headers: { 'origin': &apo ...

When you drag down on mobile Safari on an iPad, touch events may cease to fire in HTML5

When I implement event listeners to handle touch events like touchmove and touchstart document.addEventListener("touchstart", function(event){ event.preventDefault(); document.getElementById("fpsCounter").innerHTML = "Touch ...

Updating the value of a global variable through dependency injection in AngularJS

One thing I consistently do is inject app.constant('DOCUMENT_ID', window.documentId || 1); into services, controllers, and directives. I'm now looking to convert DOCUMENT_ID into a global variable. The goal is for any changes made to DOCUME ...

Using three.js to project a scene onto a personalized mesh

After experimenting with a demonstration of Three.js rendering a scene to a texture, I managed to replicate its essence in my own project: within my main scene, there is now a sphere where a secondary scene is displayed using a THREE.WebGLRenderTarget buff ...

Endless invocation of AngularJS $http requests

Could someone kindly clarify why the $http request is continuously sending an infinite number of requests to the server in my application? The code snippet provided is causing this issue: (function(){ var app = angular.module("GrahamsSocksProducts", [ ...

The default image field value in Django Rest Framework triggers a Validation error

Our development team utilizes REST and includes a site management feature on our app. This feature retrieves information such as name, description, title, and icon from the API. Additionally, we have an admin interface on a separate front-end app that can ...

Nuxt encountering a critical issue: "module 'dir-glob' not found"

Recently, while running my Nuxt app, I encountered an error after restarting the server using npm run dev. The error message stated that it couldn't find the module 'dir-glob'. Despite finding a similar issue on Stack Overflow related to Ang ...

Tips for showcasing an image on an HTML page

I am encountering an issue with my HTML page that includes a Button. When clicked, it is supposed to display an image using an Ajax call. The functionality works properly in Postman Rest Client. However, when accessed through a browser, it only shows raw ...

Determine whether a request is for CSS or JavaScript when using NodeJS and Express

My routing configuration includes the following setup: app.get('*', function (req, res, next) { req.xhr ? next() : res.render('layout/layout'); }); The idea behind this is to return the base layout if the request is not an XMLHttp ...