-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: ci | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
ci: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [ 14.x ] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Run ci | ||
run: npm ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# XR Editor | ||
|
||
![workflow](https://github.com/ch-real3d/xr-editor/actions/workflows/ci.yml/badge.svg) | ||
|
||
![](https://rshop.tech/gw/assets/upload/202308292230998.png) | ||
|
||
一个开源的 3D 编辑器。 | ||
|
||
- 基于 Babylon.js、React 和 antd | ||
- 可外部扩展的面板系统 | ||
- 内建 H5、apng 导出功能 | ||
|
||
## 在项目中使用 | ||
|
||
``` | ||
npm install xr-editor | ||
``` | ||
|
||
```jsx | ||
import React, { useContext, useEffect, useRef, useState } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { IBuiltinWBKeyItem, XREditor, XRProjectModel, XRSetup, UserLevelEnum } from '@xr/editor'; | ||
import { ExternalImpl, MemoryFS } from 'ah-memory-fs'; | ||
import { IndexedDBAdapter } from 'ah-memory-fs-indexed-db'; | ||
import XRRuntimeStartupManifest from '@xr/editor/esm/XRRuntimeStartup.manifest.json'; | ||
|
||
ExternalImpl.ArrayBufferToString = data => new TextDecoder().decode(data); | ||
ExternalImpl.StringToArrayBuffer = data => new TextEncoder().encode(data); | ||
|
||
XRSetup(); | ||
|
||
|
||
export const EntryApp = () => { | ||
const ctx = useContext(AppContext); | ||
|
||
const [ready, setReady] = useState<boolean>(false); | ||
const projectRef = useRef<XRProjectModel>(); | ||
|
||
useEffect(() => { | ||
launch(); | ||
|
||
return () => { | ||
projectRef.current?.dispose(); | ||
}; | ||
}, []); | ||
|
||
const launch = async () => { | ||
const attachTo = 'XR-PLAYGROUND'; | ||
const mfs = await MemoryFS.create(() => IndexedDBAdapter.attach(attachTo)); | ||
|
||
const _uploadDist = async (data: Blob, path: string) => { | ||
return ''; // 自定义 data 上传 URL | ||
}; | ||
|
||
const _projModel = new XRProjectModel(mfs, XRRuntimeStartupManifest.js[0], _uploadDist); | ||
await _projModel.reload(); | ||
|
||
_projModel.setUserLevel(UserLevelEnum.Anonymous); // 游客模式 | ||
_projModel.setMetaInfo({ title: '本地项目' }); | ||
|
||
projectRef.current = _projModel; | ||
setReady(true); | ||
}; | ||
|
||
|
||
return ready && projectRef.current ? ( | ||
<> | ||
<XREditor | ||
style={{ width: '100vw', height: '100vh' }} | ||
project={projectRef.current} | ||
/> | ||
</> | ||
) : null; | ||
}; | ||
|
||
ReactDOM.render( | ||
<EntryApp />, | ||
document.getElementById('__app') | ||
); | ||
``` | ||
## 本地启动 | ||
```bash | ||
npm install | ||
npm run app:dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters