Show3D SDK

Demo 建模器 API 首页
v4.0.0 · MIT

Show3D SDK

自研 3D 引擎,一行 script 标签引入,零 CDN 依赖。57+ 几何体、9 材质、6 灯光、CSM+PCSS 阴影、骨骼动画、GPU 粒子、GLTF 加载、WebXR VR/AR、KTX2 纹理、内置物理引擎。

57 几何体 9 材质 CSM+PCSS 骨骼动画 GPU 粒子 GLTF/OBJ/STL WebXR KTX2 物理引擎

快速开始

在你的 HTML 页面中加入一行 <script> 标签即可。引擎由 ShowH5 服务直接托管,不依赖任何第三方 CDN。

第 1 步 · 引入引擎
<!-- 直接引用 /3d 路径,浏览器自动获得 JS -->
<script src="https://h5.xcmdy.top/3d"></script>
<script>
  // 引擎挂载到全局 window.SH5_3D
  var S = SH5_3D;
  console.log('Show3D 版本:', S.version);  // 4.0.0
</script>
<!-- 使用显式文件名(等价于 /3d)-->
<script src="https://h5.xcmdy.top/3d/show3d.js"></script>
<!-- 或 -->
<script src="https://h5.xcmdy.top/3d/show3d.min.js"></script>
// 通过 fetch + new Function 动态加载(跨域已开启 CORS)
const res = await fetch('https://h5.xcmdy.top/3d?raw=1');
const code = await res.text();
new Function(code)();
const S = window.SH5_3D;
第 2 步 · 最小渲染示例
<canvas id="c" width="600" height="400"></canvas>
<script src="https://h5.xcmdy.top/3d"></script>
<script>
  var S = SH5_3D;
  var canvas = document.getElementById('c');
  var renderer = S.createRenderer(canvas);   // 自动选 WebGL / CPU 软渲染
  var cam = { x:0, y:2, z:5, tx:0, ty:0, tz:0, fov:60 };
  var lights = [
    { type:'directional', x:5, y:10, z:5, color:'#ffffff', intensity:0.8 },
    { type:'ambient', color:'#404040', intensity:0.4 }
  ];
  var objects = [
    { id:'cube1', type:'cube', x:0, y:0, z:0, scale:1, size:1,
      color:'#ff4444', material:'standard', metalness:0.5, roughness:0.5,
      castShadow:true, receiveShadow:true }
  ];
  renderer.render(objects, cam, lights, {});
</script>
提示:直接在浏览器地址栏访问 /3d 会看到本文档页(因为浏览器 Accept 头是 text/html)。<script src> 引用时则返回 JS。如需强制获取 JS,加 ?raw=1 参数:/3d?raw=1

在线 Demo

下面的演示直接通过 <script src="/3d?raw=1"> 加载引擎并实时渲染。

全屏打开 ↗
点击按钮交互

API 概览

引擎挂载到全局 window.SH5_3D(简写 S)。以下为核心模块,完整 API 可通过 /3d/api 程序化查询。

S.Math

数学库:4x4 矩阵、三维向量、四元数、几何工具。

mat4.create/translate/rotate/multiply/perspective/lookAt/invert vec3.create/normalize/cross/dot/add/sub/lerp quat.create/multiply/slerp/fromEuler

S.createGeometry(type, opts)

创建几何体,返回 {vertices, normals, uvs, indices}

cubespherecylinder conetorustorusKnot capsuleplaneicosahedron dodecahedronlathetube text3Dheartdiamond mobiusStripkleinBottlesupershape ...共 57 种

S.createMaterial(type, opts)

创建材质。

standard (PBR)physical (PBR) phongtoonbasic lambertnormaldepthmatcap

S.createLight(type, opts)

创建灯光。

pointdirectionalspot ambienthemisphererectarea

S.createRenderer(canvas)

创建渲染器,自动选择 WebGL GPU 或 CPU 软渲染(无 WebGL 时回退)。

renderer.type = 'webgl' | 'software' renderer.render(objects, cam, lights, opts)

S.EffectComposer

后处理合成器,12+ 特效可叠加。

bloomsmaafxaa tonemapvignettedof ssaogodRaytoon pixelglitchchromaticAberration

骨骼动画

完整的骨骼蒙皮动画系统。

S.BoneS.SkinnedMesh S.AnimationClipS.AnimationMixer S.AnimationTrack

S.ParticleSystem

GPU 粒子系统,支持发射器、生命周期、速度、大小、颜色。

new S.ParticleSystem(opts) .setEmitter(x,y,z) .update(dt).getBufferData()

模型加载器

支持 4 种主流格式,二进制 + ASCII。

S.GLTFLoaderS.OBJLoader S.STLLoaderS.PLYLoader

S.WebXRManager

WebXR VR/AR 管理,支持 immersive-vr / immersive-ar 会话与手柄追踪。

.isSupported().enterVR() .enterAR().exit()

S.KTX2Loader

KTX2 / Basis 超纹理压缩加载,GPU 解码,显存占用降低 75%。

.load(url, cb).loadFromBuffer(buf, cb)

S.Physics (v3.3.0)

内置物理引擎(Cannon.js 风格),刚体、约束、碰撞检测。

S.createPhysicsWorld(opts) S.Physics.BodyS.Physics.Sphere S.Physics.BoxS.Physics.Constraint world.step(dt)

渲染对象字段参考

renderer.render(objects, cam, lights, opts)objects 数组中每个对象支持以下字段:

字段类型说明
idstring对象唯一标识
typestring几何体类型(cube/sphere/...,共 57 种)
x/y/znumber世界坐标位置
rx/ry/rznumber欧拉旋转(弧度)
scalenumber统一缩放
sizenumber几何体尺寸(半径/边长等)
colorstring基础颜色(#rrggbb)
materialstring材质类型(standard/physical/phong/toon/...)
metalnessnumberPBR 金属度(0-1)
roughnessnumberPBR 粗糙度(0-1)
opacitynumber不透明度(0-1,小于 1 时透明)
texturestring纹理图片 URL
castShadowboolean是否投射阴影
receiveShadowboolean是否接收阴影

路径说明

路径返回用途
/3dJS(script 引用)/ HTML(浏览器直接访问)主入口,外部应用引用此路径
/3d/show3d.jsJS显式文件名
/3d/show3d.min.jsJS显式压缩版文件名(同上)
/show3d.jsJS根路径别名
/3d?raw=1JS强制返回 JS(不跳转文档页)
/3d/docsHTML本文档页
/3d/apiJSON程序化 API 概览查询
缓存:JS 文件带 Cache-Control: public, max-age=3600, immutable 和 CORS 头,可被任意域名跨域引用。升级版本后如需立即生效,加版本号查询参数:/3d?v=4.0.1