Updating materials within the Forge

Currently, we have implemented a system where the client retrieves object states when the page loads, changing the colors of 'pending' objects in the model. We continue to poll for changes to update the coloring - initially coloring pending objects upon viewer load and then checking and updating state periodically to render them in different colors while storing their original color/material. If a change is detected that an object should no longer be colored, we instruct Forge to revert to the old color/material.

The Issue: We have identified the problem but are struggling to find a solution. The issue lies in the fact that changing materials in Forge only works within the first few seconds after startup (materials were used to display colors).

However, setting overlays continues to work even after the initial ~3 seconds, showing overlays instead of materials to represent colors. This is suboptimal as overlays may appear over everything.

Materials appear to be 'locked' after the initial ~3 seconds, prohibiting further changes or updates. It seems like they are not being refreshed properly.

In some examples, using viewer.impl.invalidate(true) was suggested to refresh the Forge viewer, but this approach ceases to be effective after the initial ~3 seconds.

We have attempted various combinations of

viewer.impl.invalidate(true, true, true)
, setting material.needsUpdate to true, and trying to re-render the entire scene without success.

We also came across this GitHub issue, although implementing similar fixes in Forge proves challenging. Even using viewer.requestSilentRender() did not yield results.

To better understand the situation, here is all the necessary code: DROPBOX LINK

Furthermore, here is a snippet from the index.html file defining color settings:

try
{
   viewer.restoreAllColorOverlays(); //to use materials instead of overlays: viewer.restoreAllColorMaterials();
   $.each(colors, function(color, selectionIds)
   {
      viewer.setColorOverlay(selectionIds, color); //to use materials instead of overlays: viewer.setColorMaterial(selectionIds, color);
   });
}
catch(error)
{
   console.error(error);
}

Answer №1

As I do not have insight into the implementation of your app, my observations are based solely on the code provided. To address the issue you mentioned, it would be helpful to showcase a reproducible case for our development team's review. If sharing the reproducible case publicly is not possible, please feel free to send it to this email address: [email protected] after removing any sensitive information.


A finding in your code:

Upon inspection, I noticed incorrect types and missing actions in your ColorMaterial extension. The color property of a material should be of type THREE.Color. I have provided a modified version below:

Autodesk.Viewing.Viewer3D.prototype.setColorMaterial = function(objectIds, color)
    {
        if( !(color instanceof THREE.Color) ) throw 'Invalid argument: Color';
 
        var material = new THREE.MeshPhongMaterial
        ({
             color:      color,
             opacity:    0.8,
             transparent: true
         });

        viewer.impl.matman().addMaterial( 'ColorMaterial-' + new Date().getTime(), material, true );

        // ...........
    };

The updated result can be seen here:

https://i.sstatic.net/fsWv9.jpg

In the ColorOverlay extension, there are also issues with the type of material color property, which should be of type THREE.Color. Making this adjustment and including the viewer.hide() method along with setColorOverlay() will ensure that the overlay appears as a transparent object covering the 3D objects.

Without hiding the 3D object of the wall:

https://i.sstatic.net/aOBgP.jpg

Hiding the 3D object of the wall:

https://i.sstatic.net/4ChaA.jpg

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

"Facing an issue with Google Chrome not refreshing the latest options in an HTML select dropdown list

Having trouble creating an offline HTML file that incorporates jQuery for the script. The page features a state select menu followed by a second menu for counties. When a state is selected, only the corresponding counties should display while others remai ...

Are instance prototypes exhibiting static behavior?

I'm in the process of creating a game for Windows 8 using HTML/Javascript and WinJS, but I'm running into issues with "prototypes" acting statically when they shouldn't. This is my first time working extensively with Javascript and dealing w ...

Activate dual AJAX JSON and cycle through multiple alerts each time an "ul li" element is clicked

In my code, I am utilizing two ajax requests. One retrieves a chat userlist column in JSON format, while the other fetches the message history for each user. The functionality works such that when a $('.member_list ul li') element is clicked, th ...

Are you experiencing problems with JSON formatting?

Currently, I am facing an issue with populating an HTML table using JSON data. The problem arises when I try to populate the table with the JSON data that was provided to me. After careful examination, I suspect that the issue might lie in the formatting o ...

