|
@@ -475,7 +475,7 @@ var grendCAD = (function grentWall() {
|
|
|
|
|
|
|
|
|
function Wall(data, cameras) {
|
|
|
- this.lineWidth = 8
|
|
|
+ this.lineWidth = 4
|
|
|
this.cameras = cameras
|
|
|
this.stateStack = []
|
|
|
var faces = {}
|
|
@@ -568,18 +568,8 @@ var grendCAD = (function grentWall() {
|
|
|
line.points[1].y = lastLine.points[0].y
|
|
|
}
|
|
|
|
|
|
- Wall.prototype._move = function (point, prevPoint, movePosition, renderer) {
|
|
|
- var xdis = point.x - prevPoint.x
|
|
|
- var ydis = point.y - prevPoint.y
|
|
|
+ Wall.prototype.detection = function (movePosition) {
|
|
|
var revoke = false
|
|
|
- var dire = movePosition.dire[0] - movePosition.dire[1] > 0 ? 'X' : 'Y'
|
|
|
-
|
|
|
- if (dire === 'X') {
|
|
|
- this.updateLine(movePosition.line, xdis, 0)
|
|
|
- } else {
|
|
|
- this.updateLine(movePosition.line, 0, ydis)
|
|
|
- }
|
|
|
-
|
|
|
var activeFacePoint = getFacePoints(movePosition.face)
|
|
|
for (let key in this.faces) {
|
|
|
if (this.faces[key] !== movePosition.face &&
|
|
@@ -599,6 +589,22 @@ var grendCAD = (function grentWall() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ return revoke
|
|
|
+ }
|
|
|
+
|
|
|
+ Wall.prototype._move = function (point, prevPoint, movePosition, renderer) {
|
|
|
+ var xdis = point.x - prevPoint.x
|
|
|
+ var ydis = point.y - prevPoint.y
|
|
|
+ var dire = movePosition.dire[0] - movePosition.dire[1] > 0 ? 'X' : 'Y'
|
|
|
+
|
|
|
+ if (dire === 'X') {
|
|
|
+ this.updateLine(movePosition.line, xdis, 0)
|
|
|
+ } else {
|
|
|
+ this.updateLine(movePosition.line, 0, ydis)
|
|
|
+ }
|
|
|
+
|
|
|
+ var revoke = this.detection(movePosition)
|
|
|
+
|
|
|
|
|
|
if (revoke) {
|
|
|
if (dire === 'X') {
|
|
@@ -697,9 +703,9 @@ var grendCAD = (function grentWall() {
|
|
|
function Position(point, angle) {
|
|
|
this.point = point
|
|
|
this.angle = angle
|
|
|
- this.withinW = 8
|
|
|
- this.abroadW = 4
|
|
|
- this.lightW = 14
|
|
|
+ this.withinW = 6
|
|
|
+ this.abroadW = 2
|
|
|
+ this.lightW = 12
|
|
|
this.lightrRdian = 1 / 2.5 * Math.PI
|
|
|
}
|
|
|
|
|
@@ -746,7 +752,7 @@ var grendCAD = (function grentWall() {
|
|
|
function Door(line, point) {
|
|
|
this.line = line
|
|
|
this.point = point
|
|
|
- this.lineWidth = 8
|
|
|
+ this.lineWidth = 4
|
|
|
this.color = 'rgba(0,200,175,1)'
|
|
|
}
|
|
|
|
|
@@ -814,7 +820,7 @@ var grendCAD = (function grentWall() {
|
|
|
count++
|
|
|
this.line = line
|
|
|
this.points = points
|
|
|
- this.lineWidth = 8
|
|
|
+ this.lineWidth = 4
|
|
|
this.color = 'rgba(0,200,175,1)'
|
|
|
}
|
|
|
|
|
@@ -944,7 +950,7 @@ var grendCAD = (function grentWall() {
|
|
|
count++
|
|
|
this.line = line
|
|
|
this.points = points
|
|
|
- this.lineWidth = 8
|
|
|
+ this.lineWidth = 4
|
|
|
this.color = '#202123'
|
|
|
}
|
|
|
|
|
@@ -1097,6 +1103,13 @@ var grendCAD = (function grentWall() {
|
|
|
this.context.translate(this.width / 2, this.height / 2);
|
|
|
this.screenOffset = getPosition(this.canvas)
|
|
|
|
|
|
+ this.section = {
|
|
|
+ minx: -this.width / 2,
|
|
|
+ maxx: this.width / 2,
|
|
|
+ miny: -this.height / 2,
|
|
|
+ maxy: this.height / 2
|
|
|
+ }
|
|
|
+
|
|
|
var points = []
|
|
|
this.origin.forEach(function (line) {
|
|
|
points = points.concat(...line.points)
|
|
@@ -1131,6 +1144,7 @@ var grendCAD = (function grentWall() {
|
|
|
* 画布点位转化为真实点位
|
|
|
*/
|
|
|
Renderer.prototype.transRealPoint = function (point) {
|
|
|
+ console.log(point)
|
|
|
return {
|
|
|
x: (point.x * this.status.prop) / (this.status.range * this.width / 2) - this.status.offset.x,
|
|
|
y: (point.y * this.status.prop) / (this.status.range * this.height / 2) - this.status.offset.y
|
|
@@ -1140,12 +1154,6 @@ var grendCAD = (function grentWall() {
|
|
|
|
|
|
Renderer.prototype.regEvent = function () {
|
|
|
var sinfo, model;
|
|
|
- var section = {
|
|
|
- minx: -this.width / 2,
|
|
|
- maxx: this.width / 2,
|
|
|
- miny: -this.height / 2,
|
|
|
- maxy: this.height / 2
|
|
|
- }
|
|
|
var startPoint = null
|
|
|
var prevPoint = null
|
|
|
|
|
@@ -1153,7 +1161,7 @@ var grendCAD = (function grentWall() {
|
|
|
down(offset) {
|
|
|
offset.x = (offset.x - this.screenOffset.x) * this.wMultiple
|
|
|
offset.y = (offset.y - this.screenOffset.y) * this.hMultiple
|
|
|
- startPoint = this.transRealPoint(util.tranPoint(offset, section))
|
|
|
+ startPoint = this.transRealPoint(util.tranPoint(offset, this.section))
|
|
|
prevPoint = startPoint
|
|
|
|
|
|
var models = Object.assign([], this.models).sort(function(a, b) {
|
|
@@ -1173,7 +1181,7 @@ var grendCAD = (function grentWall() {
|
|
|
move(move) {
|
|
|
move.x = (move.x - this.screenOffset.x) * this.wMultiple
|
|
|
move.y = (move.y - this.screenOffset.y) * this.hMultiple
|
|
|
- var point = this.transRealPoint(util.tranPoint(move, section))
|
|
|
+ var point = this.transRealPoint(util.tranPoint(move, this.section))
|
|
|
model._move(point, prevPoint, sinfo, this, this.context)
|
|
|
prevPoint = point
|
|
|
},
|
|
@@ -1253,7 +1261,11 @@ var grendCAD = (function grentWall() {
|
|
|
}
|
|
|
|
|
|
function update2d(wall, line) {
|
|
|
+ if (line.___loadUpdate) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
var update = line.update
|
|
|
+ line.___loadUpdate = true
|
|
|
line.update = function (dirs, len) {
|
|
|
var args = [
|
|
|
{x: 0, y: 0},
|
|
@@ -1269,30 +1281,89 @@ var grendCAD = (function grentWall() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return function (dom, line2Ds, cameras) {
|
|
|
+ /**
|
|
|
+ * 装载门窗,并拦截线段移动碰到门窗
|
|
|
+ * @param {*} line2Ds
|
|
|
+ * @param {*} wall
|
|
|
+ */
|
|
|
+ function loadComponents(line2Ds, wall, renderer) {
|
|
|
var doors = []
|
|
|
var casements = []
|
|
|
- var wall = new Wall(line2Ds, cameras)
|
|
|
|
|
|
- line2Ds.forEach(function(line) {
|
|
|
- if (line.doors) {
|
|
|
- doors.push.apply(doors,
|
|
|
- line.doors.map(function(door) {
|
|
|
- return new Door(line, door.points)
|
|
|
- })
|
|
|
- )
|
|
|
- }
|
|
|
+ line2Ds.forEach(function (line) {
|
|
|
+ line.__doors = line.__doors || []
|
|
|
+ line.__casements = line.__casements || []
|
|
|
|
|
|
- if (line.casements) {
|
|
|
- casements.push.apply(casements,
|
|
|
- line.casements.map(function (casements) {
|
|
|
- return new Casement(line, casements.points)
|
|
|
- })
|
|
|
- )
|
|
|
- }
|
|
|
+
|
|
|
+ line.otherobjs && line.otherobjs.forEach(function (obj) {
|
|
|
+ function check(_obj) {
|
|
|
+ return _obj.origin === obj
|
|
|
+ }
|
|
|
+ if (~line.__doors.findIndex(check) || ~line.__casements.findIndex(check)) return;
|
|
|
+
|
|
|
+ if (~obj.id.indexOf('door')) {
|
|
|
+ var door = new Door(line, obj.points2d)
|
|
|
+ door.origin = obj
|
|
|
+ // 创建线段中的门
|
|
|
+ line.__doors.push(door)
|
|
|
+ doors.push(door)
|
|
|
+ } else if (~obj.id.indexOf('window')) {
|
|
|
+ var casement = new Casement(line, obj.points2d)
|
|
|
+ casement.origin = obj
|
|
|
+ // 创建线段中的门
|
|
|
+ line.__casements.push(casement)
|
|
|
+ casements.push(casement)
|
|
|
+ }
|
|
|
+
|
|
|
+ var update = obj.update2d
|
|
|
+ obj.update2d = function() {
|
|
|
+ update && update()
|
|
|
+ renderer.render()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 3D改变同步状态改变2D方法注册
|
|
|
update2d(wall, line)
|
|
|
})
|
|
|
|
|
|
+
|
|
|
+ if (!wall.__additional__detection) {
|
|
|
+ // 创建拦截,拦截移动墙面碰到门窗
|
|
|
+ wall.__additional__detection = true
|
|
|
+ var detection = wall.detection.bind(wall)
|
|
|
+ wall.detection = function (movePos) {
|
|
|
+ if (detection(movePos)) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ var line = movePos.line
|
|
|
+ // var objs = [(line.__doors || []).concat(line.__casements || [])]
|
|
|
+ var objs = []
|
|
|
+ var reject = false
|
|
|
+
|
|
|
+ for (var i = 0; i < line2Ds.length; i++) {
|
|
|
+ if (line2Ds[i].id === line.linkedLineID[0] || line2Ds[i].id === line.linkedLineID[1]) {
|
|
|
+ line2Ds[i].__doors && objs.push.apply(objs, line2Ds[i].__doors)
|
|
|
+ line2Ds[i].__casements && objs.push.apply(objs, line2Ds[i].__casements)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ objs.forEach(function (obj) {
|
|
|
+ if (!obj.detection()) {
|
|
|
+ reject = true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return reject
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return doors.concat(casements)
|
|
|
+ }
|
|
|
+
|
|
|
+ return function (dom, line2Ds, cameras) {
|
|
|
+ var renderer = new Renderer(dom, line2Ds)
|
|
|
+ var wall = new Wall(line2Ds, cameras)
|
|
|
+
|
|
|
+ // 当墙面位置发生改变时同步3D
|
|
|
wall.listen('changePosition', function(line2D) {
|
|
|
line2Ds.forEach(function (line) {
|
|
|
if (line.id === line2D.linkedLineID[0] ||
|
|
@@ -1303,19 +1374,30 @@ var grendCAD = (function grentWall() {
|
|
|
update3D(line2D)
|
|
|
})
|
|
|
|
|
|
- doors.concat(casements).forEach(function (obj) {
|
|
|
- obj.listen('changePoints', function() {
|
|
|
- update3D(obj.line)
|
|
|
- })
|
|
|
- })
|
|
|
|
|
|
- var renderer = new Renderer(dom, line2Ds)
|
|
|
renderer.models.push(wall)
|
|
|
- renderer.models.push.apply(renderer.models, doors.concat(casements))
|
|
|
renderer.render()
|
|
|
|
|
|
+ function load () {
|
|
|
+ var objs = loadComponents(line2Ds, wall, renderer)
|
|
|
+ // 当门窗位置大小发生改变时同步3D
|
|
|
+ objs.forEach(function (obj) {
|
|
|
+ obj.listen('changePoints', function () {
|
|
|
+ if (obj.origin.update3D) {
|
|
|
+ obj.origin.update3D()
|
|
|
+ } else {
|
|
|
+ console.log(obj.origin, '组件未绑定更新3D方法')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ renderer.models.push.apply(renderer.models, objs)
|
|
|
+ renderer.render()
|
|
|
+ }
|
|
|
+ load();
|
|
|
+
|
|
|
var position;
|
|
|
return {
|
|
|
+ // 设置当前位置
|
|
|
position: function (posPoint, angle) {
|
|
|
if (!position) {
|
|
|
position = new Position(posPoint, angle)
|
|
@@ -1326,7 +1408,8 @@ var grendCAD = (function grentWall() {
|
|
|
}
|
|
|
renderer.render()
|
|
|
},
|
|
|
- renderer: renderer
|
|
|
+ renderer: renderer,
|
|
|
+ updateComponents: load
|
|
|
}
|
|
|
}
|
|
|
})();
|