Jump to content

Collision after mesh.bakeTransformIntoVertices()


Arte
 Share

Recommended Posts

Hi A!  Hey, thx for the mini tags-tutorial over in the other thread. (Thx to Tobi, too)

Umm... want some quick guesses? 

mesh.refreshBoundingInfo();

mesh.computeWorldMatrix(true);

I don't know what they do, but they sure look important.  :D

Might want to check mesh.showBoundingBox = true; 

Perhaps the boundingBox didn't make "the bake".  Maybe it got left behind.  If this gets more deeply puzzling, we might need to make a demo playground... show it happening.  That would be cool.  Talk soon.

Link to comment
Share on other sites

Yuh, yuh, yuh.  hmm. 

Before we go further, I want to say that the built-in collision system was initially created to test for cameras colliding with mesh, and NOT for mesh colliding with mesh.  (see note in source code). 

That said, this is still a puzzler.

I did a little testing... https://www.babylonjs-playground.com/#SN6DTF#4

This PG has the drag system removed, and uses a handy function called .moveWithCollisions().  It starts the movement after 4 seconds.

Same symptom as before.  When line 52 is active, collision fails. 

Let's beg to @Deltakosh to see if he has some hints for us.  Even though bakes work fine even when a mesh is not set updatable=true, I set greenBox updatable to true, just in case.  No change.  :)

Just for fun, I added an onCollideObservable up in line 26.  It is working.  Not sure if that is pertinent.  Just another one of my famous "feel around in the dark" testing methods.  :)

I'll keep thinking and testing... but I'm far from an expert.  An interesting find, Arte!  Thx for the report and playground.  Fellow helpers... you know... all comments/ideas welcome.

Link to comment
Share on other sites

Hey team!

BakeTransformIntoVertices will physically move vertices and after this call the mesh is considered at 0,0,0 (but with a pivot completely moved)

So the collision could not work anymore as it considers the mesh is centered on 0,0,0 (in object world) which is no more the case.

 

Does it make sense?

Link to comment
Share on other sites

@Wingnut My background is cad/cam technician ;). Thank you for trying.

@Deltakosh Can we recreate somehow? or just clone mesh before BakeTransformIntoVertices and reattach children's?

The reason for this:

I have so many problems with

parent.create..... 

child.create..... 

child.parent=parent  

child1.create..... 

child1.parent=child

child2.create..... 

child2.parent=child1 and ........

recalculate scale for every child is :o

Link to comment
Share on other sites

CAD/CAM?  Holy cow!  COOOOOOL!  Why am I talking... you're a darned genius in this stuff!  :)  I have probably SERIOUSLY embarrassed myself, but I guess that's not unusual at all.  heh. 

Thanks for info, Deltakosh.  I understand. 

Arte probably does, too, so far.  :) 

Neither of us LIKE that info, though.  heh.  Mesh.recreateCollider() might be interesting, if possible.  hmm.  Future thoughts.  Anyway...

https://www.babylonjs-playground.com/#SN6DTF#7  (#8 for spinning)

Wingy doing demented experiments... trying to use setPivotMatrix to reset the collider to geometry "center"... what we can call "green center".

I'm a little unsure-about WHAT is an origin, and WHAT is a pivot point... but it's all good fun.

Notice the onCollideObserver firing @ console... when pivot point hits blueBox?  It also shows a collide at first RUN.  Not sure why that is happening.

Play with line 24 at will... but wear a safety helmet and glasses... in case something pops.  :D  Bake is happening @ 25.  If you reverse the order of 24/25, then... oh I dunno... it all gets even MORE fun.  heh

Link to comment
Share on other sites

1 hour ago, Arte said:

I have so many problems with

parent.create..... 

child.create..... 

child.parent=parent  

child1.create..... 

child1.parent=child

child2.create..... 

child2.parent=child1 and ........

recalculate scale for every child is 

Not sure what it is you want your meshes to do but I know parenting and scaling can be a nightmare. However if you use BABYLON.MeshBuilder.Create...... instead of BABYLON.Mesh.Create.... you do not have to worry so much about scaling http://doc.babylonjs.com/tutorials/mesh_createxxx_methods_with_options_parameter as you can set sizes of mesh in their different dimensions.