Tips for implementing Animation.css in Angular version 1.5.8

I have successfully added the ngAnimate dependency to my AngularJS project: var app=angular.module('testApp',['ngRoute', 'ngAnimate']); I have also included the animation classes in my animation.css file: .slide-animation.n ...

What are the key distinctions between DOCS and PSD base64 URLs?

My current challenge involves displaying a preview of attachments. I want to show an IMAGE SVG preview for image attachments and a PDF preview for PDF attachments, both based on their respective base64 formats. For example, I am currently using the split m ...

Dim the background for all elements except for one

Seeking a way to create a dimmed-background effect by adjusting the opacity of all elements on the page except for one specific element. I've experimented with using the :not() selector as well as jQuery selectors to exclude certain elements, but have ...

Using NodeJS with the Express framework to send a GET request

Can express be used as a client-module for making http-requests to another server? Currently, I'm handling requests like this: var req = http.get({host, path}, function(res) { res.on('data', function(chunk) { .... } } This ...

I am trying to locate the source of the unexpected token error

Hi there! I've encountered a syntax error in my code, specifically pointing to the closing curly bracket right above the render method. The error message indicates that it's expecting a comma, but all my curly brackets seem to have opening and cl ...

Encountering difficulty in adding content to a table using JavaScript. An error message appears stating that assignment to a function

I am utilizing ajax to retrieve an item from a web API, and then attempting to allocate attributes of that item to a table: function find() { var id = $('#contentID').val(); $.getJSON(uri + '/' + id) .done( ...

Storing Firestore Timestamp as a Map in the database

Snippet Below const start = new Date(this.date + 'T' + this.time); console.log(start); // Thu Sep 12 2019 04:00:00 GMT+0200 const tournament:Tournament = { start: firebase.firestore.Timestamp.fromDate(start) } When passing the tournament ...

Production Server experiencing issues with sending Large Lists via Http Post

I'm experiencing an issue where the server is unable to read values from a large list when sent using Post. Oddly enough, this works on the homologation server but not on the production server. Http post AngularJs $http({ url: $rootScope.raiz_ws ...

I am having trouble unzipping the file

I encountered an issue while attempting to download a .zip file from Discord and extracting it using the decompress package. Despite not returning any errors, the package did not get extracted as expected. (The file was saved and downloaded correctly) co ...

The FormData() object in Django backend is consistently found to be void of any data

I am currently experimenting with uploading an HTML form through AJAX using pure JavaScript, without jQuery. The form is put together in my template by combining three components: the CSRF token, a ModelForm, and a regular Django form (forms.Form). The vis ...

Is it possible to retrieve browser history from Google Chrome using Node.js on a Windows operating system?

I'm currently developing a personal electron app for managing my lifestyle. One of the key features is controlling my daily internet browsing through the app. I am aiming to integrate my Chrome history into the electron app. Could someone recommend a ...

Is it possible to reveal a concealed element or modify the functionality of a hyperlink?

I have a link in the navigation that includes an animated icon of a + turning into an x. When the icon is in the x state, I want users to be able to close it by clicking on the icon or text. However, I am unsure of the best way to approach this. One op ...

Can Angular Universal SSR be activated specifically for Googlebot User Agents?

I am aiming to activate Angular Universal SSR only when the User Agent is identified as Googlebot. However, I am uncertain about how to instruct Angular Universal SSR to deliver server side rendered HTML exclusively if the User Agent is Googlebot. server ...

Utilizing JavaScript: Storing the output of functions in variables

Currently in the process of learning JavaScript and aiming to grasp this concept. Analyzed the following code snippet: function multiNum(x, y){ return x * y; } var num = multiNum(3, 4); document.write(num); Decided to try it out on my own, here's ...

What steps can be taken to solve the JavaScript error provided below?

My objective is to create a new variable called theRightSide that points to the right side div. var theRightSide = document.getElementById("rightSide"); Once all the images are added to the leftSide div, I need to use cloneNode(true) to copy the left ...

Ramda Transitioning to a Liberated Style of Programming

Unable to find a suitable resource for this particular issue. I apologize if this question has already been asked, but my attempts to locate the answer have proven fruitless (perhaps due to a lack of effective search methods). I've developed a functi ...