How to use the babylonjs.Vector3 function in babylonjs

To help you get started, we’ve selected a few babylonjs examples, based on popular ways it is used in public projects.

github cassieview / Build-First-Web-VR-Game-Absolute-Beginner / src / index.ts View on Github external
function createScene(): Scene {
    // Create scene
    var scene: Scene = new Scene(engine);
    var sphereLight = new DirectionalLight("dir02", new Vector3(0.2, -1, 0), scene);
    sphereLight.position = new Vector3(0, 80, 0);
    var gravityVector = new BABYLON.Vector3(0, -1, 0);
    scene.enablePhysics(gravityVector, new CannonJSPlugin);

    scene.clearColor = BABYLON.Color4.FromColor3(BABYLON.Color3.Black());

    var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -10), scene);
    //var camera = new BABYLON.UniversalCamera("UniversalCamera", new BABYLON.Vector3(0, 0, -10), scene);
    camera.checkCollisions = true;
    camera.applyGravity = true;
    // Targets the camera to a particular position. In this case the scene origin
    camera.setTarget(BABYLON.Vector3.Zero());

    // Attach the camera to the canvas
    camera.attachControl(canvas, true);

    var grassMaterial = new BABYLON.StandardMaterial("grass", scene);
github chad-autry / hex-grid-map-3D / src / HexBoard.js View on Github external
// And give it an ambient color
  board.scene.ambientColor = new babylon.Color3(0.3, 0.3, 0.3);
  // This creates and positions a free camera
  //var camera = new babylon.FreeCamera("camera1", new babylon.Vector3(0, 0, 1000), scene);
  //  Create an ArcRotateCamera aimed at 0,0,0, with no alpha, beta or radius, so be careful.  It will look broken.
  board.camera = new babylon.ArcRotateCamera(
    "ArcRotateCamera",
    0,
    0,
    0,
    babylon.Vector3.Zero(),
    board.scene
  );
  //Set up anti-aliasing (required in babylon.js 3.0+)
  board.postProcess = new babylon.FxaaPostProcess("fxaa", 1.0, board.camera);
  board.camera.upVector = new babylon.Vector3(0, 0, 1);

  board.camera.upperBetaLimit = Math.PI;
  board.camera.allowUpsideDown = true;

  //Make an invisible plane to hit test for the scene's X, Y co-ordinates (not the screens X, Y co-ordinates)
  board.pickerPlane = new babylon.Plane.FromPositionAndNormal(
    babylon.Vector3.Zero(),
    new babylon.Vector3(0, 0, 1)
  );

  //Initialize variables
  board.cameraTargetX = 0; //The X point on the Z = 0 plane the camera is pointed
  board.cameraTargetY = 0; //The Y point on the Z = 0 plane the camera is pointed

  board.cameraAlpha = Math.PI/4; //The camera angle above the XY plane
  board.cameraBeta = 0; //The camera angle rotated around the Z axis
github wanadev / holes-in / debug / js / debugger3d.js View on Github external
createScene(engine,canvas) {
      const camera = new BABYLON.ArcRotateCamera("camera1",0, 0, 200,new BABYLON.Vector3(0,0,0), debugger3d.scene);
      camera.radius = 200;
      camera.setTarget(new BABYLON.Vector3(0,0,0));
      camera.attachControl(canvas, false);
      debugger3d.camera= camera;

      var light1 = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(1,1,1), debugger3d.scene);
      var light2 = new BABYLON.HemisphericLight('light2', new BABYLON.Vector3(-1,-1,0), debugger3d.scene);

      light1.diffuse = new BABYLON.Color3(1, 1, 1);
      light1.specular = new BABYLON.Color3(1, 1, 1);

      light2.diffuse = new BABYLON.Color3(1, 1, 1);
      light2.specular = new BABYLON.Color3(1, 1, 1);

      debugger3d.scene.clearColor = new BABYLON.Color3(0.3,0.3,0.3);
github mishig25 / 3d-posenet / graphics.js View on Github external
setCamera(){
        const camera = new BABYLON.ArcRotateCamera("camera", 0, 1, 20, BABYLON.Vector3.Zero(), this.scene);
        camera.setTarget(new BABYLON.Vector3(0, 4, 0));
        camera.setPosition(new BABYLON.Vector3(0, 6, 12))
        camera.attachControl(this.canvas, true);
        const light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), this.scene);
        light.intensity = 0.7;
        return camera;
    }
