Browse Source

三维家下载打包下载接口

dengsixing 2 years ago
parent
commit
f14b6708d4

+ 195 - 0
src/main/java/com/fdkankan/scene/bean/EulerAngles.java

@@ -0,0 +1,195 @@
+package com.fdkankan.scene.bean;
+
+
+import static com.sun.javafx.util.Utils.clamp;
+
+public class EulerAngles {
+
+    /**
+     * 俯仰角(pitch) 弧度       x
+     */
+    public double x;
+    /**
+     * yaw 即heading(航向角) 弧度 y
+     */
+    public double y;
+    /**
+     * 翻滚角(roll) 弧度   z
+     */
+    public double z;
+
+    /**
+     * 通过四元数转欧拉角
+     */
+    public EulerAngles(double w, double x, double y, double z, String order) {
+        double x2 = x + x,  y2 = y + y, z2 = z + z;
+        double xx = x * x2, xy = x * y2, xz = x * z2;
+        double yy = y * y2, yz = y * z2, zz = z * z2;
+        double wx = w * x2, wy = w * y2, wz = w * z2;
+
+        double[] te = new double[16];
+
+        te[ 0 ] = ( 1 - ( yy + zz ) ) * 1;
+        te[ 1 ] = ( xy + wz ) * 1;
+        te[ 2 ] = ( xz - wy ) * 1;
+        te[ 3 ] = 0;
+
+        te[ 4 ] = ( xy - wz ) * 1;
+        te[ 5 ] = ( 1 - ( xx + zz ) ) * 1;
+        te[ 6 ] = ( yz + wx ) * 1;
+        te[ 7 ] = 0;
+
+        te[ 8 ] = ( xz + wy ) * 1;
+        te[ 9 ] = ( yz - wx ) * 1;
+        te[ 10 ] = ( 1 - ( xx + yy ) ) * 1;
+        te[ 11 ] = 0;
+
+        te[ 12 ] = x;
+        te[ 13 ] = y;
+        te[ 14 ] = z;
+        te[ 15 ] = 1;
+        setFromRotationMatrix(te,order);
+    }
+
+    private void setFromRotationMatrix(double[] te,String order){
+        double m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
+        double m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
+        double m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
+
+        if ( order.equals( "XYZ") ) {
+
+            this.y = Math.asin( clamp( m13, - 1, 1 ) );
+
+            if ( Math.abs( m13 ) < 0.99999 ) {
+
+                this.x = Math.atan2( - m23, m33 );
+                this.z = Math.atan2( - m12, m11 );
+
+            } else {
+
+                this.x = Math.atan2( m32, m22 );
+                this.z = 0;
+
+            }
+
+        } else if ( order.equals( "YXZ") ) {
+
+            this.x = Math.asin( - clamp( m23, - 1, 1 ) );
+
+            if ( Math.abs( m23 ) < 0.99999 ) {
+
+                this.y = Math.atan2( m13, m33 );
+                this.z = Math.atan2( m21, m22 );
+
+            } else {
+
+                this.y = Math.atan2( - m31, m11 );
+                this.z = 0;
+
+            }
+
+        } else if ( order .equals("ZXY") ) {
+
+            this.x = Math.asin( clamp( m32, - 1, 1 ) );
+
+            if ( Math.abs( m32 ) < 0.99999 ) {
+
+                this.y = Math.atan2( - m31, m33 );
+                this.z = Math.atan2( - m12, m22 );
+
+            } else {
+
+                this.y = 0;
+                this.z = Math.atan2( m21, m11 );
+
+            }
+
+        } else if ( order.equals( "ZYX") ) {
+
+            this.y = Math.asin( - clamp( m31, - 1, 1 ) );
+
+            if ( Math.abs( m31 ) < 0.99999 ) {
+
+                this.x = Math.atan2( m32, m33 );
+                this.z = Math.atan2( m21, m11 );
+
+            } else {
+
+                this.x = 0;
+                this.z = Math.atan2( - m12, m22 );
+
+            }
+
+        } else if ( order.equals( "YZX") ) {
+
+            this.z = Math.asin( clamp( m21, - 1, 1 ) );
+
+            if ( Math.abs( m21 ) < 0.99999 ) {
+
+                this.x = Math.atan2( - m23, m22 );
+                this.y = Math.atan2( - m31, m11 );
+
+            } else {
+
+                this.x = 0;
+                this.y = Math.atan2( m13, m33 );
+
+            }
+
+        } else if ( order.equals( "XZY") ) {
+
+            this.z = Math.asin( - clamp( m12, - 1, 1 ) );
+
+            if ( Math.abs( m12 ) < 0.99999 ) {
+
+                this.x = Math.atan2( m32, m22 );
+                this.y = Math.atan2( m13, m11 );
+
+            } else {
+
+                this.x = Math.atan2( - m23, m33 );
+                this.y = 0;
+
+            }
+
+        } else {
+            //通过按照以上几种旋转顺序设置欧拉角对象失败报错
+            System.out.println("THREE.Euler: .setFromRotationMatrix() given unsupported order: " + order);
+        }
+    }
+
+
+    public EulerAngles(double w,double x, double y, double z,double x1,double y1,double z1) {
+        double t = 0
+                , i = 1
+                , n = 0
+                , r = x
+                , o = y
+                , a = z
+                , s = w
+                , l = s * t + o * n - a * i
+                , c = s * i + a * t - r * n
+                , h = s * n + r * i - o * t
+                , u = -r * t - o * i - a * n;
+
+        this.x = l * s + u * -r + c * -a - h * -o;
+        this.y = c * s + u * -o + h * -r - l * -a;
+        this.z = h * s + u * -a + l * -o - c * -r;
+
+        this.x += x1;
+        this.y += y1;
+        this.z += z1;
+    }
+
+
+    @Override
+    public String toString() {
+        return "EulerAngles{" +
+                "x=" + x +
+                ", y=" + y +
+                ", z=" + z +
+                '}';
+    }
+
+}
+

