Duplicating objects in Forge Viewer

I have been attempting to duplicate an object within Forge Viewer. Despite my efforts using THREE.js to create a clone, the resulting structure does not match the original object.

sceneBuilder = viewer.loadExtension("Autodesk.Viewing.SceneBuilder");
let modelBuilder = await sceneBuilder.addNewModel({
    conserveMemory: false,
    modelNameOverride: `Custom model`,
  });

let renderProxy = viewer.impl.getRenderProxy(viewer.model, fragId);
let geom = new THREE.Geometry();
let VE = Autodesk.Viewing.Private.VertexEnumerator;
VE.enumMeshVertices(renderProxy.geometry, (v, i) => {
    geom.vertices.push(new THREE.Vector3(v.x, v.y, v.z));
  });

  VE.enumMeshIndices(renderProxy.geometry, (a, b, c) => {
    geom.faces.push(new THREE.Face3(a, b, c));
  });
geom.computeFaceNormals();
let mesh = new THREE.Mesh(
    new THREE.BufferGeometry().fromGeometry(geom),
    renderProxy.material
  );
(mesh as any).dbId = dbId;
modelBuilder.addMesh(mesh);

After discovering that renderProxy is also a THREE.Mesh, my attempt to clone it using

let clone = renderProxy.clone(); modelBuilder.addMesh(clone)
was unsuccessful. Is there a way to properly clone an object in Viewer?

Furthermore, when I add a mesh using modelBuilder, I notice that the created object is added to the browser tree, but I am still unable to utilize Viewer functions with it (such as

Viewer.select(dbId); Viewer.fitToView();
)

Answer №1

Simply copying the renderProxy won't likely be successful since the Forge Viewer tends to provide the same THREE.Mesh object each time you ask for a proxy, only with altered internal components for efficiency.

Opting for the code snippet that extracts vertices and faces from the proxy is a more reliable option. Have you tested this snippet yet, and does it work as intended or are there any glitches?

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

What could be causing my middleware to run twice?

A custom middleware was created in express.js/node.js to handle session checking. If a user ID is found in the session, it displays the user's menu; otherwise, it shows the default menu. For every page request, an ID check is performed and the user d ...

I am looking to remove identical innerText values from two arrays using JavaScript

Is it possible to use JavaScript to remove the "added" className of an element with the same innerText when the delete button (.btn-wrap>li>button) is clicked? <div class="table"> <ul> <li class="added">l ...

What could be the reason for the malfunction of the select (mongoose query)?

I'm trying to retrieve a User's highest score post. To accomplish this, I am querying the Post model and looking for posts where their user._id matches the author in the post. Everything is functioning correctly in this regard. However, my goal ...

Is there a Wordpress floating bar similar to the one seen on 9gag?

After browsing through some posts on stackoverflow, I noticed that my website is not responding as expected. You can check out my site here: To troubleshoot, you can examine the source code and utilize Firebug to inspect the css and javascript being used ...

Switch between showing excerpts and full content using Ajax Load More

Currently experimenting with the Infinite Scroll plugin, my goal is to display only excerpts initially, with the option to load the full content upon user click. The PHP code snippet: <div class="tenant"> <li<?php if (! has_post_thumbnail() ) ...

Error message: Encountered JavaScript heap out-of-memory error during Azure DevOps React Container Production Build

I am facing challenges in building a React production Docker container with Azure DevOps pipelines. Despite upgrading my build environment and code, the pipeline failed to run successfully. After conducting some research, I attempted to add the "--node-fla ...

Looking for a way to locate a string for a Boolean field in mongoDB?

I am dealing with a situation where I have a field name and criteria to search for in a collection. However, the types of fields I am working with vary, ranging from String to Number to Boolean. I attempted the following approach: const fieldName1 = &ap ...

Assign a class to an element depending on its position using JavaScript/jQuery

<ul> <li>Apple</li> <li>Banana</li> <li>Orange</li> </ul> How can I use jQuery to add a class to the second li element in the list without using an existing class or id? ...

On screens with smaller dimensions, the Material-UI AppBar buttons elegantly overlap to save space

I am facing an issue with my Appbar component where it displays properly on wide screens, as shown below: https://i.sstatic.net/Uz83x.png However, on smaller screens, the buttons overlap each other like this: https://i.sstatic.net/JnM6F.png Even aft ...

Issue with Express.js res.append function: Headers cannot be set after they have already been sent

I encountered an issue in my express project where I tried to set multiple cookies using "res.append" in the same request, but I kept getting an error saying "Error: Can't set headers after they are sent.". Can someone help me identify the problem and ...

"Utilizing the v-autocomplete component with on-select and on-remove events in Vuet

Are there any on-select or on-remove properties available in v-autocomplete from Vuetify? I need to manually handle these events. I have tried using @change, but it does not inform me whether an option has been added or removed. <v-autocomplete : ...

There was an issue with locating the module: Error: Unable to find the specified module 'vue-axios' in the directory 'C:xampphtdocsvue-laravel-api esourcesjs'

I am currently working on a CRUD project using Laravel and Vue.js. I made sure to install all the necessary devDependencies, but when I try running NPM run watch, I encounter the following error: https://i.sstatic.net/Kqkpq.png My app.js file includes all ...

HTML dynamic voting system

I'm new to coding in HTML and I have a specific challenge that I need help with. I want to display a value on my webpage that increases every time a user clicks a button. Below is the code I have written so far: <script type="text/javascript& ...

Ways to substitute the v-model pattern with react hooks

Transitioning my application from Vue to React. In Vue 2, using v-model on a component was similar to passing a value prop and emitting an input event. To change the prop or event names to something different in Vue, a model option needed to be added to t ...

C# implementation of the btoa function from JavaScript

I am in need of assistance recoding a JavaScript function to C# that makes use of the btoa method to convert a string of Unicode characters into base64. The challenge lies in ensuring that the encoding used in both languages is identical, as currently, the ...

Try out the Jquery Chosen plugin, which allows you to select multiple instances of the same

I am currently using the chosen plugin to create multiple select input fields. You can view an example of this in action by following this link: By default, the plugin disables an option if it has already been selected. For instance, in the provided examp ...

How can I ensure that the div remains fixed on scroll and appears directly below the navigation bar, rather than at the top of the page?

There is a div (#callback) that loads asynchronously via ajax upon submit, for updating or deleting an item. It appears as the green message box at the top of the page. Click here to see image and this is how it looks when "scrolling": Check out the scrol ...

Executing JavaScript code from an external HTML file

My goal is to create and utilize native web components by defining them as HTML files containing markup, CSS, and Javascript all bundled together in one file, similar to how Vue handles .vue files. These components would be fetched from an external compone ...

Code for refreshing content using AJAX

I'm looking for AJAX code to set a value in a session. For instance: $_SESSION['verif_code'] I want to generate a random number and assign it to this session. I need some AJAX code to refresh this random number function and set the value ...

Invoking a function within a functional component from a React element

Let's imagine a scenario where we have a Child component that is a functional component and contains a function called a(): export default function child({ ... }) { ... function a() { ... } ... } Now, let's introduce a parent ...