Adjust the position of the model in the Forge viewer after applying a

After utilizing the Model transformation extension to relocate the model, I am now seeking ways to retrieve the updated location or coordinates of the transformed model. Despite querying the bounding box min and max points, they seem to remain constant. Any suggestions on how to achieve this? My goal is to determine the new position of the model in relation to the origin post-translation.

Answer №1

After isolating the core section of that extension, I carefully examined the position and bounding box before and after the transformation process. Specifically focusing on translation only, it appears that these values are indeed updated post-transformation. Perhaps this approach could assist in diagnosing your issue?

To test this theory, simply select one object and execute the function as follows:

retrieveTransformedBoundingBox (fragIds, fragList) {

   const fragbBox = new THREE.Box3()
   const nodebBox = new THREE.Box3()

  fragIds.forEach(function(fragId) {

     fragList.getWorldBounds(fragId, fragbBox)

     nodebBox.union(fragbBox)
  })

  return nodebBox
}

 $('#test').click(function(rt){

        var dbids = NOP_VIEWER.getSelection();
        var it = NOP_VIEWER.model.getData().instanceTree;
        var fragList = NOP_VIEWER.model.getFragmentList();  

        fragIds = [];

        it.enumNodeFragments(dbids[0], function(fragId) {
            fragIds.push(fragId); 
        }, false);

        var bb = retrieveTransformedBoundingBox(fragIds,fragList);
        console.log('boundingbox pre-transformation: [max,min]: ' + 
        bb.max.x + ' ' + bb.max.y + ' ' + bb.max.z + '\n'+ 
        bb.min.x + ' ' + bb.min.y + ' ' + bb.min.z ); 

        fragIds.forEach(function(fragId){ 

            var fragProxy = NOP_VIEWER.impl.getFragmentProxy(
            NOP_VIEWER.model,
            fragId)

            fragProxy.getAnimTransform()

            console.log('fragment position in LCS prior to transform:' + 
                            fragProxy.position.x + ','+
                            fragProxy.position.y + ','+ 
                            fragProxy.position.z);

            var wcsMatrix = new THREE.Matrix4(); 
            fragProxy.getWorldMatrix(wcsMatrix);
            var wcsPos = wcsMatrix.getPosition();
            console.log('fragment position in wcs matrix before transformation: ' + 
            wcsPos.x + ' ' + wcsPos.y + ' ' + wcsPos.z);


            fragProxy.position.x += 10; 
            fragProxy.position.y += 10; 
            fragProxy.position.z += 10;   

            fragProxy.updateAnimTransform()  
        }); 
        NOP_VIEWER.impl.sceneUpdated(true) 


        fragIds.forEach(function(fragId){ 

            var fragProxy = NOP_VIEWER.impl.getFragmentProxy(
            NOP_VIEWER.model,
            fragId)

            fragProxy.getAnimTransform()

            console.log('fragment position in LCS after transformation:' + 
                            fragProxy.position.x + ','+
                            fragProxy.position.y + ','+ 
                            fragProxy.position.z); 

            var wcsMatrix = new THREE.Matrix4(); 
            fragProxy.getWorldMatrix(wcsMatrix);
            var wcsPos = wcsMatrix.getPosition();
            console.log('fragment position in wcs matrix after transformation: ' + 
            wcsPos.x + ' ' + wcsPos.y + ' ' + wcsPos.z);
        }); 

        bb = retrieveTransformedBoundingBox(fragIds,fragList);
        console.log('boundingbox post-transformation: [max,min]: ' + 
        bb.max.x + ' ' + bb.max.y + ' ' + bb.max.z + '\n'+ 
        bb.min.x + ' ' + bb.min.y + ' ' + bb.min.z ); 

    });

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

Merging two distinct arrays of objects in JavaScript can be achieved by utilizing various methods and

