在drupal上搭建babylonjs
web.config
ASP.Net
babylon文件
<staticContent>
<mimeMap fileExtension = ".babylon" mimeType = "application/babylon" />
</staticContent>
BABYLON.SceneLoader.Load("filepath", "filename", engine, function(scene){})
添加mime
根目录下的.htaccess
根目录下的web.config
/etc/mime.types
Babylonjs基本功能:新建简单几何体和贴图
Shape
MeshBuilder Method
var shape = BABYLON.MeshBuilder.CreateShape(name, options, scene);
Box
var box = BABYLON.MeshBuilder.CreateBox("box", {}, scene);
Sphere
var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {}, scene);
Plane
var plane = BABYLON.MeshBuilder.CreatePlane("plane", {}, scene);
Ground
var Ground = BABYLON.MeshBuilder.CreateGround("ground", {}, scene);
faceUV and faceColors
Texture Atlas
faceUV[f] = (c * 1/6, r * 1/4, (c + 1) * 1/6, (r + 1) * 1/4);
var mat = new BABYLON.StandardMaterial("mat", scene);
var texture = new BABYLON.Texture("URL of Texture Atlas", scene);
mat.diffuseTexture = texture;
mesh.material = mat;
Colors
faceColors[f] = new BABYLON.Color4(r,g,b,a);
These colors are BJS Color4-class values. The Color4 alpha values become active if we set hasVertexAlpha = true :
Orientation
faceUV[1] = new BABYLON.Vector4(Ubottom_left, Vbottom_left, Utop_right, Vtop_right);
faceUV[1].x = Ubottom_left;
faceUV[1].y = Vbottom_left;
faceUV[1].z = Utop_right;
faceUV[1].w = Vtop_right;
var temp = faceUV[1].x;
faceUV[f].x = faceUV[f].z;
faceUV[f].z = temp;
Box - faceColors
var faceColors = new Array(6);
faceColors[4] = new BABYLON.Color4(1,0,0,1); // red top
faceColors[1] = new BABYLON.Color4(0,1,0,1);
transparent color
box.hasVertexAlpha = true;
Position
pilot.position = new BABYLON.Vector3(2, 3, 4);
pilot.position.x = 2;
pilot.position.y = 3;
pilot.position.z = 4;
Rotation
pilot.rotation.x = alpha; //rotation around x axis
pilot.rotation.y = beta; //rotation around y axis
pilot.rotation.z = gamma; //rotation around z axis
where alpha, beta and gamma are angles measured in radians.
mesh.addRotation(Math.PI/2, 0, 0).addRotation(0, Math.PI/2, 0).addRotation(0, 0, Math.PI/2);
在babylonjs里添加控制手柄
var VJC = new BABYLON.VirtualJoysticksCamera("VJC", scene.activeCamera.position, scene);
VJC.rotation = scene.activeCamera.rotation;
VJC.checkCollisions = scene.activeCamera.checkCollisions;
VJC.applyGravity = scene.activeCamera.applyGravity;
scene.activeCamera = VJC;
scene.activeCamera.attachControl(canvas);