+ 42 - 0
src/main/java/com/fdkankan/scene/common/house/Component.java

@@ -0,0 +1,42 @@
+package com.fdkankan.scene.common.house;
+
+import java.util.List;
+
+public class Component {
+    private String vectorId;
+    private String parent;
+    private String geoType;
+    private List<Point> vertexes;
+
+    public String getVectorId() {
+        return vectorId;
+    }
+
+    public void setVectorId(String vectorId) {
+        this.vectorId = vectorId;
+    }
+
+    public String getParent() {
+        return parent;
+    }
+
+    public void setParent(String parent) {
+        this.parent = parent;
+    }
+
+    public String getGeoType() {
+        return geoType;
+    }
+
+    public void setGeoType(String geoType) {
+        this.geoType = geoType;
+    }
+
+    public List<Point> getVertexes() {
+        return vertexes;
+    }
+
+    public void setVertexes(List<Point> vertexes) {
+        this.vertexes = vertexes;
+    }
+}

+ 39 - 0
src/main/java/com/fdkankan/scene/common/house/FileWriterUtil.java

@@ -0,0 +1,39 @@
+package com.fdkankan.scene.common.house;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+
+public class FileWriterUtil {
+
+    public static void writerJson(String tagPath,String fileName,String msg){
+        try {
+            File file = new File(tagPath);
+            if(!file.exists()){
+                file.mkdirs();
+            }
+            FileWriter fw = new FileWriter(tagPath +File.separator +fileName);
+            fw.write(msg);
+            fw.close();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    public static  String readFile(String file) throws Exception {
+        BufferedReader reader = new BufferedReader(new FileReader(file));
+        String line = null;
+        StringBuilder stringBuilder = new StringBuilder();
+        String ls = System.getProperty("line.separator");
+        try {
+            while((line = reader.readLine()) != null) {
+                stringBuilder.append(line);
+                stringBuilder.append(ls);
+            }
+            return stringBuilder.toString();
+        } finally {
+            reader.close();
+        }
+    }
+}

+ 42 - 0
src/main/java/com/fdkankan/scene/common/house/Floor.java

@@ -0,0 +1,42 @@
+package com.fdkankan.scene.common.house;
+
+import java.util.List;
+
+public class Floor {
+    private List<Wall> walls;       //墙
+    private List<Point> points;     //点位
+    private List<Symbol> symbols;     //门窗
+    private List<Component> components;     //柱子
+
+    public List<Wall> getWalls() {
+        return walls;
+    }
+
+    public void setWalls(List<Wall> walls) {
+        this.walls = walls;
+    }
+
+    public List<Point> getPoints() {
+        return points;
+    }
+
+    public void setPoints(List<Point> points) {
+        this.points = points;
+    }
+
+    public List<Symbol> getSymbols() {
+        return symbols;
+    }
+
+    public void setSymbols(List<Symbol> symbols) {
+        this.symbols = symbols;
+    }
+
+    public List<Component> getComponents() {
+        return components;
+    }
+
+    public void setComponents(List<Component> components) {
+        this.components = components;
+    }
+}

+ 15 - 0
src/main/java/com/fdkankan/scene/common/house/HouseJson.java

@@ -0,0 +1,15 @@
+package com.fdkankan.scene.common.house;
+
+import java.util.List;
+
+public class HouseJson {
+    private List<Floor> floors;       //楼层
+
+    public List<Floor> getFloors() {
+        return floors;
+    }
+
+    public void setFloors(List<Floor> floors) {
+        this.floors = floors;
+    }
+}

+ 362 - 0
src/main/java/com/fdkankan/scene/common/house/JsonToHouseUtil.java

@@ -0,0 +1,362 @@
+package com.fdkankan.scene.common.house;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class JsonToHouseUtil {
+    public static void main(String[] args) {
+         floorplanCadToHouseJson("D:\\fddowm\\KK-t-3s7KlBajCc\\scene\\data\\dataKK-t-3s7KlBajCc\\floorplan_cad.json");
+         houstFloorToHouseJson("D:\\fddowm\\houst_floor.json");
+    }
+
+    public static int floorplanCadToHouseJson(String srcPath){
+        HouseJson houseJson = new HouseJson();
+        List<Floor> floorList = new ArrayList<>();
+        houseJson.setFloors(floorList);
+        try {
+            String msg = FileWriterUtil.readFile(srcPath);
+            JSONObject jsonObject = JSONObject.parseObject(msg);
+            JSONArray floors = jsonObject.getJSONArray("floors");
+            for (Object o : floors) {
+                JSONObject floor = (JSONObject) o;
+                HashMap<String,List<String>> map = new HashMap<>();
+                JSONArray segment = floor.getJSONArray("segment");
+                List<Wall> wallList = new ArrayList<>();
+                for (Object seo : segment) {
+                    JSONObject segmentObj = (JSONObject) seo;
+                    Wall wall = new Wall();
+                    wall.setVectorId("Wall"+segmentObj.getInteger("id"));
+                    wall.setStart("Point"+ segmentObj.getInteger("a"));
+                    wall.setEnd("Point"+segmentObj.getInteger("b"));
+                    wallList.add(wall);
+
+                    setPointParent(map,wall,"start");
+                    setPointParent(map,wall,"end");
+                }
+
+
+                JSONArray vertex = floor.getJSONArray("vertex-xy");
+                List<Point> pointList = new ArrayList<>();
+                for (Object vo : vertex) {
+                    JSONObject vertexObj = (JSONObject) vo;
+                    Integer vertexId = vertexObj.getInteger("id");
+                    Point point = new Point();
+                    point.setVectorId("Point"+vertexId);
+                    point.setX(vertexObj.getDouble("x"));
+                    point.setY( vertexObj.getDouble("y"));
+
+                    JSONObject parent = new JSONObject();
+                    List<String> strings = map.get(point.getVectorId());
+                    if(strings!=null){
+                        for (String res : strings) {
+                            parent.put(res.split(",")[0],res.split(",")[1]);
+                        }
+                    }
+                    point.setParent(parent);
+
+                    pointList.add(point);
+                }
+                Floor floor1 = new Floor();
+                floor1.setPoints(pointList);
+                floor1.setWalls(wallList);
+                floorList.add(floor1);
+            }
+            int i = checkPointAndWall(floorList);
+            if(i !=0){
+                return i;
+            }
+            String tag = srcPath.replace("floorplan_cad.json","");
+            FileWriterUtil.writerJson(tag,"house.json",JSONObject.toJSONString(houseJson));
+        }catch (Exception e){
+            e.printStackTrace();
+            return -3;
+        }
+        return 0;
+    }
+
+    public static Integer houstFloorToHouseJson(String srcPath){
+        HouseJson houseJson = new HouseJson();
+        List<Floor> floorList = new ArrayList<>();
+        houseJson.setFloors(floorList);
+        try {
+            String msg = FileWriterUtil.readFile(srcPath);
+            JSONObject jsonObject = JSONObject.parseObject(msg);
+            JSONArray floors = jsonObject.getJSONArray("floors");
+            for (Object o : floors) {
+                JSONObject floor = (JSONObject) o;
+                JSONArray segment = floor.getJSONArray("wall");
+                List<Wall> wallList = new ArrayList<>();
+                HashMap<String,List<String>> map = new HashMap<>();
+                for (Object seo : segment) {
+                    JSONObject segmentObj = (JSONObject) seo;
+                    Wall wall = new Wall();
+                    wall.setVectorId("Wall"+segmentObj.getInteger("id"));
+                    wall.setStart("Point"+ segmentObj.getInteger("p1"));
+                    wall.setEnd("Point"+segmentObj.getInteger("p2"));
+                    wallList.add(wall);
+                    setPointParent(map,wall,"start");
+                    setPointParent(map,wall,"end");
+                }
+                JSONArray vertex = floor.getJSONArray("vertex");
+                List<Point> pointList = new ArrayList<>();
+                for (Object vo : vertex) {
+                    JSONObject vertexObj = (JSONObject) vo;
+                    Integer vertexId = vertexObj.getInteger("id");
+                    Point point = new Point();
+                    point.setVectorId("Point"+vertexId);
+                    point.setX(vertexObj.getDouble("x"));
+                    point.setY( vertexObj.getDouble("y"));
+
+                    JSONObject parent = new JSONObject();
+                    List<String> strings = map.get(point.getVectorId());
+                    if(strings!=null){
+                        for (String res : strings) {
+                            parent.put(res.split(",")[0],res.split(",")[1]);
+                        }
+                    }
+                    point.setParent(parent);
+                    pointList.add(point);
+                }
+                List<Symbol> symbolList = new ArrayList<>();
+                setSymbol(floor,symbolList,"window","SingleWindow");
+                setSymbol(floor,symbolList,"groundCase","FrenchWindow");
+                setSymbol(floor,symbolList,"bayCase","BayWindow");
+                setSymbol(floor,symbolList,"door","SingleDoor");
+                setSymbol(floor,symbolList,"slideDoor","SlideDoor");
+                setSymbol(floor,symbolList,"doubleDoor","DoubleDoor");
+                List<Component> componentList = new ArrayList<>();
+                setComponents(floor,componentList,"column","Beam");                //柱子
+                setComponents(floor,componentList,"furnFlue","Flue");              //烟道
+                setComponents(floor,componentList,"furnColumn","FurnColumn");      //框架柱
+                setComponents(floor,componentList,"stair","Corridor");             //楼道
+
+
+                Floor floor1 = new Floor();
+                floor1.setPoints(pointList);
+                floor1.setWalls(wallList);
+                floor1.setSymbols(symbolList);
+                floor1.setComponents(componentList);
+                floorList.add(floor1);
+            }
+
+            int i = checkPointAndWall(floorList);
+            if(i !=0){
+                return i;
+            }
+            String tag = srcPath.replace("houst_floor.json","");
+            FileWriterUtil.writerJson(tag,"house.json",JSONObject.toJSONString(houseJson));
+        }catch (Exception e){
+            e.printStackTrace();
+            return -3;
+        }
+        return 0;
+    }
+
+
+
+    private static void setComponents(JSONObject floor, List<Component> componentList,String key, String geoType) {
+        JSONArray array = floor.getJSONArray(key);
+        for (Object o : array) {
+            JSONObject obj = (JSONObject) o;
+            JSONArray pos = obj.getJSONArray("pos");
+            String line = obj.getString("line");
+            Component component = new Component();
+            component.setVectorId(geoType+componentList.size());
+            if(line!=null){
+                component.setParent("Wall"+line);
+            }
+            component.setGeoType(geoType);
+            Point point1 = new Point(pos.get(0),pos.get(1));
+            Point point2 = new Point(pos.get(2),pos.get(3));
+            Point point3 = new Point(pos.get(4),pos.get(5));
+            Point point4 = new Point(pos.get(6),pos.get(7));
+            List<Point> pointList = Arrays.asList(point1, point2, point3, point4);
+            component.setVertexes(pointList);
+            componentList.add(component);
+        }
+    }
+
+
+    private static void setSymbol( JSONObject floor, List<Symbol> symbolList,String key,String geoType){
+        JSONArray windows = floor.getJSONArray(key);
+        for (Object windowO : windows) {
+            JSONObject window = (JSONObject) windowO;
+            JSONArray pos = window.getJSONArray("pos");
+            JSONArray ctl = window.getJSONArray("ctl");
+            Integer within = window.getInteger("within");
+            String id = window.getString("id")==null ?symbolList.size()+"" :window.getString("id");
+
+            Symbol symbolInfo = new Symbol();
+            symbolInfo.setParent("Wall"+window.getString("line"));
+            symbolInfo.setGeoType(geoType);
+            symbolInfo.setVectorId(geoType+id);
+            symbolInfo.setStart(new Point(pos.get(0),pos.get(1)));
+            symbolInfo.setEnd(new Point(pos.get(2),pos.get(3)));
+            symbolInfo.setOpenSide("LEFT");
+            if(ctl!=null && ctl.size() >0){
+                Double p = Double.valueOf(pos.get(1).toString());
+                Double d = Double.valueOf(ctl.get(1).toString());
+                if(p >d){
+                    symbolInfo.setOpenSide("RIGHT");
+                }
+            }
+            setDoorOpenSide(symbolInfo,within);
+            symbolList.add(symbolInfo);
+        }
+    }
+    private static void setDoorOpenSide(Symbol symbolInfo, Integer within) {
+        if(within == null){
+            return;
+        }
+        Point start = symbolInfo.getStart();
+        Point end = symbolInfo.getEnd();
+        if(end.getX() >= start.getX() && end.getY() >= start.getY()){
+            if(within == 0 || within ==3){
+                if(start.getX() >=0){
+                    symbolInfo.setOpenSide("LEFT");
+                }else {
+                    symbolInfo.setOpenSide("RIGHT");
+                }
+            }else {
+                if(start.getX() >=0){
+                    symbolInfo.setOpenSide("RIGHT");
+                }else {
+                    symbolInfo.setOpenSide("LEFT");
+                }
+            }
+        }
+        if(end.getX() >= start.getX() && end.getY() < start.getY()){
+            if(within == 0 || within ==3){
+                if(start.getY() >=0){
+                    symbolInfo.setOpenSide("RIGHT");
+                }else {
+                    symbolInfo.setOpenSide("LEFT");
+                }
+            }else {
+                if(start.getY() >=0){
+                    symbolInfo.setOpenSide("LEFT");
+                }else {
+                    symbolInfo.setOpenSide("RIGHT");
+                }
+            }
+
+        }
+        if(end.getX() < start.getX() && end.getY() >= start.getY()){
+            if(within == 0 || within ==3){
+                if(start.getY() >=0){
+                    symbolInfo.setOpenSide("LEFT");
+                }else {
+                    symbolInfo.setOpenSide("RIGHT");
+                }
+            }else {
+                if(start.getY() >=0){
+                    symbolInfo.setOpenSide("RIGHT");
+                }else {
+                    symbolInfo.setOpenSide("LEFT");
+                }
+            }
+        }
+        if(end.getX() < start.getX() && end.getY() < start.getY()){
+            if(within == 0 || within ==3){
+                if(start.getY() >=0){
+                    symbolInfo.setOpenSide("LEFT");
+                }else {
+                    symbolInfo.setOpenSide("RIGHT");
+                }
+            }else {
+                if(start.getY() >=0){
+                    symbolInfo.setOpenSide("RIGHT");
+                }else {
+                    symbolInfo.setOpenSide("LEFT");
+                }
+            }
+        }
+        if(within == 3 || within == 1){
+            if(symbolInfo.getOpenSide().equals("LEFT")){
+                symbolInfo.setOpenSide("RIGHT");
+            }else {
+                symbolInfo.setOpenSide("LEFT");
+            }
+            symbolInfo.setStart(end);
+            symbolInfo.setEnd(start);
+        }
+    }
+
+
+    private static void setPointParent(HashMap<String, List<String>> map, Wall wall, String type){
+        String key = null;
+        if(type.equals("start")){
+            key = wall.getStart();
+        }else {
+            key = wall.getEnd();
+        }
+        List<String> list = map.get(key);
+        if(list == null){
+            list = new ArrayList<>();
+        }
+        list.add(wall.getVectorId()+","+type);
+        map.put(key,list);
+    }
+
+    public static Integer ToHouseJson(String src) {
+        File file = new File(src);
+        Integer bo = -4;
+        if(file.exists() && file.isDirectory()){
+            File[] files = file.listFiles();
+            List<String> fileNameList = new ArrayList<>();
+            for (File file1 : files) {
+                fileNameList.add(file1.getName());
+            }
+            if(fileNameList.contains("houst_floor.json")){
+                log.info("JsonToHouseUtil:houstFloorToHouseJson--->{}",src +File.separator + "houst_floor.json");
+                bo = JsonToHouseUtil.houstFloorToHouseJson(src +File.separator + "houst_floor.json");
+            }else {
+                log.info("JsonToHouseUtil:floorplanCadToHouseJson--->{}",src +File.separator + "houst_floor.json");
+                bo = JsonToHouseUtil.floorplanCadToHouseJson(src +File.separator + "floorplan_cad.json");
+            }
+        }
+        return bo;
+    }
+
+    public static int checkPointAndWall(List<Floor> floors){
+        if(floors.size() <=0){
+            return -1;
+        }
+        Integer wallSize =0;
+        Integer pointSize =0;
+        for (Floor floor : floors) {
+            List<Point> points = floor.getPoints();
+            if(!checkPoint(points)){
+                return -2;
+            }
+            List<Wall> walls = floor.getWalls();
+            wallSize += points.size();
+            pointSize += walls.size();
+        }
+
+        if(wallSize == 0 || pointSize == 0){
+            return -1;
+        }
+        return 0;
+    }
+
+    private static boolean checkPoint(List<Point> pointList) {
+        HashMap<String,Integer> map = new HashMap<>();
+        for (Point point : pointList) {
+            String key = "x:"+point.getX()+"-y:"+point.getY();
+            if(map.get(key) == null){
+                map.put(key,1);
+            }else {
+                return false;
+            }
+        }
+        return true;
+    }
+}

+ 50 - 0
src/main/java/com/fdkankan/scene/common/house/Point.java

@@ -0,0 +1,50 @@
+package com.fdkankan.scene.common.house;
+
+import com.alibaba.fastjson.JSONObject;
+
+public class Point {
+    private Double x;
+    private Double y;
+    private String vectorId;
+    private JSONObject parent;
+
+    public Double getX() {
+        return x;
+    }
+
+    public void setX(Double x) {
+        this.x = x;
+    }
+
+    public Double getY() {
+        return y;
+    }
+
+    public void setY(Double y) {
+        this.y = y;
+    }
+
+    public String getVectorId() {
+        return vectorId;
+    }
+
+    public void setVectorId(String vectorId) {
+        this.vectorId = vectorId;
+    }
+
+    public JSONObject getParent() {
+        return parent;
+    }
+
+    public void setParent(JSONObject parent) {
+        this.parent = parent;
+    }
+
+    public Point() {
+    }
+
+    public Point(Object x, Object y) {
+        this.x = Double.valueOf(x.toString());
+        this.y = Double.valueOf(y.toString());
+    }
+}

+ 58 - 0
src/main/java/com/fdkankan/scene/common/house/Symbol.java

@@ -0,0 +1,58 @@
+package com.fdkankan.scene.common.house;
+
+public class Symbol {
+    private String parent;
+    private String geoType;
+    private Point start;
+    private Point end;
+    private String vectorId;
+    private String openSide;
+
+    public String getParent() {
+        return parent;
+    }
+
+    public void setParent(String parent) {
+        this.parent = parent;
+    }
+
+    public String getGeoType() {
+        return geoType;
+    }
+
+    public void setGeoType(String geoType) {
+        this.geoType = geoType;
+    }
+
+    public Point getStart() {
+        return start;
+    }
+
+    public void setStart(Point start) {
+        this.start = start;
+    }
+
+    public Point getEnd() {
+        return end;
+    }
+
+    public void setEnd(Point end) {
+        this.end = end;
+    }
+
+    public String getVectorId() {
+        return vectorId;
+    }
+
+    public void setVectorId(String vectorId) {
+        this.vectorId = vectorId;
+    }
+
+    public String getOpenSide() {
+        return openSide;
+    }
+
+    public void setOpenSide(String openSide) {
+        this.openSide = openSide;
+    }
+}

+ 40 - 0
src/main/java/com/fdkankan/scene/common/house/Wall.java

@@ -0,0 +1,40 @@
+package com.fdkankan.scene.common.house;
+
+public class Wall {
+    private String start;
+    private String end;
+    private Double width;
+    private String vectorId;
+
+    public String getStart() {
+        return start;
+    }
+
+    public void setStart(String start) {
+        this.start = start;
+    }
+
+    public String getEnd() {
+        return end;
+    }
+
+    public void setEnd(String end) {
+        this.end = end;
+    }
+
+    public Double getWidth() {
+        return width;
+    }
+
+    public void setWidth(Double width) {
+        this.width = width;
+    }
+
+    public String getVectorId() {
+        return vectorId;
+    }
+
+    public void setVectorId(String vectorId) {
+        this.vectorId = vectorId;
+    }
+}

+ 116 - 0
src/main/java/com/fdkankan/scene/controller/Scene3dFamilyController.java

@@ -0,0 +1,116 @@
+package com.fdkankan.scene.controller;
+
+import cn.hutool.core.util.StrUtil;
+import com.dtflys.forest.annotation.Get;
+import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.scene.entity.Scene3dfamily;
+import com.fdkankan.scene.entity.ScenePro;
+import com.fdkankan.scene.service.IScene3dfamilyService;
+import com.fdkankan.scene.service.ISceneProService;
+import com.fdkankan.scene.service.IUserService;
+import com.fdkankan.web.controller.BaseController;
+import com.fdkankan.web.response.Result;
+import com.fdkankan.web.user.SSOUser;
+import java.util.Arrays;
+import java.util.Date;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/**
+ * 三维家
+ */
+@RefreshScope
+@Slf4j
+@RestController
+@RequestMapping("/service/scenev3/threefamily")
+public class Scene3dFamilyController extends BaseController {
+
+    @Autowired
+    private IScene3dfamilyService scene3dFamilyService;
+    @Autowired
+    private ISceneProService sceneProService;
+    @Autowired
+    private IUserService userService;
+
+    @Value("${3d.family.keys:#{null}}")
+    private String[] secrets;
+
+
+    /**
+     *
+     * 三维家 拉取场景数据,压缩zip包
+     */
+    @Get(value = "/scenecpzip")
+    public Result scenecpzip(String sceneNum) throws Exception{
+        String token = getToken();
+        if(StringUtils.isEmpty(token)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3004);
+        }
+        SSOUser ssoUser = this.getSsoUserV3();
+        if(ssoUser == null || ssoUser.getId() == null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3004);
+        }
+
+        if(StrUtil.isEmpty(sceneNum)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
+        }
+
+        ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum);
+        if(sceneProEntity == null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+        }
+
+        //验证是否在打包
+        Scene3dfamily scene3dFamilyEntity = scene3dFamilyService.findSceneNumByNum(sceneProEntity.getNum(),0);
+        if(scene3dFamilyEntity != null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5031);
+        }
+        scene3dFamilyService.updateSceneNumByNum(sceneProEntity);
+
+        //信息入库
+        scene3dFamilyEntity = new Scene3dfamily();
+        scene3dFamilyEntity.setSceneNum(sceneNum);
+        scene3dFamilyEntity.setStatus(0);
+        scene3dFamilyEntity.setZipStartTime(new Date());
+        scene3dFamilyEntity.setCreateUesr(ssoUser.getId());
+        scene3dFamilyEntity.setUpdateUesr(ssoUser.getId());
+        scene3dFamilyService.save(scene3dFamilyEntity);
+
+        scene3dFamilyService.createZip(sceneProEntity, ssoUser.getId());
+
+        return Result.success();
+    }
+
+
+    /**
+     *
+     * 三维家 拉取场景数据,压缩zip包
+     */
+    @RequestMapping(value = "/detail", method = RequestMethod.GET)
+    public Result detail(String sceneNum,String keys) throws Exception{
+
+        if (!ObjectUtils.isEmpty(secrets) && Arrays.asList(secrets).contains(keys)){
+            if(StrUtil.isEmpty(sceneNum)){
+                throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
+            }
+            ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum);
+            if(sceneProEntity == null){
+                throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+            }
+            return Result.success(scene3dFamilyService.findSceneNumByNum2(sceneProEntity));
+        }else{
+            return Result.failure("身份验证失败!");
+        }
+
+    }
+
+}

