npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gltf-display

v0.0.2

Published

💡 An easy glTF preview package.

Downloads

10

Readme

glTF Display

📑 Homepage

https://wzdong26.github.io/gltf-display/editor/

📙 Introduction

这是一个 glTF 3D 模型预览编辑器,项目基于 ThreeJS 实现。支持功能包括:

  • 支持拖拽上传本地 3D 模型(.glb/.gltf)文件预览效果(可支持文件夹上传);
  • 支持在线 glTF 文件 URL 路径输入预览效果;
  • 支持场景及模型参数调节,包括:背景色/透明度、可交互、场景旋转、灯光、模型线框(wireframe)、模型动画(animations)、等;
  • 支持截图(screenCapture),制作立体图像;
  • 支持分享(share),作为纯 web 页面分享到任何地方,包括作为 iframe 嵌入到你的 web 应用中(只支持在线 glTF 模型分享,本地 glTF 模型暂不支持);
  • 持续更新中。。。

点击 Homepage 即可在线体验

🛠 Installation

除了上面介绍的 Web 应用之外,该项目的核心包还支持 npm 引入:

npm install gltf-display three

## yarn
yarn add gltf-display three

## pnpm
pnpm add gltf-display three

或者也可以直接通过 CDN 引入:

<script type="importmap">
  {
    "imports": {
      "gltf-display": "https://cdn.jsdelivr.net/npm/[email protected]",
      "three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
      "three/examples/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/"
    }
  }
</script>

<script type="module">
  import { Configurator, Viewer } from "gltf-display";
  // ...
</script>

Getting Started

gltf-display 的使用非常简单,你只需要像下面这样就可以创建一个 3D 场景:

import { Configurator } from "gltf-display";
const { conf } = new Configurator();
conf.src = "https://wzdong26.github.io/gltf-display/loading/scene.gltf";
conf.rotate = 30;

API

gltf-display 采用 jsDoc 类型注解,保证在开发过程中舒适的代码提示。

  • Configurator

Configurator 是实现 gltf 模型预览的一个声明式 API。你只需要声明 Configurator.conf 对象上的属性就可以创建一个 3D 场景。

type ConstructorParameters<Configurator> = [
  {
    container: Element; // canvas 的父容器
  }
];
  • Configurator.conf
Configurator.conf: {
    bgColor: string; // 背景色
    bgOpacity: number; // 背景透明度
    enableCtrl: boolean; // 场景是否可交互控制
    rotate: number; // 场景旋转速度,负数为顺时针旋转,正数为逆时针旋转
    lightColor: string; // 环境光照颜色
    lightIntensity: number; // 环境光照强度
    src: string; // 在线 gltf 模型 url
    wireframe: boolean; // gltf 模型是否以线框结构显示
    boxHelper: boolean; // 是否显示 gltf 模型外包围盒
    zoom: number; // 控制 gltf 模型距离相机远近,值越大相机距离越远,模型视觉效果越小
    alpha: number; // 控制相机高度,值越大越高,显示俯瞰角度
    animationSpeed: number; // 动画速度,仅在加载动画时有效
    animations: string[]; // 指定加载 gltf 模型的哪些动画,仅在 gltf 模型中有该动画时有效
}
  • Viewer

Viewer 是实现 gltf 模型预览的一个命令式 API。它更加基础。

type ConstructorParameters<Viewer> = [
  {
    camera: { fov: number; near: number; far: number }; // threejs 中 PerspectiveCamera 初始化参数
    renderer: WebGLRendererParameters; // threejs 中 WebGLRenderer 初始化参数
  }
];
  • Viewer

Viewer 是实现 gltf 模型预览的一个命令式 API。它更加基础。

type ConstructorParameters<Viewer> = [
  {
    camera: { fov: number; near: number; far: number }; // threejs 中 PerspectiveCamera 初始化参数
    renderer: WebGLRendererParameters; // threejs 中 WebGLRenderer 初始化参数
  }
];
  • Viewer.loadGLTF
typeof loadGLTF = (url:string, blobs?:Record<string, Blob>) => Promise<GLTF>

🙆‍♂️ Contributor