From 353addd4d73986d68fc84085bb3bef4525f0edc7 Mon Sep 17 00:00:00 2001 From: nguyenhanhdk Date: Thu, 22 Sep 2016 22:17:43 +0700 Subject: [PATCH] Roof --- js/view3d.js | 69 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/js/view3d.js b/js/view3d.js index f06422a..4e278ef 100644 --- a/js/view3d.js +++ b/js/view3d.js @@ -18,6 +18,11 @@ var floor_width = 1283; var floor_height = 960; var isViewHandrail = false; +var roofTan1 = 300/(1810/2); +var roofTan2 = 300/1810; + +var heightRoof = 0; + var wallPaintTexture; var wallPaint = []; var loader = new THREE.TextureLoader(); @@ -46,11 +51,11 @@ var stepper3D = { var wall3D = { 'height_startpoint': converMMtoPX(0), - 'height_endpoint': converMMtoPX(2330), + 'height_endpoint': converMMtoPX(1850), }; var column3D = { 'height_startpoint': converMMtoPX(0), - 'height_endpoint': converMMtoPX(2330), + 'height_endpoint': converMMtoPX(1850), }; var door3D = { 'height_startpoint': converMMtoPX(100), @@ -246,20 +251,22 @@ function initializeScene() { var _3dobject = stepper[3]; drawStepper(scene, _3dxy, _3dobject); } - - + if (!inside) { // roof 101 var roofList = getArray3dCadByType(101); if (roofList.length != 0) { + + heightRoof = roofTan2*floorInfo[2][2]; + roofList = roofList[0]; var _3dxy = { 'start_X': (roofList[2][0]), 'start_Y': (roofList[2][1]), 'width_X': (roofList[2][2]), 'width_Y': (roofList[2][3]), - 'height_startpoint': converMMtoPX(2110), - 'height_endpoint': converMMtoPX(2110 + 50), + 'height_startpoint': wall3D.height_endpoint + converMMtoPX( heightRoof/2- 300), + 'height_endpoint': wall3D.height_endpoint+ converMMtoPX(heightRoof/2- 300+50), }; var _3dobject = roofList[3]; console.log(baconInfo); @@ -268,14 +275,17 @@ function initializeScene() { // roof 102 var roofList = getArray3dCadByType(102); if (roofList.length != 0) { + + heightRoof = roofTan2*floorInfo[2][2]; + roofList = roofList[0]; var _3dxy = { 'start_X': (roofList[2][0]), 'start_Y': (roofList[2][1]), 'width_X': (roofList[2][2]), 'width_Y': (roofList[2][3]), - 'height_startpoint': converMMtoPX(2110), - 'height_endpoint': converMMtoPX(2110 + 50), + 'height_startpoint': wall3D.height_endpoint + converMMtoPX( heightRoof/2- 300), + 'height_endpoint': wall3D.height_endpoint+ converMMtoPX(heightRoof/2- 300+50), }; var _3dobject = roofList[3]; drawRoof3D(scene, _3dxy, _3dobject, 102); @@ -283,14 +293,16 @@ function initializeScene() { // roof 103 var roofList = getArray3dCadByType(103); if (roofList.length != 0) { + heightRoof = roofTan2*floorInfo[2][3]; + roofList = roofList[0]; var _3dxy = { 'start_X': (roofList[2][0]), 'start_Y': (roofList[2][1]), 'width_X': (roofList[2][2]), 'width_Y': (roofList[2][3]), - 'height_startpoint': converMMtoPX(2110), - 'height_endpoint': converMMtoPX(2110 + 50), + 'height_startpoint': wall3D.height_endpoint + converMMtoPX( heightRoof/2 - 300), + 'height_endpoint': wall3D.height_endpoint+ converMMtoPX(heightRoof/2- 300 +50), }; var _3dobject = roofList[3]; drawRoof3D(scene, _3dxy, _3dobject, 103); @@ -298,14 +310,18 @@ function initializeScene() { // roof 104 var roofList = getArray3dCadByType(104); if (roofList.length != 0) { + + + heightRoof = roofTan2*floorInfo[2][3]; + roofList = roofList[0]; var _3dxy = { 'start_X': (roofList[2][0]), 'start_Y': (roofList[2][1]), 'width_X': (roofList[2][2]), 'width_Y': (roofList[2][3]), - 'height_startpoint': converMMtoPX(2110), - 'height_endpoint': converMMtoPX(2110 + 50), + 'height_startpoint': wall3D.height_endpoint + converMMtoPX( heightRoof/2- 300), + 'height_endpoint': wall3D.height_endpoint+ converMMtoPX(heightRoof/2- 300+50), }; var _3dobject = roofList[3]; drawRoof3D(scene, _3dxy, _3dobject, 104); @@ -743,8 +759,10 @@ function drawWall(scene, _3dxy, _3dobject) { } else { _3dxy.width_Y = converMMtoPX(wallWidth); } - _3dxy.height_endpoint = wall3D.height_endpoint + floor3D.height_endpoint; + console.log("drawWal heightRoof: " + heightRoof); + _3dxy.height_endpoint = wall3D.height_endpoint + floor3D.height_endpoint + converMMtoPX(heightRoof) ; _3dxy.height_startpoint = wall3D.height_startpoint + floor3D.height_endpoint; + var material = { 'tex': wallTexture, }; @@ -840,7 +858,7 @@ function getWallPosition(_3dxy) { //Draw Pillar function drawPillar(scene, _3dxy, _3dobject) { - _3dxy.height_endpoint = column3D.height_endpoint + floor3D.height_endpoint; + _3dxy.height_endpoint = column3D.height_endpoint + floor3D.height_endpoint + converMMtoPX(heightRoof) ; _3dxy.height_startpoint = floor3D.height_endpoint; drawPillarWithPaintInside(scene, _3dxy, _3dobject) @@ -1923,7 +1941,7 @@ function drawRoof3D(scene, _3dxy, _3dobject, type) { } var typeRoof = _3dobject[0].split('-'); typeRoof = typeRoof[0] + '-' + typeRoof[1]; - var heightRoof = 300; + //var heightRoof = 300; // var rType = JSON.parse(JSON.stringify(roofType)); if (rotate == 1) @@ -1936,6 +1954,7 @@ function drawRoof3D(scene, _3dxy, _3dobject, type) { type = 104; // if (typeRoof == 'roof-2') { + var tan = roofTan2; roof3D = drawObj(scene, _3dxy, _3dobject, material); roof_2roof_obj = null; @@ -1945,21 +1964,26 @@ function drawRoof3D(scene, _3dxy, _3dobject, type) { _3dxyRoof = JSON.parse(JSON.stringify(_3dxy)); //// if (type == 101) { - var tan = (heightRoof) / (floorInfo[2][3]); + //var tan = (heightRoof) / (floorInfo[2][3]); + //heightRoof = tan*floorInfo[2][3]; + var b = 2030 +tan*(floorInfo[2][3]-(converPxtoMm(_3dxyRoof.width_Y)/2 - 300)) + 50 / 2; - // var b = 1820 + converPxtoMm(tan * (floorInfo[2][3])-(_3dxyRoof.width_Y/2-converMMtoPX(300))) + 50 / 2; + // var b = 1820 + converPxtoMm(tan * (floorInfo[2][3])-(_3dxyRoof.width_Y/2-converMMtoPX(heightRoof))) + 50 / 2; roof3D.rotation.x = Math.atan(tan); } else if (type == 102) { - var tan = (heightRoof) / (floorInfo[2][3]); + //var tan = (heightRoof) / (floorInfo[2][3]); + //heightRoof = tan*floorInfo[2][3]; var b = 2030 +tan*(floorInfo[2][3]-(converPxtoMm(_3dxyRoof.width_Y)/2 - 300)) + 50 / 2; roof3D.rotation.x = -Math.atan(tan); } else if (type == 103) { - var tan = (heightRoof) / (floorInfo[2][2]); + //var tan = (heightRoof) / (floorInfo[2][2]); + //heightRoof = tan*floorInfo[2][2]; var b = 2030 +tan*(floorInfo[2][2]-(converPxtoMm(_3dxyRoof.width_X)/2 - 300)) + 50 / 2; roof3D.rotation.z = -Math.atan(tan); } else if (type == 104) { - var tan = (heightRoof) / (floorInfo[2][2]); + //var tan = (heightRoof) / (floorInfo[2][2]); + //heightRoof = tan*floorInfo[2][2]; var b = 2030 +tan*(floorInfo[2][2]-(converPxtoMm(_3dxyRoof.width_X)/2 - 300)) + 50 / 2; roof3D.rotation.z = Math.atan(tan); } @@ -1992,14 +2016,15 @@ function drawRoof3D(scene, _3dxy, _3dobject, type) { scene.add(roofSlice); } else if (typeRoof == 'roof-1') { var diff = 300; - var heightRoof = 300; + //var heightRoof = 300; + tan = roofTan1; roof3D = null; if (type == 101 || type === 102) { var roof_1roof = JSON.parse(JSON.stringify(_3dxy)); //roof1 roof_1roof.width_Y = roof_1roof.width_Y / 2; roof_1roof_obj = drawObj(scene, roof_1roof, _3dobject, material); - var tan = converMMtoPX(heightRoof) / (roof_1roof.width_Y); + //var tan = converMMtoPX(heightRoof) / (roof_1roof.width_Y); roof_1roof_obj.rotation.x = -Math.atan(tan); var c = 2030 + 300 - tan * roof_1roof.width_Y * 2; roof_1roof_obj.position.y = converMMtoPX(c) + floor3D.height_endpoint - floor3D.height_startpoint; -- 1.8.5.3