+ 93 - 0
src/main/java/com/fdkankan/scene/entity/Scene3dfamily.java

@@ -0,0 +1,93 @@
+package com.fdkankan.scene.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * <p>
+ * 三维家表
+ * </p>
+ *
+ * @author 
+ * @since 2022-10-31
+ */
+@Getter
+@Setter
+@TableName("t_scene_3dfamily")
+public class Scene3dfamily implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 场景码
+     */
+    @TableField("scene_num")
+    private String sceneNum;
+
+    /**
+     * zip包存放路径
+     */
+    @TableField("zip_link")
+    private String zipLink;
+
+    /**
+     * 状态 1 - 打包完成  0 - 打包中
+     */
+    @TableField("status")
+    private Integer status;
+
+    /**
+     * 打包开始时间
+     */
+    @TableField("zip_start_time")
+    private Date zipStartTime;
+
+    /**
+     * 打包结束时间
+     */
+    @TableField("zip_end_time")
+    private Date zipEndTime;
+
+    /**
+     * 创建人
+     */
+    @TableField("create_uesr")
+    private Long createUesr;
+
+    /**
+     * 创建时间
+     */
+    @TableField("create_time")
+    private Date createTime;
+
+    /**
+     * 更新人
+     */
+    @TableField("update_uesr")
+    private Long updateUesr;
+
+    /**
+     * 更新时间
+     */
+    @TableField("update_time")
+    private Date updateTime;
+
+    /**
+     * 记录的状态,A: 生效,I: 禁用
+     */
+    @TableField("rec_status")
+    @TableLogic(value = "A", delval = "I")
+    private String recStatus;
+
+
+}