perhaps these might be useful as well http://babylonjsguide.github.io/advanced/Pivots and http://babylonjsguide.github.io/advanced/Pivot

Depending on what it is you are actually trying to do there may be a way around it without using bakeTransformIntoVertices.

Link to comment
Share on other sites

Arte, are you going to need LIVE-adjusting?  Like... perhaps some + and - buttons that need to live-update cabinet width/height/depth?  Just curious.

WAY back... I made a parametric frame... similar to a 4-poster bed frame.

https://www.babylonjs-playground.com/#2GSAKE#2

(It's actually a Manned Mobility Unit / MMU for spacewalkers, but that's not important)

In lines 182-185, you can set those values to almost anything, and the frame will build correctly, with NO z-fighting-causing mesh-overlap, and no gaps between rail spans.

I was young, and was even a worse coder than I am now.  But still, I think this is a parameter-based structure.  I think the same techniques could be used for a cabinet.

Link to comment
Share on other sites

@Wingnut "are you going to need LIVE-adjusting?  Like... perhaps some + and - buttons that need to live-update cabinet width/height/depth?" Yes

Its not that difficult to create a parametric cabinet, but it is considerably harder to make live updates.

Link to comment
Share on other sites

2 hours ago, Arte said:

@JohnK I am trying to create parametric cabinet with components. Does it make sense?

Yes that makes sense. Do you want to use collisions for fitting shelves and draws?

30 minutes ago, Arte said:

@JohnK Thank you for links. I'm using BABYLON.MeshBuilder.CreateBox() to create parents, child's BABYLON.Mesh.CreateBox() .

 

Sorry for my English (its my 3rd language)

You have three languages wow! Personally I would be consistent and just use MeshBuilder, Mesh calls MeshBuilder anyway.

Link to comment
Share on other sites

7 hours ago, Pryme8 said:

I take it that means it worked?

Yes it works. I will tag as best answer :).

But I'm still looking for better solution. Every time I change the size I need to create new parent, I'm not happy with that.

 

I can see I'm not alone with "parenting and scaling can be a nightmare @JohnK". :huh:

I like "Just another one of my famous "feel around in the dark" testing methods @Wingnut". But in the day time I feel safe.;)

Yes that makes sense @Deltakosh 

Should we start new topic "How WE can improve parent and child relationship"?

 

Link to comment
Share on other sites

I think I see the issue but who knows? I don't think I would use parenting but would make up my own data structure (but then I like to make like difficult for myself)!

Consider a cupboard which is made up of a back, left-side, right-side, top, bottom and shelf each made from a box with width (x), height (y) and depth (z). Just to make life difficult the left and right sides are made up of panels which when though of as panels have a panel-width, panel-height and panel-thickness but when in position to form the cupboard the panel-width is depth (z), panel-height is height (y) and panel-thickness is width(x). The top, bottom and shelf panels are such that panel-width is width (x), panel-height is depth (z) and panel-thickness is height (y) and all these share panel-thickness. For the back panel-width is width (x), panel-height is height (y) and panel-thickness is depth (z) .

For simplicity imagine the origin is at the cupboard centre.

Now any left-right change moves the position of the left and right sides and scales only the width (x) of the top, bottom, shelf and back.

Any up-down change moves the position of the top and bottom panels and scales only the height (y) of the side panels and the back.

Any front-back change moves the position of the back panel and scales only the depth (z) of the side panels and the top, bottom and shelf panels.

So we take a action that matches change to what moves and what scales.

Here is a PG with a function that deals with changing width, something similar will do height and depth.

https://www.babylonjs-playground.com/#0MFGKW#1

Link to comment
Share on other sites

3 minutes ago, JohnK said:

Here is a version with parent. The parent is just to keep the pieces together.

NOTE the pieces are assigned the parent before they are positioned, ie immediately after creation - very important.

https://www.babylonjs-playground.com/#0MFGKW#2

Ho ho ho! You are my hero of the day :)

Almost there, just I need to play with recursive function for each child inside child. :D

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...