I have a challenge where I need to merge two arrays of objects in a nested way. var array1=[{ PersonalID: '11', qusetionNumber: '1', value: 'Something' }, { PersonalID: '12', qusetionNumber: '2& ...

Add an element to an array using the `push` method in JavaScript

I am currently studying the code for creating a canvas circle motion trail effect. I am a bit puzzled by the push(x:Pos,y:Pos) within thestoreLastPosition() function in the sample code provided below: ctx = canvas.getContext('2d'); var xPos = - ...

If a div element includes a specific text, then update that portion of the text without altering the value of any variables

Need help removing text without affecting variables Attempting to translate a specific line with JQuery Looking to change text only, leaving the content within the strong tag intact $('.content-box__row div:nth-child(3)').text('') ...

Display error page when unable to load ng-view template

Is there a way to display a standard error page or template if a certain template cannot be loaded using ngRoute in Angular? I've come across suggestions that subscribing to the $routeChangeError event might help, but I'm not sure what steps to ...

Printing in HTML is limited to only one page

While printing an HTML table that can vary in length, I often encounter the issue of it printing multiple pages. Is there a way to limit the printing to just one page through coding? Yes, you can achieve this by using the option in the browser print dialog ...

refreshing the webpage with information from an API request

I am completely new to web development, so please bear with me. I am attempting to make a simple API call: const getWorldTotal = async () => { const response = await fetch('https://cors-anywhere.herokuapp.com/https://health-api.com/api/v1/cov ...

Counting and Arranging Numerous Commitments in the World of Javascript

I’m faced with a challenging scenario that’s got me puzzled: -I’ve got an array of 10 objects, each with two properties: IDNum and imageURL. -Only 3 of these objects actually have their imageURL property set (at index positions [0, 4, 9]), and n ...

Assistance needed with implementing jQuery tabs

I'm looking to add a link that takes me directly to content within a non-default tab on another page. Here's the code snippet that explains what I need: My Code: This is from my profile_edit.php page: The javascript: <script src="Javascrip ...

Implementing XHR progress events for texture loading in Three.js

In the latest version of Three.js (R84), textures are loaded using image tags, which unfortunately do not have support for onProgress events. This means that while it is possible to track how many files have been loaded, there is no way to retrieve detaile ...

Is there a way to incorporate innerhtml (or innertext) with the h() function for adding content?

Due to certain requirements, I need to utilize virtual DOM. Below is the code snippet that I am working with: // test.js import { h, ref } from 'vue' const ButtonCounter = { name: 'button-counter', props: { tag: { type: S ...

Can JavaScript be used to save data to a file on a disk?

As a beginner to intermediate programmer exploring AJAX, I was intrigued while learning about JavaScript. It caught my attention that many examples I have come across incorporate PHP for this task. While some may say 'I'm going about it the wrong ...

What is the best way to reset the state to null when the input field is blank?

After setting some inputs with a state of null, I noticed that when the end-user types something and then deletes it all, the input reverts back to an empty string. How can I adjust the state so that it returns to null? I seem to be encountering an issue ...

Transforming the value of a property in a JSON object using JavaScript

I have a JSON object that I am trying to manipulate by changing the value of its property "quantity" "[{"name":"Butter","image":"/static/images/items/dairy/butter.jpg", "price":" 30 uah","quantity":"1","alias":"butter"}, {"name":"Chesse","image":"/stat ...

Utilizing Vue.js to ensure that nested components remain within the parent component even when the store

I have been working on a chat messaging system, where I initially populate the store with root messages and then map the state of that list (array). Everything works fine when posting a new message - the store updates and displays the new post. However, I ...

The vertical timeline feature in React does not appear to be displaying properly on the web browser

import { VerticalTimeline, VerticalTimelineElement } from "react-vertical-timeline-component" import { motion } from "framer-motion" import 'react-vertical-timeline-component/style.min.css'; import {styles} from '../styl ...

What seems to be the issue with this 3D array not functioning properly?

Game Code Overview The following code pertains to a grid-based game that I am currently developing, primarily for educational purposes. This game is played on an 8 x 8 grid where the player navigates from one cell to another while encountering obstacles s ...

Nodejs application crashes due to buffer creation issues

router.post('/image', multipartMiddleware , function(req, res) { var file_name = req.body.name; var data = req.body.data; var stream = fs.createReadStream(data); //issue arises here return s3fsImpl.writeFile(file_name , stream).t ...

Tracking User IDs across different domains with Piwik: a step-by-step guide using PHP and JavaScript

Is there a way to connect the IP address of the current visitor to a specific user ID using PHP in Piwik tracking, and ensure this connection is maintained across multiple (sub)domains? I have multiple (sub)domains and I want to assign a unique UserID to ...

Use the $router.push method to pass an entire object as a parameter

I am attempting to utilize the $router.push method in order to transfer data from one view to another. Below is an excerpt of the code: let obj = { foo: 'f1', foo2: ['f2'], foo3: { foo4: [], foo5: new Map(), ...

I did not anticipate the React setState function to behave in the manner it did

While working on form validation for my page, I came across a tutorial showcasing a validation method that seems to be functioning correctly. However, there is one aspect that I am struggling to grasp. The tutorial suggests declaring a variable before the ...