+ 18 - 0
src/main/java/com/fdkankan/scene/mapper/IScene3dfamilyMapper.java

@@ -0,0 +1,18 @@
+package com.fdkankan.scene.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fdkankan.scene.entity.Scene3dfamily;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ * 代理商申请表 Mapper 接口
+ * </p>
+ *
+ * @author 
+ * @since 2022-07-29
+ */
+@Mapper
+public interface IScene3dfamilyMapper extends BaseMapper<Scene3dfamily> {
+
+}

+ 22 - 0
src/main/java/com/fdkankan/scene/service/IScene3dfamilyService.java

@@ -0,0 +1,22 @@
+package com.fdkankan.scene.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.scene.entity.Scene3dfamily;
+import com.fdkankan.scene.entity.ScenePro;
+import com.fdkankan.web.response.Result;
+
+/**
+ * Created by Hb_zzZ on 2019/7/23.
+ */
+public interface IScene3dfamilyService extends IService<Scene3dfamily> {
+
+    Result createZip(ScenePro sceneProEntity,long userId) throws Exception;
+
+    Scene3dfamily findSceneNumByNum(String num,Integer status);
+
+    JSONObject findSceneNumByNum2(ScenePro sceneProEntity);
+
+    void updateSceneNumByNum (ScenePro sceneProEntity);
+
+}