github brianzinn / create-react-app-babylonjs / src / ScaledModelWithProgress.js View on Github external
position={this.props.center}
                    rootUrl={this.props.rootUrl}
                    sceneFilename={this.props.sceneFilename}
                    pluginExtension={this.props.fileExtension}
                    rotation={this.props.modelRotation}
                />
                {(this.state.loadProgress < 1) &&
                    <Mesh rotation={this.props.progressRotation} position={this.props.center}>
                        <Box key="progress" name="boxProgress" height={this.props.scaleTo/15} width={this.props.scaleTo} depth={this.props.scaleTo/30} scaling={new Vector3(this.state.loadProgress, 1, 1)}
                            position={new Vector3(this.props.scaleTo / 2, 0, this.props.scaleTo/60)}
                            setPivotMatrix={ [ Matrix.Translation(-this.props.scaleTo, 0, 0) ] }
                            setPreTransformMatrix={ [ Matrix.Translation(-this.props.scaleTo / 2, 0, 0) ] }>
                            <StandardMaterial diffuseColor={this.props.progressBarColor} specularColor={Color3.Black()} />
                        </Box>
                        <Box key="back" name="boxBack" height={this.props.scaleTo/15} width={this.props.scaleTo} depth={this.props.scaleTo/30}
                            position={new Vector3(0, 0, this.props.scaleTo/-60)}
                        />
                    </Mesh>
                }
            </React.Fragment>
        )
    }
}
github BabylonJS / Editor / src / extensions / behavior / nodes / list / utils.ts View on Github external
registerNode({ name: 'Vector Merger', description: 'Exposes the XYZW properties to merge into 2d, 3d or 4d vectors.', path: 'utils/vectormerger', ctor: Object, functionRef: (node) => {
        node.store.vector2 = node.store.vector2 || new Vector2(0, 0);
        node.store.vector3 = node.store.vector3 || new Vector3(0, 0, 0);
        node.store.vector4 = node.store.vector4 || new Vector4(0, 0, 0, 0);

        node.store.vector2.x = node.store.vector3.x = node.store.vector4.x = node.getInputData(0);
        node.store.vector2.y = node.store.vector3.y = node.store.vector4.y = node.getInputData(1);
        node.store.vector3.z = node.store.vector4.z = node.getInputData(2);
        node.store.vector4.w = node.getInputData(3);

        node.setOutputData(1, node.store.vector3.asArray());
        node.setOutputData(2, node.store.vector4.asArray());

        return node.store.vector2;
    }, inputs: [
        { name: 'x', type: 'number' },
github j-o-d-o / multiplayer-babylon-js-game / server / src / objects / area.ts View on Github external
let plane = Mesh.CreateGround("ground1", 460, 460, 2, this.scene);
        this.mesh.push(plane); 

        let centerObj = Mesh.CreateBox("object", 40, this.scene);
        centerObj.position.y = -17;
        this.mesh.push(centerObj);

        let wall_top: Mesh = MeshBuilder.CreateBox("wall_top", {width: 460, height: 20, depth: 20}, this.scene);
        let wall_bottom: Mesh = wall_top.clone("wall_bottom");
        let wall_left: Mesh = wall_top.clone("wall_left");
        let wall_right: Mesh = wall_top.clone("wall_right");
        wall_top.position.z = 230;
        wall_bottom.position.z = -230;
        wall_left.rotate(new Vector3(0, 1, 0), Math.PI / 2)
        wall_left.position.x = 230;
        wall_right.rotate(new Vector3(0, 1, 0), Math.PI / 2);
        wall_right.position.x = -230;
        this.mesh.push(wall_top);
        this.mesh.push(wall_bottom);
        this.mesh.push(wall_left);
        this.mesh.push(wall_right);

        this.mesh.forEach(element => {
            element.physicsImpostor = new PhysicsImpostor(
                element, 
                PhysicsImpostor.BoxImpostor,
                { 
                    mass: 0, 
                    restitution: 0.3,
                    friction: 100
            }, this.scene);
        });
github chad-autry / hex-grid-map-3D / src / contexts / GridContext.js View on Github external
module.exports.prototype.createPartialMesh = function(scene) {
  //Create tubes for 3 sides of a hex

  var zeroZeroPixelCoordinates = this.hexDimensions.getPixelCoordinates(0, 0);
  //The first point of each line is the lower "junction" point of the point up hexagon

  //Draw the vertical line first
  var vertical = babylon.Mesh.CreateTube(
    "vertical",
    [
      new babylon.Vector3(
        zeroZeroPixelCoordinates.x,
        zeroZeroPixelCoordinates.y + this.hexDimensions.hexagon_half_wide_width,
        0
      ),
      new babylon.Vector3(
        zeroZeroPixelCoordinates.x,
        zeroZeroPixelCoordinates.y +
          this.hexDimensions.hexagon_half_wide_width +
          2 * this.hexDimensions.hexagon_scaled_half_edge_size,
        0
      )
    ],
    2,
    20,
    null,
    0,
    scene
  );

  //Next the bottom right line
  var bottomRight = babylon.Mesh.CreateTube(
github chad-autry / hex-grid-map-3D / src / meshFactories / UpdateableVectorMeshFactory.js View on Github external
)
    ) *
    180 /
    Math.PI;
  if (normalizedPixelCoordinates.y < 0) {
    angle = -angle;
  }

  //Cap the vector
  var joint = babylon.Mesh.CreateSphere("sphere", 20, item.shaftWidth, scene);

  //Draw it pointing straight on y = 0
  var vector = babylon.Mesh.CreateTube(
    "tube",
    [
      new babylon.Vector3(0, 0, 0),
      new babylon.Vector3(magnitude - item.shaftWidth, 0, 0),
      new babylon.Vector3(magnitude - item.shaftWidth, 0, 0),
      new babylon.Vector3(magnitude, 0, 0)
    ],
    null,
    20,
    function(i) {
      if (i === 0 || i === 1) {
        return item.shaftWidth / 2;
      } else if (i === 2) {
        return item.shaftWidth * 1.5;
      } else {
        return 0;
      }
    },
    0,