Hi
I am trying to do the following, Take a model in wireframe and add new meshes to its vertices.
I created a simple model of 2 tetrahedrons and imported it into babylon using the raw data from the export file, using setVerticesData.
It renders correctly however the next part to my project is to add meshes to each vertex point ( suppose to be 8 ),
I instead get 24 points into my array when I use the function
getVerticesData(BABYLON.VertexBuffer.PositionKind);
In clara.io I see 8 vertices. So I am not sure why I am getting so many vertex points.
The reason why I am importing the raw data is due to the fact I do not want to use a web server for this project.
it must run off the browser in offline mode.
see code
I also attached screenshots from the playground
I would like to get the correct 8 vertices to add my custom meshes to it
link to clara.io model
https://clara.io/view/2ee8381f-23f5-4eeb-b682-01e6f68f037d/image
thanks
zak
var createScene = function () {
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 2, Math.PI / 8, 50, BABYLON.Vector3.Zero(), scene);
var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);
camera.attachControl(canvas, true);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;
var base = createBase(scene);
var vertices = base.getVerticesData(BABYLON.VertexBuffer.PositionKind);
createMeshAtVertices(vertices, scene)
return scene;
};
function createBase(scene){
var tet1 = new BABYLON.Mesh("base", scene);
var tet1positions = [-0.009,0.1071,-0.01,-0.2019,0.7687,0.4279,0.473,0.7658,-0.0316,-0.2019,0.7687,0.4279,-0.009,0.1071,-0.01,-0.2622,0.7861,-0.3862,0.473,0.7658,-0.0316,-0.2019,0.7687,0.4279,-0.2622,0.7861,-0.3862,-0.009,0.1071,-0.01,0.473,0.7658,-0.0316,-0.2622,0.7861,-0.3862,0.009,-0.1271,0.0092,0.2622,-0.8054,0.3865,-0.473,-0.7857,0.0319,0.2019,-0.7894,-0.4276,-0.473,-0.7857,0.0319,0.2622,-0.8054,0.3865,0.2019,-0.7894,-0.4276,0.2622,-0.8054,0.3865,0.009,-0.1271,0.0092,0.2019,-0.7894,-0.4276,0.009,-0.1271,0.0092,-0.473,-0.7857,0.0319];
var tet1normals = [0.5243,-0.3584,0.7725,0.5243,-0.3584,0.7725,0.5243,-0.3584,0.7725,-0.9461,-0.3177,0.0632,-0.9461,-0.3177,0.0632,-0.9461,-0.3177,0.0632,0.018,0.9996,0.02,0.018,0.9996,0.02,0.018,0.9996,0.02,0.4038,-0.3236,-0.8557,0.4038,-0.3236,-0.8557,0.4038,-0.3236,-0.8557,-0.4038,0.3249,0.8552,-0.4038,0.3249,0.8552,-0.4038,0.3249,0.8552,-0.0179,-0.9997,-0.0184,-0.0179,-0.9997,-0.0184,-0.0179,-0.9997,-0.0184,0.9461,0.3177,-0.0637,0.9461,0.3177,-0.0637,0.9461,0.3177,-0.0637,-0.5243,0.3571,-0.773,-0.5243,0.3571,-0.773,-0.5243,0.3571,-0.7734];
var tet1uvs = [0.375,0.6959,0.875,0.6959,0.625,0.3041,0.875,0.6959,0.375,0.6959,0.125,0.3041,0.625,0.3041,0.875,0.6959,0.125,0.3041,0.375,0.6959,0.625,0.3041,0.125,0.3041,0.625,0.3041,0.875,0.6959,0.375,0.6959,0.125,0.3041,0.375,0.6959,0.875,0.6959,0.125,0.3041,0.875,0.6959,0.625,0.3041,0.125,0.3041,0.625,0.3041,0.375,0.6959];
var indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23];
tet1.setVerticesData(BABYLON.VertexBuffer.PositionKind, tet1positions, true);
tet1.setVerticesData(BABYLON.VertexBuffer.NormalKind, tet1normals, true);
tet1.setVerticesData(BABYLON.VertexBuffer.UVKind, tet1uvs, true);
tet1.setIndices(indices);
var material = new BABYLON.StandardMaterial("pyshical", scene);
material.wireframe = true;
material.diffuseColor = BABYLON.Color3.White();
material.specularColor = BABYLON.Color3.White();
material.emissiveColor = BABYLON.Color3.Blue();
tet1.material = material;
tet1.scaling = new BABYLON.Vector3(15, 15, 15);
tet1.rotation.z = -0.4;
tet1.rotation.y = 2.5;
tet1.rotation.x = 2.6;
tet1.bakeCurrentTransformIntoVertices();
return tet1;
};
function createMeshAtVertices(vertices, scene) {
var stype = 0;
var shape;
for (var i = 0; i < vertices.length / 3; i++ ){
if(stype == 5)
stype = 0;
shape = BABYLON.Mesh.CreatePolyhedron("pyshical", { type: stype, size:0.5 }, scene);
shape.position = BABYLON.Vector3.FromArray(vertices, i);
shape.scaling = new BABYLON.Vector3(1, 1, 1);
stype++;
}
};