+ 280 - 0
src/main/java/com/fdkankan/scene/service/impl/Scene3dfamilyServiceImpl.java

@@ -0,0 +1,280 @@
+package com.fdkankan.scene.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ZipUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.constant.RecStatus;
+import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import com.fdkankan.model.constants.ConstantFilePath;
+import com.fdkankan.model.utils.CreateObjUtil;
+import com.fdkankan.scene.bean.EulerAngles;
+import com.fdkankan.scene.bean.ResponseScene;
+import com.fdkankan.scene.common.house.JsonToHouseUtil;
+import com.fdkankan.scene.entity.Scene3dfamily;
+import com.fdkankan.scene.entity.ScenePro;
+import com.fdkankan.scene.mapper.IScene3dfamilyMapper;
+import com.fdkankan.scene.service.IScene3dfamilyService;
+import com.fdkankan.scene.service.ISceneProService;
+import com.fdkankan.web.response.Result;
+import com.fdkankan.web.response.ResultData;
+import java.io.File;
+import java.io.FileWriter;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+/**
+ * Created by Hb_zzZ on 2019/6/28.
+ */
+@Slf4j
+@Service
+public class Scene3dfamilyServiceImpl extends ServiceImpl<IScene3dfamilyMapper, Scene3dfamily> implements IScene3dfamilyService {
+
+    private static String DIR_NAME = "downloads/furnished/";
+
+
+    @Autowired
+    private ISceneProService sceneProService;
+
+    @Autowired
+    private FYunFileServiceInterface fYunFileService;
+
+    @Value("${fyun.host}")
+    private String fyunHost;
+
+    @Override
+    public Result createZip(ScenePro sceneProEntity,long userId) throws Exception{
+
+        Scene3dfamily scene3dFamilyEntity = this.findSceneNumByNum(sceneProEntity.getNum(),0);
+        String path = sceneProEntity.getDataSource() + "_3df" + File.separator + sceneProEntity.getNum();
+        try {
+            if(scene3dFamilyEntity == null){
+                throw new BusinessException(ErrorCode.FAILURE_CODE_5032);
+            }
+
+            log.info("三维家 信息保存 路径 : " + path);
+            //创建文件夹
+            FileUtils.createDir(path);
+
+            //生成vision.json
+            this.downloadVisionData(sceneProEntity);
+
+            String dataBuf = "data" + File.separator + "data" + sceneProEntity.getNum() + File.separator;
+            this.visionTxtToPano(ConstantFilePath.SCENE_PATH + dataBuf //本地路径
+                    + "vision.json",path+ File.separator +"scene"+ File.separator+ dataBuf );
+
+            //拉取data
+            CreateObjUtil.ossUtilCp("data" + File.separator + "data" + sceneProEntity.getNum()  + File.separator,
+                    path + File.separator + "scene" + File.separator + "data" + File.separator + "data" + sceneProEntity.getNum());
+
+            //转换house.json
+            Integer bo = JsonToHouseUtil.ToHouseJson(path + File.separator + "scene" + File.separator + dataBuf);
+
+            if(bo!=0){
+                switch (bo){
+                    case -1:
+                        throw new BusinessException(ErrorCode.FAILURE_CODE_5029.code(), "点位数据为空");
+                    case -2:
+                        throw new BusinessException(ErrorCode.FAILURE_CODE_5029.code(), "点位数据重复");
+                    case -3:
+                        throw new BusinessException(ErrorCode.FAILURE_CODE_5029.code(), "转换异常");
+                    case -4:
+                        throw new BusinessException(ErrorCode.FAILURE_CODE_5029.code(), "源文件不存在");
+                }
+            }
+
+            //写入 scene.json 改名为 getinfo.json
+            ResultData result = sceneProService.getInfo(sceneProEntity.getNum());
+            ResponseScene responseScene = (ResponseScene) result.getData();
+
+            JSONObject dataJson = (JSONObject) JSONObject.toJSON(responseScene);
+
+            FileUtils.writeFile(path + File.separator + "scene"  + File.separator + "data" +  File.separator  + "data"
+                                      + sceneProEntity.getNum() + File.separator + "getinfo.json", dataJson.toString());
+
+            //下载场景封面图
+            String ossImagePath =  "images" + File.separator + "images" + sceneProEntity.getNum() + File.separator;
+            String ImagePath = path + File.separator + "scene"  + File.separator + "images" + File.separator + "images" + sceneProEntity.getNum();
+            FileUtils.downLoadFromUrl(sceneProEntity.getThumb(),"cover.jpg", ImagePath);
+
+            //拉取images
+            fYunFileService.downloadFile(ossImagePath + "floorLogoImg.png", ImagePath + "/floorLogoImg.png");
+            fYunFileService.downloadFile(ossImagePath + "floorplan.png", ImagePath + "/floorplan.png");
+            fYunFileService.downloadFile(ossImagePath + "logo-main.png", ImagePath + "/logo-main.png");
+            fYunFileService.downloadFile(ossImagePath + "logo-main-en.png", ImagePath + "/logo-main-en.png");
+            fYunFileService.downloadFile(ossImagePath + "smallPic.jpg", ImagePath + "/smallPic.jpg");
+            fYunFileService.downloadFile(ossImagePath + "thumbBigImg.jpg", ImagePath + "/thumbBigImg.jpg");
+            fYunFileService.downloadFile(ossImagePath + "thumbSmallImg.jpg", ImagePath + "/thumbSmallImg.jpg");
+            fYunFileService.downloadFileByCommand(ImagePath + "/pan", ossImagePath + "pan");
+
+            // 异步执行
+            CompletableFuture.runAsync(()->{
+                //压缩zip
+                try {
+                    log.info("开始异步执行打包逻辑……");
+                    //获取六面体图
+                    fYunFileService.downloadFileByCommand(ImagePath + "/tiles", ossImagePath + "tiles");
+
+                    //拉取video
+                    fYunFileService.downloadFileByCommand(path + File.separator + "scene"  + File.separator + "video" + File.separator + "video" + sceneProEntity.getNum(),
+                        "video" + File.separator + "video" + sceneProEntity.getNum()  + File.separator);
+
+                    //拉取voice
+                    fYunFileService.downloadFileByCommand(path + File.separator + "scene"  + File.separator + "voice" + File.separator + "voice" + sceneProEntity.getNum(),
+                        "voice" + File.separator + "voice" + sceneProEntity.getNum()  + File.separator);
+
+                    ZipUtil.zip(path, path + ".zip");
+
+                    log.info("三维家 zip完成 : " + path);
+
+                    //上传oss
+                    // 上传到阿里云sso
+                    fYunFileService.uploadFileByCommand(path + ".zip", DIR_NAME + sceneProEntity.getNum() + ".zip");
+                    log.info("upload success");
+
+                    String url = fyunHost + DIR_NAME + sceneProEntity.getNum() + ".zip";
+
+                    log.info("upload url: {}" + url);
+
+                    scene3dFamilyEntity.setZipLink(url);
+                    scene3dFamilyEntity.setStatus(1);
+                    scene3dFamilyEntity.setZipEndTime(new Date());
+                    scene3dFamilyEntity.setUpdateTime(new Date());
+                    this.updateById(scene3dFamilyEntity);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    scene3dFamilyEntity.setStatus(2);
+                    scene3dFamilyEntity.setZipEndTime(new Date());
+                    scene3dFamilyEntity.setUpdateTime(new Date());
+                    this.updateById(scene3dFamilyEntity);
+                }finally {
+                    FileUtils.deleteDirectory(path);
+                    FileUtils.deleteFile(path + ".zip");
+                }
+            });
+        }catch (Exception e){
+            scene3dFamilyEntity.setStatus(2);
+            scene3dFamilyEntity.setZipEndTime(new Date());
+            scene3dFamilyEntity.setUpdateTime(new Date());
+            this.updateById(scene3dFamilyEntity);
+            e.printStackTrace();
+            throw e;
+        }
+        return Result.success();
+    }
+
+
+    @Override
+    public Scene3dfamily findSceneNumByNum(String num,Integer status){
+        LambdaQueryWrapper<Scene3dfamily> wrapper = new LambdaQueryWrapper<Scene3dfamily>()
+            .eq(Scene3dfamily::getSceneNum, num);
+        if(status != null){
+           wrapper.eq(Scene3dfamily::getStatus, status);
+        }
+        List<Scene3dfamily> list = this.list(wrapper);
+        if(CollUtil.isEmpty(list)){
+            return null;
+        }
+        return list.get(0);
+    }
+
+    @Override
+    public JSONObject findSceneNumByNum2(ScenePro sceneProEntity){
+
+        JSONObject jsonObject = new JSONObject();
+        Scene3dfamily scene3dFamilyEntity = this.findSceneNumByNum(sceneProEntity.getNum(), null);
+        if(scene3dFamilyEntity!=null){
+            jsonObject.put("url",scene3dFamilyEntity.getZipLink() == null ?"":scene3dFamilyEntity.getZipLink());
+            jsonObject.put("status",scene3dFamilyEntity.getStatus());
+        }else{
+            jsonObject.put("url","");
+            jsonObject.put("status",3);
+        }
+        //验证是否在打包
+        return jsonObject;
+    }
+
+    @Override
+    public void updateSceneNumByNum (ScenePro sceneProEntity){
+        this.update(new LambdaUpdateWrapper<Scene3dfamily>().set(Scene3dfamily::getRecStatus,
+            RecStatus.DISABLE.code()).eq(Scene3dfamily::getSceneNum, sceneProEntity.getNum()));
+    }
+
+    private void downloadVisionData(ScenePro sceneProEntity) throws Exception {
+        StringBuffer dataBuf = new StringBuffer().append("data").append(File.separator)
+            .append("data").append(sceneProEntity.getNum()).append(File.separator);
+
+        StringBuffer imagesBuf = new StringBuffer().append("images").append(File.separator)
+            .append("images").append(sceneProEntity.getNum()).append(File.separator);
+
+        StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
+        StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
+
+        fYunFileService.downloadFile(imagesBuf.toString() + "vision.modeldata", dataBuffer.toString() + "vision.modeldata");
+
+        File file = new File(dataBuffer.toString() + "vision.modeldata");
+        if(!file.exists()) {
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
+        }
+        CreateObjUtil.convertVisionmodeldataToTxt(dataBuffer.toString() + "vision.modeldata", dataBuffer.toString() + "vision.json");
+
+        fYunFileService.uploadFile(dataBuffer.toString() + "vision.json", dataBuf.toString() + "vision.json");
+    }
+
+    /**
+     *
+     * @param src   vision.json 路径
+     * @param tag   pano.json 目录路径
+     */
+    private void visionTxtToPano(String src,String tag){
+        try {
+            log.info("QuaternionToEulerUtil---------src:{},tag:{}",src,tag);
+            String str = FileUtil.readUtf8String(src);
+            JSONObject jsonObject = JSONObject.parseObject(str);
+            JSONArray sweepLocations = jsonObject.getJSONArray("sweepLocations");
+            for (Object o : sweepLocations) {
+                JSONObject obj = (JSONObject) o;
+                JSONObject pose = obj.getJSONObject("pose");
+                JSONObject rotation = pose.getJSONObject("rotation");
+                JSONObject translation = pose.getJSONObject("translation");
+                Double w = rotation.getDouble("w");
+                Double x = rotation.getDouble("x");
+                Double y = rotation.getDouble("y");
+                Double z = rotation.getDouble("z");
+                Double x1 = translation.getDouble("x");
+                Double y1 = translation.getDouble("y");
+                Double z1 = translation.getDouble("z");
+                JSONObject newRotation = new JSONObject();
+                EulerAngles eulerAngles = new EulerAngles(w,x,y,z,x1,y1,z1);
+                newRotation.put("x",eulerAngles.x);
+                newRotation.put("y",eulerAngles.y);
+                newRotation.put("z",eulerAngles.z);
+                pose.put("target",newRotation);
+                pose.remove("rotation");
+            }
+            File file = new File(tag);
+            if(!file.exists()){
+                file.mkdirs();
+            }
+            FileWriter fw = new FileWriter(tag+ "pano.json");
+            fw.write(jsonObject.toJSONString());
+            fw.close();
+        }catch (Exception e){
+            log.error("QuaternionToEulerUtil---------error:",e);
+            e.printStackTrace();
+        }
+
+    }
+}