Visibility issue in Three.js: Object not appearing immediately despite setting object.visible to true

I'm toggling visibility in my Three.js scene by using the .visible property on objects.

Initially, certain objects (rooms) have their .visible property set to false. Once the camera enters a specific mesh (the room bounding box), the .visible property is turned to true and the room becomes visible.

However, there seems to be a slight delay (a few seconds or less) between setting the .visible property to true and the room actually appearing. This delay is reduced after entering the rooms multiple times.

What could be causing this delay? Is there a way to determine when the room is fully prepared for rendering? It appears that update events are not triggered after setting .visible to true, so listening for those events may not provide a solution.

Any assistance would be greatly appreciated,

Thanks!

UPDATE

Since I encountered issues with using ColladaLoader2.js, I opted to manually traverse the models loaded using ColladaLoader.js and replace all geometry properties with a copy of BufferGeometry created from the existing Geometry object. I discovered that setting the .dynamic property of an existing Geometry object to false has a similar effect.

dae.traverse(function (obj) {
    if (obj.hasOwnProperty('geometry')) {
        obj.dynamic = false;
        //obj.geometry = new THREE.BufferGeometry().fromGeometry(obj.geometry);
    }
});

Now, when I change the .visible property of an object to true, the engine momentarily freezes instead of experiencing the previous delay before the object becomes visible. I now need to decide where I can tolerate this brief freeze, as it may not be feasible for all objects to be visible concurrently for performance considerations.

Having more control and insight into whether an object and its geometry are loaded and ready for display, or if they need to be reloaded into memory, would be helpful. Currently, it is unclear whether a BufferGeometry will render immediately upon setting .visible to true, or if a brief freeze will occur.

Answer №1

When rendering, it is important to convert <code>Geometry
to BufferGeometry. This conversion process will not take place if mesh.visible is set to false. Keep in mind that the conversion can be time-consuming for complex geometries or a large number of geometries.

One solution is to build your meshes using BufferGeometry.

var bufferGeometry = new THREE.BufferGeometry().fromGeometry( geometry );
var mesh = new THREE.Mesh( bufferGeometry, material );

Version of three.js: r.73

Answer №2

When looking at my code, I noticed that there is a delay when objects are initially switched to visible. However, once they have been toggled between visible true/false, there does not appear to be another delay.

As a workaround, one solution could be to set the visible flag on all objects and render everything when the WebGLRenderer is not displayed on the browser (for example, when it is located behind a level loading screen). Then, adjust the objects' visible flags accordingly before displaying the screen. This way, there should be no delay when toggling the visibility of the objects.

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

Using TypeORM to Retrieve Data from Many-to-Many Relationships with Special Attributes

Hey there, I'm diving into the world of TypeORM and could really use some guidance. I've been attempting to set up many-to-many relationships with custom properties following the instructions provided here However, I've run into a few iss ...

Optimal Strategy: Utilizing Spring Boot for Backend Development and jQuery for Frontend Interface

I am currently tackling a project that involves a Spring Boot 2 Backend and a jQuery Frontend. The frontend communicates with the backend by sending Ajax requests to Spring REST controllers in order to interact with database entities. One of the challenge ...

Troubleshooting problem with rotation and text geometry label on AxisHelper

Within my main scene, there is a sphere along with a subwindow located in the bottom right corner where I have displayed the (x,y,z) axis of the main scene. In this specific subwindow, I am aiming to label each axis as "X", "Y", and "Z" at the end of each ...

Tips on resolving the issue of an Axios post request not appearing in a get request in React

