Jump to content

How to swap a mesh and retain position


vdheeraj
 Share

Recommended Posts

Hi,

Have render a bike model as show.

init.PNG.302d0692f7df56418cf2a64b2a284718.PNG

Few details regarding the model:

  1. Exported model from blender.
  2. All parts are under a parent mesh.

I want to swap the existing fuel tank with a new fuel tank.

Loading new mesh(fuel tank) using AssetsManager.

meshTask.onSuccess = function (task) {
           //Get current tank

          //Hide current tank 

          //Get current tank position using getAbsolutePosition()

         //Set position to new tank

         //Set new tank's parent

        //Show new tank
        }

Few details regarding new tank model:

  1. Exported model from blender.
  2. Has no parent.

But new tank is not in correct position.

swap.PNG.2e6edff3fc1729a350d5c65f897d697d.PNG

I can update the position manually(hard code) and get the following result.(Don't want to do this)

final.PNG.becce8582b28351465f7d8015f38acf6.PNG

Need to swap current mesh with new mesh and retain the position.

 

Link to comment
Share on other sites

On 4/22/2017 at 6:43 AM, vdheeraj said:

         //Set position to new tank

         //Set new tank's parent

Hi @vdheeraj, welcome to the forum.  Nice model/scene... pretty.  You did a well-explained post, too, thx.  Could you try a test for me?

Try reversing the order of those two lines.  Set tank's parent first, then set position gotten from previous tank.  Setting parent AFTER setting position... might accidentally over-ride your position setting. 

Report results, please.  Perhaps this will work.  I hope so, but if not, we'll try more ideas... if I can think of some.  :)

Link to comment
Share on other sites

Maybe try:

           //Get current tank

          //Hide current tank 

           // compute world matrix on current tank

          //Get current tank position using getAbsolutePosition()

           // set new tanks parent

           // set new tanks position using setAbsolutPosition()

Link to comment
Share on other sites

Hi @Wingnut and @Convergence thanks for the suggestions, but didn't resolve the issue.

However @Wingnut, while trying to resolve this, came across this post.

I'm doing something similar as mention in the post.

So instead of having 2 files (original bike and modified tank), combined both and layered them in blender and exported.(All meshes have single parent)

Load all the meshes upfront and toggle isVisible and setEnabled to show and hide mesh.

Was able to achieve this.

final_2.PNG.a12afcde3c058eff56b52615c7f4816e.PNG

Thanks @Wingnut, To quote you "you're just the coolest" .

And @Convergenceappreciate your help.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...