在Babylon.js中绘制自定义形状

时间:2015-06-16 13:54:31

标签: three.js babylonjs

我一直在网上搜索一种在babylon.js中绘制自定义3d形状的方法。如果有人能提供一个有效的例子,我将不胜感激。例如,一个3d不规则五边形,三角形扇形或楔形。

2 个答案:

答案 0 :(得分:1)

你可以在这里找到很多关于Babylon.js中参数形状的信息: http://doc.babylonjs.com/page.php?p=24847

主要针对这里的功能区: http://doc.babylonjs.com/page.php?p=25088

答案 1 :(得分:1)

这是使用功能区对象的楔形:

var createScene = function() {

var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3(0.8, 0.8, 0.8);
var camera = new BABYLON.ArcRotateCamera("Camera", 3 *Math.PI / 2, Math.PI / 2, 20, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, false);

// lights
var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);
light.groundColor = new BABYLON.Color3(0.2, 0.2, 0.5);
light.intensity = 0.6;


var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(-20, 0, -20), scene);
light2.diffuse = BABYLON.Color3.White();
light2.specular = BABYLON.Color3.Green();
light2.intensity = 0.6;

// material
var mat = new BABYLON.StandardMaterial("mat1", scene);
mat.alpha = 1.0;
mat.diffuseColor = new BABYLON.Color3(0.5, 0.5, 1.0);
//mat.backFaceCulling = false;
mat.wireframe = true;

 // tubular ribbon
 path1 = [];
 path2 = [];

  path1.push( new BABYLON.Vector3(0, 0, 0) );
  path2.push( new BABYLON.Vector3(0, 2, 0) );
  path1.push( new BABYLON.Vector3(1, 0, 0) );
  path2.push( new BABYLON.Vector3(1, 2, 0) );
  path1.push( new BABYLON.Vector3(0, 0, 1) );
  path2.push( new BABYLON.Vector3(0, 2, 1) );


var ribbon = BABYLON.Mesh.CreateRibbon("ribbon", [path1, path2], false, true, 0, scene);
ribbon.material = mat;

scene.registerBeforeRender(function(){
    light2.position = camera.position;
});
return scene;};