Skip to content

Instantly share code, notes, and snippets.

Avatar

Limes2018 flushpot1125

View GitHub Profile
View bjs_editor_script_sample1.ts
import { Mesh,PhysicsImpostor } from "@babylonjs/core";
import { fromScene} from "../tools";
export default class block extends Mesh {
@fromScene("ball")
_ball :Mesh;//1つ上の行の"@fromScene"の引数が、Graph View上のオブジェクト名 (この場合は"ball"というオブジェクトがGraph Viewに存在する)。そのオブジェクトを_ballに対応させる
//補足 Graph Viewは、UnityのHierarchy Viewと同等
//block生成時に1度だけ呼ばれる
View webxr_camera_position.js
xr.baseExperience.onStateChangedObservable.add((state)=>{
if(state === BABYLON.WebXRState.IN_XR){
console.log('WebXR camera position(before_enteringVR): '+xr.baseExperience.camera.position);
xr.baseExperience.camera.position.set(0, 2, 10);
console.log('WebXR camera position(after_enteringVR): '+xr.baseExperience.camera.position);
}
});
View partof-webxr-thumbstick-motioncontroller-bjs.js
thumbstickComponent.onAxisValueChangedObservable.add((axes) => {
//Box_Right_ThumbStick is moving according to stick axes but camera rotation is also changing..
Box_Right_ThumbStick.position.x += (axes.x)/100;
Box_Right_ThumbStick.position.y += (axes.y)/100;
// console.log(values.x, values.y);
});
View get-webxr-motioncontroller-id.js
const xr_ids = motionController.getComponentIds();
for (let i=0;i<xr_ids.length;i++){
console.log("right:"+xr_ids[i]);
}
View partof-webxr-lefttrigger-motioncontroller-bjs.js
xr.input.onControllerAddedObservable.add((controller) => {
controller.onMotionControllerInitObservable.add((motionController) => {
if (motionController.handness === 'left') {
const xr_ids = motionController.getComponentIds();
let triggerComponent = motionController.getComponent(xr_ids[0]);//xr-standard-trigger
triggerComponent.onButtonStateChangedObservable.add(() => {
if (triggerComponent.pressed) {
Box_Left_Trigger.scaling= new BABYLON.Vector3(1.2,1.2,1.2);
}else{
View partof-oculus-touch-v3.json
{
"profileId": "oculus-touch-v3",
"fallbackProfileIds": [ "oculus-touch-v2", "oculus-touch", "generic-trigger-squeeze-thumbstick"],
"layouts": {
"left": {
"selectComponentId": "xr-standard-trigger",
"components": {
"xr-standard-trigger": { "type": "trigger" },
"xr-standard-squeeze": { "type": "squeeze" },
View bjs_es6_webpack.config.js
//参考:https://qiita.com/10mi8o/items/2477f2640291f0ce6687
/* pathモジュールを使ってwebページとして出力するパスを指定する。
"path.resolveは、引数をつなげて絶対パスに変換する"
"__dirname"は、実行集のソースコードが格納されているディレクトリパス
参考:https://gist.github.com/uupaa/da42698d6b2d2cbb3cca
*/
const path = require('path');
//const outputPath = path.resolve(__dirname, 'dist');
View modified_index.html
<!-- <script src="./node_modules/cannon/build/cannon.js" type="text/javascript"></script> -->
<!-- you should drag and drop cannon.js file -->
<script src="./cannon.js" type="text/javascript"></script>
View call_other_class_method_example.ts
//ball.ts
import { Mesh} from "@babylonjs/core";
import GameComponent from "./game";
export default class BallComponent extends Mesh {
public _scene: GameComponent;
//...
/**
* Called each frame.
View gui_example.ts
import { AdvancedDynamicTexture, TextBlock, Control, Image, StackPanel } from "@babylonjs/gui";
/**
* Defines the reference to the GUI advanced texture.
*/
public gui: AdvancedDynamicTexture = null;
/**
* Called on the node is being initialized.
* This function is called immediatly after the constructor has been called.
*/