When using axios to make a post request in this code, a new username is posted, but there is an issue with retrieving the posted name from the API. How can I fix this problem to view my posted request? const App = () => { const [data, setData] = u ...

Generating unique font shapes with less detail in Three.js. Is the divisions parameter being neglected?

While reviewing the Font class documentation, I came across the mention of the "divisions" parameter for handling the fineness of the text shape generation. However, upon inspecting the implementation in the GitHub repository, it seems that this parameter ...

The Transition Division Is Malfunctioning

I've encountered an issue where I am trying to move a div by adjusting its left property, but no transition is taking place. Regardless of the changes I make to my code, the result remains the same. Below is the current state of the code. Can anyone i ...

The submit option fails to appear on the screen in the JsonForm library

I've been using the JsonForm library ( https://github.com/jsonform/jsonform ) to define a form in HTML. I have set up the schema and form of the JsonForm structure, but for some reason, the "onSubmit" function that should enable the send button is not ...

What steps can be taken to address the error message "FATAL: Unable to load template" encountered while using

I'm encountering the issues documented here and here on GitHub. I'm working on incorporating documentation for my Next.js code, and below is my jsdoc configuration file. { "tags": { "allowUnknownTags": true, "di ...

Using the code `$("img").one('load'` can trigger only a single load event without repetition

I have implemented the following function: function CheckImage(url, index) { $("<img/>").one('load', function () { $("div.photos").append(this); }).attr('src', url).attr('data-photo', '0' + ind ...

Trouble with Bootstrap modal implementation when using ajax and looping through data

I am having an issue with using the BS modal to display a form containing a select box and updating records in the database via an ajax call. The trigger button to open the modal consists of <i></i> tags with the same class name, itagbtn, and d ...

The scenario of two users simultaneously gaining control access in socket.io creating a race condition

There is a need to ensure that only one user at a time is notified for an available room. I am implementing a solution to prevent multiple users from being notified simultaneously for the same room. socket.on('Check', function (room) { io.in(r ...

Accessing a precise div element in a webpage

Currently, I am utilizing Vue.js and Nuxt for my web development. One issue I am facing is related to anchors. Specifically, when I navigate to mysite.com/page1#section1, I want the page to scroll to section1. In my code, I have the following snippet: < ...

What is the best approach to send data to the parent when closing $mdDialog?

When I open a Dialog Window, it has its own controller. Is there a way for me to modify data in the differentController that belongs to the Dialog Window and then send the modified data back to the parent controller when the dialog is being removed? fun ...

Reduce the number of redundant fields in MongoDB collections

I'm facing an issue with my model structure. Here is the schema: var accountSchema = new mongoose.Schema({ 'seeker': { 'fullName': String, 'ageGroup': String, 'education': String, ...

The presence of a backslash is preventing the state from transitioning to '/{username:[a-zA-Z0-9]{3,20}}' within the AngularJs UI-router

In my abstract root state named 'site', the empty URL ('') contains two child states: 'profile' and 'home'. The URL for home is '/', while the URL for profile is '/{username:[a-zA-Z0-9]{3,20}}'. I ...

What is the best way to ensure that a component remains the highest layer on a react-leaflet map?

I am encountering an issue where the table on my page only shows for a brief second when I refresh the page, and then it disappears. The Map Component being used is a react-leaflet map. I would like to have a component always displayed on top of the map wi ...

What is the best way to obtain a unique result for a single cell without encountering any duplicates when using the Angular

Currently, I have functional code that successfully passes data from a dialog window to a table. Everything works fine for a single row, but when I try to add multiple rows to the table, I get results for several columns simultaneously. Is there a way to o ...

worldpay implements the useTemplateForm callback function

My experience with implementing worldpay on my one-page Angular app (Angular 1.x) has been mostly positive. I have been using the useTemplateForm() method to generate a credit card form and retrieve a token successfully. However, I have encountered an issu ...

Encountered an unhandled promise rejection: TypeError - The Form is undefined in Angular 6 error

Whenever I attempt to call one .ts file from another using .Form, I encounter the following error: Uncaught (in promise): TypeError: this.Form is undefined The file that contains the error has imported the .ts file which I intend to pass values to. ...

Align images at the center of a division using the Bootstrap framework

I'm facing an issue with centering social network icons under a div in my login form while keeping it responsive. Can someone please assist me with this problem? Please help me!!. .row { background: #f8f9fa; margin-top: 20px; } .col { bor ...