Я динамически генерирую трехмерную структуру для крыши, и она отлично работает для определенной меры. Но когда я устанавливаю разные измерения, учитывая, что я генерирую каждый столбец / стропила / стержень по отдельности, и оба имеют разное вращение, положение и размер, у меня возникают трудности с масштабированием.
Чтобы понять:
Я получу динамически ширину и длину крыши, а также количество остекления. У меня всегда есть 4 колонны и 4 стропила. Остекление может быть от 0 до любого значения.
Мои идеальные и наиболее используемые (пользователями) размеры: ширина 2 м, высота 2 м и 2 полосы остекления.
Но когда я получаю ширину 3 м или более с высотой 2 м, мой наклон или положение остекления не совпадают с моими основными измерениями.
Я пробовал сотни разных способов сделать это, но мне определенно нужно создать масштаб и применить его к столбцам и стропилам, но я не знаю, как это сделать.
var rh = 2;
var glazBarNum = 2;
//var rightPropostion = 2 / 2;
//var currentPropostion = rw / rh;
var bm = rw;
if (rh > rw) bm = rh;
// put in the correct proportion
var roofHeight = rh * (20 / bm);
var roofWidth = rw * (20 / bm);
var stTilt = 4.87;
var stBigColHeight = 18;
var stBigRafHeight = 8.8;
var stSmallColHeight = 15.2;
var stSamllRafHeight = 5.6;
var stSmallColPosition = -(stSmallColHeight * 0.1); // -1.52
var stBigColPosition = -(((stBigColHeight * 0.1)-((stBigColHeight * 0.1) * 0.2))-1); // ((18*0.1)-20%)-1 = 0.44
var createScene = function () {
// Create the scene space
var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3(1, 1, 1);
// Add a camera to the scene and attach it to the canvas
var camera = new BABYLON.ArcRotateCamera("Camera", 1 * Math.PI / 4, Math.PI / 3.5, 50, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);
// Add lights to the scene
var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene);
var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene);
// Materials
var mat = new BABYLON.StandardMaterial('mat', scene);
mat.diffuseColor = new BABYLON.Color3(.15, .07, 0);
// Add and manipulate meshes in the scene
var rafterWidth1 = BABYLON.MeshBuilder.CreateBox("rafterWidth1", { height: (roofWidth+1.5), width: 0.78, depth: 0.78 }, scene);
rafterWidth1.position = new BABYLON.Vector3(0, stBigRafHeight, -((roofHeight)/2));
rafterWidth1.rotation = new BABYLON.Vector3(4.71, 1.57085);
rafterWidth1.material = mat;
var rafterWidth2 = BABYLON.MeshBuilder.CreateBox("rafterWidth2", { height: (roofWidth+1.5), width: 0.78, depth: 0.78 }, scene);
rafterWidth2.position = new BABYLON.Vector3(0, stSamllRafHeight, ((roofHeight)/2));
rafterWidth2.rotation = new BABYLON.Vector3(4.71, 1.57085);
rafterWidth2.material = mat;
var rafterLength1 = BABYLON.MeshBuilder.CreateBox("rafterLength1", { height: (roofHeight+3), width: 0.78, depth: 0.78 }, scene);
rafterLength1.position = new BABYLON.Vector3(-((roofWidth)-((roofWidth)/2)), 7.8, 0);
rafterLength1.rotation = new BABYLON.Vector3(stTilt, 0);
rafterLength1.material = mat;
var rafterLength2 = BABYLON.MeshBuilder.CreateBox("rafterLength2", { height: (roofHeight+3), width: 0.78, depth: 0.78 }, scene);
rafterLength2.position = new BABYLON.Vector3(((roofWidth)-((roofWidth)/2)), 7.8, 0);
rafterLength2.rotation = new BABYLON.Vector3(stTilt, 0);
rafterLength2.material = mat;
for (var i = 1; i <= glazBarNum; i++) {
var space = roofWidth / (glazBarNum + 1);
var glaPos = ((roofWidth)-((roofWidth)/2)) - (space * i);
window['glazzingBar' + i]
window['glazzingBar' + i] = BABYLON.MeshBuilder.CreateBox("glazzingBar"+i, { height: (roofHeight+3), width: 0.78, depth: 0.78 }, scene);
window['glazzingBar' + i].position = new BABYLON.Vector3(glaPos, 7.8, 0);
window['glazzingBar' + i].rotation = new BABYLON.Vector3(stTilt, 0);
window['glazzingBar' + i].material = mat;
}
var col1 = BABYLON.MeshBuilder.CreateBox("col1", { height: stBigColHeight, width: 0.78, depth: 0.78 }, scene);
col1.position = new BABYLON.Vector3((roofWidth/2), stBigColPosition, -(roofHeight/2));
col1.material = mat;
var col2 = BABYLON.MeshBuilder.CreateBox("col2", { height: stSmallColHeight, width: 0.78, depth: 0.78 }, scene);
col2.position = new BABYLON.Vector3((roofWidth/2), stSmallColPosition, (roofHeight/2));
col2.material = mat;
var col3 = BABYLON.MeshBuilder.CreateBox("col3", { height: stBigColHeight, width: 0.78, depth: 0.78 }, scene);
col3.position = new BABYLON.Vector3(-(roofWidth/2), stBigColPosition, -(roofHeight/2));
col3.material = mat;
var col4 = BABYLON.MeshBuilder.CreateBox("col4", { height: stSmallColHeight, width: 0.78, depth: 0.78 }, scene);
col4.position = new BABYLON.Vector3(-(roofWidth/2), stSmallColPosition, (roofHeight/2));
col4.material = mat;
return scene;
};
Вы можете использовать игровую площадку Babylon.js для тестирования: https://www.babylonjs -playground.com / . Просто скопируйте весь этот код и перезапишите весь код, который появляется там, а затем нажмите кнопку RUN.
Я ожидаю, что все углы / соединения идеально подходят, когда я ввожу разные измерения.