ソースを参照

像素流改造

baixuanda 2 ヶ月 前
コミット
a7876ae706

+ 2 - 2
WebVue/TaiHufenglang/package-lock.json

@@ -564,7 +564,7 @@
     },
     "node_modules/@epicgames-ps/lib-pixelstreamingfrontend-ue5.2": {
       "version": "0.5.8",
-      "resolved": "https://registry.npmjs.org/@epicgames-ps/lib-pixelstreamingfrontend-ue5.2/-/lib-pixelstreamingfrontend-ue5.2-0.5.8.tgz",
+      "resolved": "https://mirrors.huaweicloud.com/repository/npm/@epicgames-ps/lib-pixelstreamingfrontend-ue5.2/-/lib-pixelstreamingfrontend-ue5.2-0.5.8.tgz",
       "integrity": "sha512-mVh05FFFRNc0VQy95V2mgISLDHIoYZyvspsw5GiaG9RZN5uEhR+YPCm/WvvKOatwqAlR7XOZ1sml1Lj1ymz7eQ==",
       "license": "MIT",
       "dependencies": {
@@ -573,7 +573,7 @@
     },
     "node_modules/@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2": {
       "version": "0.4.9",
-      "resolved": "https://registry.npmjs.org/@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2/-/lib-pixelstreamingfrontend-ui-ue5.2-0.4.9.tgz",
+      "resolved": "https://mirrors.huaweicloud.com/repository/npm/@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2/-/lib-pixelstreamingfrontend-ui-ue5.2-0.4.9.tgz",
       "integrity": "sha512-ZKNp1anSurKeQd4u+0cRoR1HHhp/ee9SUFfOHJSx3Pqd7/6leAr7up1km0ZJVJnVcC89++WOnLU6InQb9T3TrQ==",
       "license": "MIT",
       "dependencies": {

+ 4 - 3
WebVue/TaiHufenglang/src/components/MapContainer.vue

@@ -8,9 +8,10 @@
       <Rightmoudle />
     </div>
   </div>
-  <Cesium />  
-   <!-- <UEpix /> -->
+  <!-- <Cesium />   -->
+  <PixelStreaming ss="http://101.227.236.189:85/"/>  
 </template>
+ 
 
 
 <script setup>
@@ -21,7 +22,7 @@ import Leftmoudle from './leftmodul.vue'
 import Rightmoudle from './rightmodul.vue'
 import Middlemoudle from './middlemodul.vue'
 import Cesium from './Cesium.vue'
-// import UEpix from './UEpix.vue'
+import PixelStreaming from './UEpix.vue'
 </script>
 
 <style scoped></style>

+ 125 - 43
WebVue/TaiHufenglang/src/components/UEpix.vue

@@ -1,47 +1,129 @@
+<script setup>
+// npm i @epicgames-ps/lib-pixelstreamingfrontend-ue5.2 @epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2
+import {
+  Config,
+  PixelStreaming,
+} from "@epicgames-ps/lib-pixelstreamingfrontend-ue5.2";
+import {
+  Application,
+  PixelStreamingApplicationStyle,
+} from "@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2";
+import { onMounted } from "vue";
+import { ref } from "vue";
+const props = defineProps({
+  ss: {
+    type: String,
+    default: "ws://127.0.0.1/",
+  },
+});
+
+const loading = ref(true);
+
+const emitter = defineEmits(["receiveMessage", "loaded"]);
+let ueWebEmitter = null;
+const pixelStreamingContainerRef = ref(null);
+
+const STATE = {
+  stream: null,
+  application: null,
+};
+
+const initPixelStreaming = () => {
+  // 控制UI样式(在这里去除了设置按钮)
+  const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle({
+    customStyles: {
+      "#uiFeatures": {
+        display: "none",
+      },
+    },
+  });
+  PixelStreamingApplicationStyles.applyStyleSheet();
+
+  // 像素流播放的一些配置
+  const config = new Config({
+    useUrlParams: true,
+    initialSettings: {
+      ss: props.ss, // 流媒体服务器地址
+      AutoConnect: true, // 自动连接:如果为 true,应用启动时会自动连接到流媒体服务器。
+      AutoPlayVideo: true, // 自动播放视频:如果为 true,在连接成功后视频将自动播放。
+      StartVideoMuted: true, // 启动时静音:如果为 true,视频在开始播放时会处于静音状态。
+      KeyboardInput: false, // 键盘输入:如果为 true,允许使用键盘进行控制。
+      MinQP: 15, // 最小量化参数:用于控制视频编码的最小质量水平,数值越低,品质越好,但带宽消耗也越大。
+      XRControllerInput: false, // XR 控制器输入:如果为 true,允许 XR(虚拟现实)控制器的输入。
+      GamepadInput: false, // 游戏手柄输入:如果为 true,允许使用游戏手柄进行控制。
+      TouchInput: false, // 触摸输入:如果为 true,允许在触摸屏设备上进行交互。
+      HoveringMouse: true, // 鼠标悬停:如果为 true,允许鼠标悬停并与 UI 进行交互。
+      HoveringMouseMode: true, // 鼠标悬停模式:如果为 true,激活鼠标悬停模式以增强 UI 交互体验。
+      SuppressBrowserKeys: false, // 抑制浏览器按键:如果为 true,将抑制浏览器的某些键盘输入,以防止干扰应用内的控制。
+      MatchViewportRes: true, // 匹配视窗分辨率:如果为 true,将调整视频分辨率以匹配视窗分辨率。
+    },
+  });
+  const stream = new PixelStreaming(config);
+  const application = new Application({
+    stream,
+    onColorModeChanged: (isLightMode) =>
+      PixelStreamingApplicationStyles.setColorMode(isLightMode),
+  });
+
+  // 加载完毕 重写 onPlayStream 添加 loading 状态
+  const onPlayStream = application.onPlayStream.bind(application);
+
+  application.onPlayStream = (...args) => {
+    onPlayStream(...args);
+    loading.value = false;
+    emitter("loaded");
+  };
+
+  // 添加到 dom
+  pixelStreamingContainerRef.value.appendChild(application.rootElement);
+  STATE.stream = stream;
+  STATE.application = application;
+
+  // 监听消息
+  stream.addResponseEventListener("handle_responses", (data) => {
+    emitter("receiveMessage", data);
+    ueWebEmitter?.emit("receive-pixel-msg", data);
+  });
+};
+
+onMounted(() => {
+  initPixelStreaming();
+});
+
+// 导出接口
+defineExpose({
+  // 像素流发送消息给 UE
+  sendMsgToUE: (payload) => {
+    if (!STATE.stream) return;
+    STATE.stream.emitUIInteraction(payload);
+  },
+  // 设置 WEB - UE - 像素流 通信的 emitter
+  setUeWebEmitter: (emitter) => {
+    (ueWebEmitter = emitter)
+
+  },
+});
+</script>
+
 <template>
-    <div>
-      <!-- 页面内容 -->
-    </div>
+  <div
+    class="pixel-streaming-container"
+    ref="pixelStreamingContainerRef"
+    :class="{
+      loaded: !loading,
+    }"
+  ></div>
 </template>
-  
-  <script>
-import { Config, PixelStreaming } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.2';
-import { Application, PixelStreamingApplicationStyle } from '@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2';
- 
- 
-export default {
-    name: 'PlayerView',
-    mounted() {
-      const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle();
-      PixelStreamingApplicationStyles.applyStyleSheet();
-  
-      // Example of how to set the logger level
-      // Logger.SetLoggerVerbosity(10);
-  
-      // Create a config object
-      const config = new Config({ useUrlParams: true });
-  
-      // Create a Native DOM delegate instance that implements the Delegate interface class
-      const stream = new PixelStreaming(config);
-      const application = new Application({
-        stream,
-        onColorModeChanged: (isLightMode) => PixelStreamingApplicationStyles.setColorMode(isLightMode)
-      });
-  
-      document.body.appendChild(application.rootElement);
-    },
-    methods: {
-      // ...
-    }
+
+<style scoped>
+.pixel-streaming-container {
+  height: 100%;
+  width: 100%;
+  opacity: 0;
+  transition: opacity 0.5s ease-in-out;
+  min-height: 100px; /** 最小高度 放置不可见 */
 }
-</script>
-  
-<style>
-body {
-    width: 100vw;
-    height: 100vh;
-    min-height: -webkit-fill-available;
-    font-family: 'Montserrat';
-    margin: 0;
+.pixel-streaming-container.loaded {
+  opacity: 1;
 }
-</style>
+</style>