Feature or bug? in javascript or babylon?

I have two questions; the behavior surprised me:

1 ) Taking code directly from the documentation, the PLAYGROUND does not like

BABYLON.Mesh.CreateBox

It draws a line through CreateBox (although it seems to run it).

What is the “correct” way to make a box? A? B? or other?

A)
const box = BABYLON.MeshBuilder.CreateBox(“box”, options, scene);

B)
const box = BABYLON.Mesh.CreateBox(“box”, size, scene);

  1. When the position of a box is (a,b,c)

and there is a

var D = ;
D.position = box.position;

then if D.position changes, box.position changes. The “=” sign is not an assignment, it identifies the position of the box with the position of D.

Is that how it is supposed to work?

Here’s a playground showing (1) and (2):

What is the “correct” way to make a box? A? B? or other?

A is the new way of creating a box instance. B is deprecated, thus you see the striking through line on the PG editor.

THE TWO BOXES SHOULD BE VERTICALLY ALIGNED. WHY DOES CHANGING THE POSITION OF SPHERE CHANGE THE POSITION OF BOX1 ?

    sphere.position = box1.position;

This assigns reference to box1’s position to sphere.position. They refer to the same Vector3 instance. You need to make a copy of box1’s position:

sphere.position = new BABYLON.Vector3().copyFrom(box1.position);

See https://playground.babylonjs.com/#WIR77Z#1225

3 Likes