How to use the babylonjs.Vector3.Zero 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 j-o-d-o / multiplayer-babylon-js-game / server / src / world.ts View on Github external
public init() {
        // Not sure why a camera is needed on the server side...
        var camera = new ArcRotateCamera("Camera", 0, 0.8, 100, Vector3.Zero(), this.scene);

        // Important to first enable physics before creating any mesh
        const OIMO = require("oimo");
        this.scene.enablePhysics(new Vector3(0, -20, 0), new OimoJSPlugin(undefined, OIMO));

        // Creat mesh objects
        this.area.init();

        this.scene.executeWhenReady(() => {
            this.engine.runRenderLoop(() => {
                this.scene.render();
            });

            // Update to clients in fixed interval
            setInterval(() => {
                Object.keys(this.playerObjs).forEach((key) => {
github BabylonJS / Editor / src / editor / edition-tools / sound-tool.ts View on Github external
protected resetToOriginal (): void {
        const m = this.object['metadata'].original;
        
        // Common
        this.object.loop = m.loop;
        this.object.setVolume(m.volume);
        this.object.rolloffFactor = m.rolloffFactor;
        this.object.setPlaybackRate(m.playbackRate);
        this.object.spatialSound = m.spatialSound;

        // Spatial
        if (!m.connectedMeshId) {
            this.object.detachFromMesh();
            this.object.setPosition(Vector3.Zero());
            this.editor.graph.setParent(this.object['id'], this.editor.graph.root);
        } else {
            const mesh = this.editor.core.scene.getMeshByID(m.connectedMeshId);
            if (mesh) {
                this.object.attachToMesh(mesh);
                this.object.setPosition(Vector3.FromArray(m.position));
                this.editor.graph.setParent(this.object['id'], mesh.id);
            }
        }

        // Update
        setTimeout(() => {
            Tags.RemoveTagsFrom(this.object, 'modified');
            this.editor.graph.updateObjectMark(this.object);
        }, 1);
github BabylonJS / Editor / src / editor / edition-tools / sound-tool.ts View on Github external
import { Sound, Vector3, Tags } from 'babylonjs';

import AbstractEditionTool from './edition-tool';
import Tools from '../tools/tools';
import Picker from '../gui/picker';

export default class SoundTool extends AbstractEditionTool<Sound> {
    // Public members
    public divId: string = 'SOUND-TOOL';
    public tabName: string = 'Sound';

    // Private members
    private _volume: number = 0;
    private _playbackRate: number = 0;
    private _rolloffFactor: number = 0;
    private _position: Vector3 = Vector3.Zero();
    private _time: number = 0;

	/**
	* Returns if the object is supported
	* @param object the object selected in the graph
	*/
    public isSupported(object: any): boolean {
        return object instanceof Sound;
    }

	/**
	* Updates the edition tool
	* @param object the object selected in the graph
	*/
    public update(sound: Sound): void {
        super.update(sound);
github BabylonJS / Editor / src / editor / prefabs / helpers.ts View on Github external
public static async CreatePreview (d: AssetElement<Prefab>, engine: Engine): Promise<void> {
        const serialization = SceneSerializer.SerializeMesh(d.data.sourceMesh, false, true);
        const file = Tools.CreateFile(Tools.ConvertStringToUInt8Array(JSON.stringify(serialization)), d.name + '.babylon');
        const canvas = engine.getRenderingCanvas();

        const scene = new Scene(engine);
        scene.clearColor.set(0, 0, 0, 1);

        const camera = new FreeCamera('PrefabAssetCamera', Vector3.Zero(), scene);
        const light = new PointLight('PrefabAssetLight', Vector3.Zero(), scene);

        await SceneLoader.AppendAsync('file:', file, scene, () => engine.hideLoadingUI());
        await new Promise<void>((resolve) => {
            engine.runRenderLoop(() => {
                scene.render();
                
                if (scene.getWaitingItemsCount() === 0) {
                    // Find camera position
                    let boundingInfo = d.data.sourceMesh.getBoundingInfo();
                    const descendants = d.data.sourceMesh.getDescendants();

                    descendants.forEach(d => {
                        if (!(d instanceof AbstractMesh))
                            return;
                        
                        d.getBoundingInfo().update(d.getWorldMatrix());
github springtype-org / springtype / src / packages / cli / springtype / template / project / babylon-3d / src / component / first-scene / first-scene.tsx View on Github external
private createCamera() {
        this.camera = new ArcRotateCamera("Camera", 0, Math.PI / 2, 12, Vector3.Zero(), this.scene);
        this.camera.attachControl(this, false);

        this.camera.lowerRadiusLimit = 6;
        this.camera.upperRadiusLimit = 6;
        this.camera.minZ = 1;
    }
github springtype-org / springtype / src / packages / cli / springtype / template / project / babylon-3d / src / component / first-scene / first-scene.tsx View on Github external
vertex: "custom",
                fragment: "custom",
            },
            {
                attributes: ["position", "normal", "uv"],
                uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"]
            });

        const mesh = Mesh.CreatePlane("mesh", 10.0, this.scene);
        mesh.rotate(Axis.Y, Math.PI * .5);

        const refTexture = new Texture("http://i.imgur.com/HP1V7TJ.png", this.scene);

        shaderMaterial.setTexture("refSampler", refTexture);
        shaderMaterial.setFloat("time", 0);
        shaderMaterial.setVector3("cameraPosition", Vector3.Zero());

        shaderMaterial.backFaceCulling = false;

        mesh.material = shaderMaterial;

        let time = 0;

        this.scene.registerBeforeRender(() => {

            shaderMaterial.setFloat("time", time);
            time += 0.02;

            shaderMaterial.setVector3("cameraPosition", this.scene.activeCamera!.position);
        });
    }
}
github brianzinn / create-react-app-babylonjs / src / withModel.js View on Github external
return (
      <div>
        <div className="row">
          <div className="col-xs-3 col-lg-3 align-top">'pointer over' boombox to see mesh</div>
          <div className="col-xs-3 col-lg-3 align-top">
            Move Avocado: 
            <Button onClick={this.moveAvocadoUp}><Octicon icon={ArrowUp}/></Button>
            &nbsp;&nbsp;
            <Button onClick={this.moveAvocadoDown}><Octicon icon={ArrowDown}/></Button>
          </div>
        </div>
        <div className="row">
          <div className="col-xs-12 col-md-6">
            <Engine antialias={true} adaptToDeviceRatio={true} canvasId="sample-canvas">
              <Scene>
                <ArcRotateCamera name="camera1" alpha={Math.PI / 2} beta={Math.PI / 2} radius={9.0} target={Vector3.Zero()} minZ={0.001} />
                <HemisphericLight name="light1" intensity={0.7} direction={Vector3.Up()} />
                
                <ScaledModelWithProgress rootUrl={`${baseUrl}BoomBox/glTF/`} sceneFilename="BoomBox.gltf" scaleTo={3} 
                  progressBarColor={Color3.FromInts(255, 165, 0)} center={new Vector3(2.5, 0, 0)}
                  onModelLoaded={this.onModelLoaded}
                />

                <ScaledModelWithProgress rootUrl={`${baseUrl}Avocado/glTF/`} sceneFilename="Avocado.gltf" scaleTo={this.state.avocadoScaling} 
                  progressBarColor={Color3.FromInts(255, 165, 0)} center={new Vector3(-2.5, this.state.avocadoYPos, 0)}
                />
              </Scene>
            </Engine>
          </div>
          <div className="col-xs-12 col-md-6">
            <pre>
                <PrismCode className="language-jsx">
github prateekbh / hopon / game / GameScene.js View on Github external
addCamera() {
    this._camera = new FreeCamera(
      'FreeCamera',
      new Vector3(0, 4, -24),
      this.scene
    );
    this._camera.setTarget(new Vector3(0, 1, 0));
    this._camera.inputs.attached.mouse.detachControl();
    this._camera.setTarget(Vector3.Zero());
  }
github springtype-org / springtype / e2e / babylon-3d / src / component / first-scene / first-scene.tsx View on Github external
vertex: "custom",
                fragment: "custom",
            },
            {
                attributes: ["position", "normal", "uv"],
                uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"]
            });

        const mesh = Mesh.CreatePlane("mesh", 10.0, this.scene);
        mesh.rotate(Axis.Y, Math.PI * .5);

        const refTexture = new Texture("http://i.imgur.com/HP1V7TJ.png", this.scene);

        shaderMaterial.setTexture("refSampler", refTexture);
        shaderMaterial.setFloat("time", 0);
        shaderMaterial.setVector3("cameraPosition", Vector3.Zero());

        shaderMaterial.backFaceCulling = false;

        mesh.material = shaderMaterial;

        let time = 0;

        this.scene.registerBeforeRender(() => {

            shaderMaterial.setFloat("time", time);
            time += 0.02;

            shaderMaterial.setVector3("cameraPosition", this.scene.activeCamera!.position);
        });
    }
}