|
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ArrayUtil;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.BreakpointsEntity;
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.BreakpointsEntity;
|
|
|
|
+import com.fdkk.fdkkmeta.domain.entity.mysql.MoveFrameEntity;
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.RotateFrameEntity;
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.RotateFrameEntity;
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.UserEntity;
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.UserEntity;
|
|
import com.fdkk.fdkkmeta.domain.po.*;
|
|
import com.fdkk.fdkkmeta.domain.po.*;
|
|
@@ -11,13 +12,17 @@ import com.fdkk.fdkkmeta.grpc.*;
|
|
import com.fdkk.fdkkmeta.grpcService.SceneGrpcService;
|
|
import com.fdkk.fdkkmeta.grpcService.SceneGrpcService;
|
|
import com.fdkk.fdkkmeta.redis.RedisCache;
|
|
import com.fdkk.fdkkmeta.redis.RedisCache;
|
|
import com.fdkk.fdkkmeta.service.BreakpointsService;
|
|
import com.fdkk.fdkkmeta.service.BreakpointsService;
|
|
|
|
+import com.fdkk.fdkkmeta.service.MoveFrameService;
|
|
import com.fdkk.fdkkmeta.service.UserService;
|
|
import com.fdkk.fdkkmeta.service.UserService;
|
|
import com.fdkk.fdkkmeta.service.RotateFrameService;
|
|
import com.fdkk.fdkkmeta.service.RotateFrameService;
|
|
|
|
+import com.fdkk.fdkkmeta.util.kesar.GetRoute;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -34,6 +39,8 @@ public class UpdateFrameMetaTask {
|
|
@Autowired
|
|
@Autowired
|
|
RotateFrameService rotateFrameService;
|
|
RotateFrameService rotateFrameService;
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ MoveFrameService moveFrameService;
|
|
|
|
+ @Autowired
|
|
SceneGrpcService sceneGrpcService;
|
|
SceneGrpcService sceneGrpcService;
|
|
@Autowired
|
|
@Autowired
|
|
BreakpointsService breakpointsService;
|
|
BreakpointsService breakpointsService;
|
|
@@ -48,11 +55,74 @@ public class UpdateFrameMetaTask {
|
|
userEntity -> {
|
|
userEntity -> {
|
|
//UserEntity user = redisCache.getCacheObject("setCacheRequest:" + userEntity.getUserId());
|
|
//UserEntity user = redisCache.getCacheObject("setCacheRequest:" + userEntity.getUserId());
|
|
// redisCache.set("updateFrameMetadata:"+userEntity.getUserId(),a.toJSONString());
|
|
// redisCache.set("updateFrameMetadata:"+userEntity.getUserId(),a.toJSONString());
|
|
|
|
+ String userId = userEntity.getUserId();
|
|
|
|
+ handle( userId);
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ private void handle(String userId){
|
|
|
|
+ List<MovePO> list = redisCache.getCacheList("setCacheRequest:move:"+userId);
|
|
|
|
+ if(list.size() == 0){
|
|
|
|
+ createMetaDataForRotate(userId);
|
|
|
|
+ createMetaDataForJoystick(userId);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ MovePO movePO = list.get(0);
|
|
|
|
+ UserEntity user = userService.findUserId(userId);
|
|
|
|
+ //true表示可以过渡了,false表示需要继续旋转
|
|
|
|
+ boolean flag = movePO.isRotated();
|
|
|
|
+ if(!flag){
|
|
|
|
+ boolean flag_rotated = rotateForMove( user, movePO);
|
|
|
|
+ if(flag_rotated) {
|
|
|
|
+ //矫正完成
|
|
|
|
+ movePO.setRotated(true);
|
|
|
|
+ }
|
|
|
|
+ //设置
|
|
|
|
+ /*********************************************************************************************/
|
|
|
|
+ //redisCache.setCacheList("setCacheRequest:move:"+userId, Arrays.asList(movePO));
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //可以过渡了
|
|
|
|
+ else {
|
|
|
|
+ flag = movePO.isMoving();
|
|
|
|
+ //打断
|
|
|
|
+ if(list.size()>1){
|
|
|
|
+ //删除第一个元素
|
|
|
|
+ /*********************************************************************************************/
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //还没开始过渡,只是打算过渡
|
|
|
|
+ if(!flag) {
|
|
|
|
+ flag = createMetaDataForRotate(userId);
|
|
|
|
+ if(!flag){
|
|
|
|
+ flag = createMetaDataForJoystick(userId);
|
|
|
|
+ }
|
|
|
|
+ if(!flag){
|
|
|
|
+ //开始过渡
|
|
|
|
+ movePO.setMoving(true);
|
|
|
|
+ //过渡中
|
|
|
|
+ /*********************************************************************************************/
|
|
|
|
+ }
|
|
|
|
+ //有旋转/操作的动作,所以打断了过渡
|
|
|
|
+ else{
|
|
|
|
+ //删除第一个元素
|
|
|
|
+ /*********************************************************************************************/
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ //开始过渡
|
|
|
|
+ movePO.setMoving(true);
|
|
|
|
+ //过渡中
|
|
|
|
+ /*********************************************************************************************/
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private boolean createMetaDataForRotate(String userId){
|
|
private boolean createMetaDataForRotate(String userId){
|
|
List<RotatePO> list = redisCache.getCacheList("setCacheRequest:rotate:"+userId);
|
|
List<RotatePO> list = redisCache.getCacheList("setCacheRequest:rotate:"+userId);
|
|
UserEntity user = userService.findUserId(userId);
|
|
UserEntity user = userService.findUserId(userId);
|
|
@@ -82,6 +152,9 @@ public class UpdateFrameMetaTask {
|
|
else{
|
|
else{
|
|
currentFrame = currentFrame % 359;
|
|
currentFrame = currentFrame % 359;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ setRotate( user, traceIds, actionResponses, currentFrame);
|
|
|
|
+ /*
|
|
rotateFrameEntity = rotateFrameService.findByAppIdAndBreakPointIdAndFrameIndex(user.getAppId(),user.getBreakPointId(),currentFrame);
|
|
rotateFrameEntity = rotateFrameService.findByAppIdAndBreakPointIdAndFrameIndex(user.getAppId(),user.getBreakPointId(),currentFrame);
|
|
PointPO playerPosition = user.getPlayerPosition();
|
|
PointPO playerPosition = user.getPlayerPosition();
|
|
Point playerPt = Point.newBuilder().setX(String.valueOf(playerPosition.getX())).setY(String.valueOf(playerPosition.getY())).setZ(String.valueOf(playerPosition.getZ())).build();
|
|
Point playerPt = Point.newBuilder().setX(String.valueOf(playerPosition.getX())).setY(String.valueOf(playerPosition.getY())).setZ(String.valueOf(playerPosition.getZ())).build();
|
|
@@ -113,15 +186,34 @@ public class UpdateFrameMetaTask {
|
|
metaDataFramePO.setMsg("");
|
|
metaDataFramePO.setMsg("");
|
|
|
|
|
|
redisCache.setCacheObject("updateFrameMetadata:"+userId,metaDataFramePO);
|
|
redisCache.setCacheObject("updateFrameMetadata:"+userId,metaDataFramePO);
|
|
|
|
+ */
|
|
//删除操作数据
|
|
//删除操作数据
|
|
- //redisCache.delete("setCacheRequest:rotate:"+userId);
|
|
|
|
|
|
+ redisCache.delete("setCacheRequest:rotate:"+userId);
|
|
|
|
+ //更新user表
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- private void createMetaDataForMove(){
|
|
|
|
-
|
|
|
|
|
|
+ private boolean createMetaDataForMove(String userId){
|
|
|
|
+ List<MovePO> list = redisCache.getCacheList("setCacheRequest:move:"+userId);
|
|
|
|
+ if(list.size()>0){
|
|
|
|
+ MovePO movePO = list.get(list.size()-1);
|
|
|
|
+ UserEntity user = userService.findUserId(userId);
|
|
|
|
+ JSONArray path = movePO.getPath();
|
|
|
|
+ //true表示可以过渡了,false表示需要继续旋转
|
|
|
|
+ boolean flag = rotateForMove( user,movePO);
|
|
|
|
+ if(flag){
|
|
|
|
+ //打断
|
|
|
|
+ /*********************************************************************************************/
|
|
|
|
+ //开始过渡
|
|
|
|
+ movePO.setMoving(true);
|
|
|
|
+ //过渡中
|
|
|
|
+ /*********************************************************************************************/
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
private boolean createMetaDataForJoystick(String userId){
|
|
private boolean createMetaDataForJoystick(String userId){
|
|
@@ -201,11 +293,145 @@ public class UpdateFrameMetaTask {
|
|
}
|
|
}
|
|
|
|
|
|
//开始过渡
|
|
//开始过渡
|
|
|
|
+ //更新user表
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setRotate(UserEntity user,String[] traceIds,JSONArray actionResponses,int currentFrame){
|
|
|
|
+ RotateFrameEntity rotateFrameEntity = rotateFrameService.findByAppIdAndBreakPointIdAndFrameIndex(user.getAppId(),user.getBreakPointId(),currentFrame);
|
|
|
|
+ PointPO playerPosition = user.getPlayerPosition();
|
|
|
|
+ Point playerPt = Point.newBuilder().setX(String.valueOf(playerPosition.getX())).setY(String.valueOf(playerPosition.getY())).setZ(String.valueOf(playerPosition.getZ())).build();
|
|
|
|
+ AnglePO playerAngle = user.getPlayerAngle();
|
|
|
|
+ AngleUe4 playerAg =AngleUe4.newBuilder().setPitch(playerAngle.getPitch()).setYaw(playerAngle.getYaw()).setRoll(playerAngle.getRoll()).build();
|
|
|
|
+ Space player = sceneGrpcService.createSpace(playerPt,playerAg);
|
|
|
|
|
|
|
|
+ PointPO cameraPoint = rotateFrameEntity.getCameraPosition();
|
|
|
|
+ Point cameraPosition = sceneGrpcService.createPoint(String.valueOf(cameraPoint.getX()),String.valueOf(cameraPoint.getY()),String.valueOf(cameraPoint.getZ()));
|
|
|
|
+ AnglePO cameraAnglePO = rotateFrameEntity.getCameraAngle();
|
|
|
|
+ AngleUe4 cameraAngle = sceneGrpcService.createAngle(cameraAnglePO.getPitch(),cameraAnglePO.getYaw(),cameraAnglePO.getRoll());
|
|
|
|
+ Space camera = sceneGrpcService.createSpace(cameraPosition,cameraAngle);
|
|
|
|
|
|
|
|
+ MetaDataFramePO metaDataFramePO = new MetaDataFramePO();
|
|
|
|
+ metaDataFramePO.setTraceIds(traceIds);
|
|
|
|
+ metaDataFramePO.setVehicle(null);
|
|
|
|
+ State playerState = sceneGrpcService.createPlayerState2(player,camera,playerPt);
|
|
|
|
+
|
|
|
|
+ RenderInfo renderInfo = sceneGrpcService.createRenderInfo();
|
|
|
|
+ UserState userState = sceneGrpcService.createUserState( user.getUserId(), playerState, renderInfo, null);
|
|
|
|
+
|
|
|
|
+ //newUserStates
|
|
|
|
+ JSONArray newUserStates = new JSONArray();
|
|
|
|
+ newUserStates.add(userState);
|
|
|
|
+ metaDataFramePO.setNewUserStates(newUserStates);
|
|
|
|
+ metaDataFramePO.setActionResponses(actionResponses);
|
|
|
|
+ metaDataFramePO.setGetStateType(0);
|
|
|
|
+ metaDataFramePO.setCode(0);
|
|
|
|
+ metaDataFramePO.setMsg("");
|
|
|
|
+
|
|
|
|
+ redisCache.setCacheObject("updateFrameMetadata:"+user.getUserId(),metaDataFramePO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //过渡前先纠正角度,走第一段的时候才需要纠正
|
|
|
|
+ private boolean rotateForMove(UserEntity user,MovePO movePO){
|
|
|
|
+ String traceId = movePO.getTrace_id();
|
|
|
|
+ int actionType = movePO.getAction_type();
|
|
|
|
+ long startBreakPointId = user.getFrameId();
|
|
|
|
+ long endBreakPointId = movePO.getPath().getLong(0);
|
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
|
+ JSONArray players = new JSONArray();
|
|
|
|
+ JSONArray cameras = new JSONArray();
|
|
|
|
+ JSONArray cameraCenters = new JSONArray();
|
|
|
|
+
|
|
|
|
+ BreakpointsEntity startBreakpointsEntity = breakpointsService.findByAppIdAndBreakPointId(user.getAppId(),startBreakPointId);
|
|
|
|
+ BreakpointsEntity endBreakpointsEntity = breakpointsService.findByAppIdAndBreakPointId(user.getAppId(),endBreakPointId);
|
|
|
|
+
|
|
|
|
+ PointPO startPosition = startBreakpointsEntity.getPosition();
|
|
|
|
+ PointPO endPosition = endBreakpointsEntity.getPosition();
|
|
|
|
+
|
|
|
|
+ PointPO temp = new PointPO();
|
|
|
|
+ temp.setX(startPosition.getX()+1);
|
|
|
|
+ temp.setY(startPosition.getY());
|
|
|
|
+ temp.setZ(startPosition.getZ());
|
|
|
|
+ int angle = (int)sceneGrpcService.calAngle(startPosition, temp, endPosition);
|
|
|
|
+ AnglePO anglePO = user.getPlayerAngle();
|
|
|
|
+ AngleUe4 playerAg =AngleUe4.newBuilder().setPitch(anglePO.getPitch()).setYaw(anglePO.getYaw()+angle).setRoll(anglePO.getRoll()).build();
|
|
|
|
+ PointPO playerPosition = user.getPlayerPosition();
|
|
|
|
+ Point playerPt = Point.newBuilder().setX(String.valueOf(playerPosition.getX())).setY(String.valueOf(playerPosition.getY())).setZ(String.valueOf(playerPosition.getZ())).build();
|
|
|
|
+ Space player = sceneGrpcService.createSpace(playerPt,playerAg);
|
|
|
|
+
|
|
|
|
+ //相机
|
|
|
|
+ RotateFrameEntity rotateFrameEntity = rotateFrameService.findById(user.getFrameId());
|
|
|
|
+ AnglePO cameraAnglePO = rotateFrameEntity.getCameraAngle();
|
|
|
|
+ angle = cameraAnglePO.getYaw();
|
|
|
|
+ int offAngle = 0;
|
|
|
|
+ offAngle = angle%45;
|
|
|
|
+ if(offAngle == 0){
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ int currentFrame = angle;
|
|
|
|
+ if(offAngle>45-offAngle) {
|
|
|
|
+ ++currentFrame;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ --currentFrame;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ String[] traceIds = new String[1];
|
|
|
|
+ traceIds[0] = traceId;
|
|
|
|
+ JSONArray actionResponses = new JSONArray();
|
|
|
|
+ JSONObject actionResponse = sceneGrpcService.createActionResponse(actionType,traceId);
|
|
|
|
+ actionResponses.add(actionResponse);
|
|
|
|
+
|
|
|
|
+ setRotate( user, traceIds, actionResponses, currentFrame);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //点对点开始移动
|
|
|
|
+ private JSONObject movePointToPoint(String userId,int angle,long startBreakPointId,long endBreakPointId){
|
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
|
+ JSONArray players = new JSONArray();
|
|
|
|
+ JSONArray cameras = new JSONArray();
|
|
|
|
+ JSONArray cameraCenters = new JSONArray();
|
|
|
|
+
|
|
|
|
+ UserEntity user = userService.findUserId(userId);
|
|
|
|
+ List<MoveFrameEntity> list = moveFrameService.findByAppIAndStartBreakPointIdAndEndBreakPointIdAndAngle(user.getAppId(),startBreakPointId,endBreakPointId,angle);
|
|
|
|
+
|
|
|
|
+ BreakpointsEntity startBreakpointsEntity = breakpointsService.findByAppIdAndBreakPointId(user.getAppId(),startBreakPointId);
|
|
|
|
+ PointPO startPosition = startBreakpointsEntity.getPosition();
|
|
|
|
+
|
|
|
|
+ BreakpointsEntity endBreakpointsEntity = breakpointsService.findByAppIdAndBreakPointId(user.getAppId(),endBreakPointId);
|
|
|
|
+ PointPO endPosition = endBreakpointsEntity.getPosition();
|
|
|
|
+
|
|
|
|
+ for(int i=0;i<list.size();++i){
|
|
|
|
+ MoveFrameEntity moveFrameEntity = list.get(i);
|
|
|
|
+ //PointPO playerPosition = user.getPlayerPosition();
|
|
|
|
+ PointPO position = new PointPO();
|
|
|
|
+ position.setX(startPosition.getX()+(endPosition.getX()-startPosition.getX())/list.size()*i);
|
|
|
|
+ position.setY(startPosition.getY()+(endPosition.getY()-startPosition.getY())/list.size()*i);
|
|
|
|
+ position.setZ(startPosition.getZ()+(endPosition.getZ()-startPosition.getZ())/list.size()*i);
|
|
|
|
+
|
|
|
|
+ Point playerPt = Point.newBuilder().setX(String.valueOf(position.getX())).setY(String.valueOf(position.getY())).setZ(String.valueOf(position.getZ())).build();
|
|
|
|
+ AnglePO playerAngle = user.getPlayerAngle();
|
|
|
|
+ AngleUe4 playerAg =AngleUe4.newBuilder().setPitch(playerAngle.getPitch()).setYaw(playerAngle.getYaw()).setRoll(playerAngle.getRoll()).build();
|
|
|
|
+ Space player = sceneGrpcService.createSpace(playerPt,playerAg);
|
|
|
|
+ players.add(player);
|
|
|
|
+
|
|
|
|
+ PointPO cameraPoint = moveFrameEntity.getCameraPosition();
|
|
|
|
+ Point cameraPosition = sceneGrpcService.createPoint(String.valueOf(cameraPoint.getX()),String.valueOf(cameraPoint.getY()),String.valueOf(cameraPoint.getZ()));
|
|
|
|
+ AnglePO cameraAnglePO = moveFrameEntity.getCameraAngle();
|
|
|
|
+ AngleUe4 cameraAngle = sceneGrpcService.createAngle(cameraAnglePO.getPitch(),cameraAnglePO.getYaw(),cameraAnglePO.getRoll());
|
|
|
|
+ Space camera = sceneGrpcService.createSpace(cameraPosition,cameraAngle);
|
|
|
|
+ cameras.add(camera);
|
|
|
|
+
|
|
|
|
+ cameraCenters.add(playerPt);
|
|
|
|
+ }
|
|
|
|
+ result.put("players",players);
|
|
|
|
+ result.put("cameras",cameras);
|
|
|
|
+ result.put("cameraCenters",cameraCenters);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
/*
|
|
/*
|
|
* {
|
|
* {
|
|
"traceIds": ["d0864cd0-378d-4d49-b7b0-3e8e1b9494c3", "d0864cd0-378d-4d49-b7b0-3e8e1b9494c3", "939087ff-4999-4551-92e4-26ecb67f8aa2"],
|
|
"traceIds": ["d0864cd0-378d-4d49-b7b0-3e8e1b9494c3", "d0864cd0-378d-4d49-b7b0-3e8e1b9494c3", "939087ff-4999-4551-92e4-26ecb67f8aa2"],
|