GithubHelp home page GithubHelp logo

arong-me / three-platformize Goto Github PK

View Code? Open in Web Editor NEW

This project forked from deepkolos/three-platformize

0.0 0.0 0.0 2.56 MB

一个让 THREE 平台化的项目,目前已适配微信小程序,淘宝小程序

JavaScript 100.00%

three-platformize's Introduction

three-platformize

一个让 THREE 平台化的项目

  1. 目前已适配微信小程序,淘宝小程序
  2. 支持 tree shaking(需用 webpack,rollup 等构建工具)
  3. VSCode types 正常,能正常访问各个类的定义
  4. 适配 examples/jsm/**/*.js,types 正常
  5. 可升级、降级版本或使用自定义 THREE

DEMO

微信小程序 DEMO

淘宝小程序 DEMO

注:运行 DEMO 时记得开启调试模式,取消域名验证

已测试模块

Loader

  1. GLTFLoader (支持带纹理的 GLB) && (EXT_meshopt_compression 安卓可用WASM,ios可用ASM版,见tools) && (KHR_mesh_quantization,小程序可用)
  2. TextureLoader
  3. RGBELoader & PMREMGenerator (小程序部分机型可能偶现生成 envMap 错误,可用HDRPrefilter避免 )
  4. SVGLoader
  5. OBJLoader
  6. EXRLoader (需支持 OES_texture_float_linear 扩展,部分移动端 GPU 不支持)
  7. MTLLoader (小程序使用 JPG 纹理即可)
  8. DDSLoader (需支持 WEBGL_compressed_texture_s3tc 扩展,移动端 GPU 不支持)
  9. LWOLoader (需支持 EXT_blend_minmax 扩展,小程序一半效果绘制出错)
  10. FBXLoader
  11. BVHLoader
  12. ColladaLoader (TGALoader 尚未适配)
  13. TTFLoader
  14. STLLoader

Controls

  1. OrbitControls & MapControls
  2. DeviceOrientationControls

不支持模块

  1. ImageBitmapLoader(微信小程序未开放 ImageBitmap)

有支持可能,但需要单独适配

  1. BasisTextureLoader(微信小程序的 Worker 不好转发,经测试安卓可在 worker 内使用 WASM)

使用

import * as THREE from 'three-platformize';
import WechatPlatform from 'three-platformize/src/WechatPlatform';

const platform = new WechatPlatform(canvas); // webgl canvas

platform.enableDeviceOrientation('game'); // 开启DeviceOrientation
THREE.PLATFORM.set(platform);

// 使用完毕后释放资源
THREE.PLATFORM.dispose();

// 正常使用three即可

实现

构建时替换平台相关的 api 调用,转发到 PLATFORM 的引用,通过 PLATFORM.set 更新

维护

如何更新/降级 Three 的版本?

# 拉取源码
> git clone https://github.com/deepkolos/three-platformize

# 安装依赖
> npm i

# 更新到最新的three版本
> npm i -S three@latest
# 或者指定three版本
> npm i -S [email protected]

# 建立软链接
> npm run link

# 构建
> npm run build

# 使用
> npm link

# 到使用的项目目录,并链接
> cd your-project
> npm link three-platformize

# 或者自行发NPM包

如何平台化自定义的 Three?

# 把自定义Three link 到./three
> npx symlink-dir yourthree ./three

# 不使用软链接直接复制或者git submodule也可以
> cp yourthree ./three

# 构建
> npm run build

TODO

  1. 更彻底 dispose,减少内存泄漏
  2. 适配头条小程序

three-platformize's People

Contributors

deepkolos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.