Skip to content

Commit

Permalink
feat: 新增360全景(#0)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihengshuai committed Mar 10, 2024
1 parent 14a55e4 commit 522af01
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 154 deletions.
3 changes: 1 addition & 2 deletions client/constants/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export enum ROUTE_NAME {

// threejs
threejsBase = "threejsBase",
threejsLine = "threejsLine",
threejsText = "threejsText",
threejsExample360 = "threejs-example-360",

// 其他
redirect = "redirect",
Expand Down
13 changes: 3 additions & 10 deletions client/constants/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,8 @@ export const SEO_META: ISEO_META[] = setMetaWhenDifferentENV([
route: ROUTE_NAME.threejsBase,
},
{
title: "ThreeJS练习 —— 画线",
keywords: ["three.js", "threejs", "3d"],
route: ROUTE_NAME.threejsLine,
hidden: true,
},
{
title: "ThreeJS练习 —— 文字",
keywords: ["three.js", "threejs", "3d"],
route: ROUTE_NAME.threejsText,
hidden: true,
title: "ThreeJS案例 —— 360全景",
keywords: ["three.js", "threejs", "3d", "全景", "360全景", "360图片", "vr展示", "360展示"],
route: ROUTE_NAME.threejsExample360,
},
]);
14 changes: 4 additions & 10 deletions client/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,10 @@ const routes: RouteRecordRaw[] = [
meta: { pageTitle: "Three.js基础练习" },
},
{
path: "threejs-line",
name: ROUTE_NAME.threejsLine,
component: LazyComponent(() => import("@/views/threejs/base/line")),
meta: { pageTitle: "Three.js线条练习" },
},
{
path: "threejs-text",
name: ROUTE_NAME.threejsText,
component: LazyComponent(() => import("@/views/threejs/base/text")),
meta: { pageTitle: "Three.js文字练习" },
path: "threejs-360-view",
name: ROUTE_NAME.threejsExample360,
component: LazyComponent(() => import("@/views/threejs/example/360-view")),
meta: { pageTitle: "Three.js - 360全景" },
},
],
},
Expand Down
4 changes: 1 addition & 3 deletions client/views/threejs/base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const ThreeJSBase = defineComponent({

function launch() {
// 场景、相机、渲染器
scene.background = new Three.Color(0x000000);

// 设置场景背景
scene.background = new Three.Color(0x000000);
// 天空背景
Expand Down Expand Up @@ -97,7 +95,7 @@ const ThreeJSBase = defineComponent({
// ========= 辅助器 =========

// 添加世界坐标系
const axesHelper = new Three.AxesHelper(5);
const axesHelper = new Three.AxesHelper(1000);
scene.add(axesHelper);

// 控制器
Expand Down
62 changes: 0 additions & 62 deletions client/views/threejs/base/line.tsx

This file was deleted.

67 changes: 0 additions & 67 deletions client/views/threejs/base/text.tsx

This file was deleted.

76 changes: 76 additions & 0 deletions client/views/threejs/example/360-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import IPanel from "@/components/common/panel";
import { defineComponent, onMounted } from "vue";
import * as Three from "three";
import "@/views/threejs/base/style.less";
import { launchResize, launchThreeJS } from "@/views/threejs/helper";
import { getAssetss } from "@/util";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";

const View360Page = defineComponent({
name: "View360Page",
setup() {
let wrapper: HTMLBodyElement;
const scene = new Three.Scene();

function launch() {
renderCubeSkyBg();

const camera = new Three.PerspectiveCamera(90, wrapper.offsetWidth / wrapper.offsetHeight, 0.1, 1000);
camera.position.set(30, 3, 7);

const renderer = new Three.WebGLRenderer({ antialias: true });
renderer.setSize(wrapper.offsetWidth, wrapper.offsetHeight);
wrapper.appendChild(renderer.domElement);
renderer.setPixelRatio(window.devicePixelRatio);

const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;

function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
controls.update();
}

launchThreeJS(render);
launchResize(renderer, camera);
}

function renderCubeSkyBg() {
const cubeLoader = new Three.CubeTextureLoader();
cubeLoader.load(
[
getAssetss("texture/pos-x.jpg"),
getAssetss("texture/neg-x.jpg"),
getAssetss("texture/pos-y.jpg"),
getAssetss("texture/neg-y.jpg"),
getAssetss("texture/pos-z.jpg"),
getAssetss("texture/neg-z.jpg"),
],
texture => {
scene.background = texture;
}
);
}

onMounted(() => {
wrapper = document.querySelector<HTMLBodyElement>("#wrapper")!;
launch();
});

return () => (
<IPanel
withMargin={false}
solid
top
>
<div
id="wrapper"
class="threejs-page"
/>
</IPanel>
);
},
});

export default View360Page;

0 comments on commit 522af01

Please sign in to comment.