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

tmhe-buildyourtruck-lib

v0.0.6

Published

This repository contains the code to load the BYT viewer into an existing React project.

Downloads

5

Readme

Build your truck library

This repository contains the code to load the BYT viewer into an existing React project.

Installation

  1. Set up model and material libraries in your public directory according to instructions
  2. Include this library into your project

npm i tmhe-buildyourtruck-lib

Use the viewer

  1. Import the viewer component from the library
 import { BYTViewer } from "tmhe-buildyourtruck-lib";
  1. Add the BYTViewer component to your document
<BYTViewer className="w-full h-full" />
  1. You can communicate with the viewer by emitting events, similarly you can listen for events coming from the viewer
  • Include the emit function and useBYTViewer hook
 import { emit, useBYTViewer } from "tmhe-buildyourtruck-lib"
  • Call the functions via the emit function. Your dev environment should give you code intellisense if you're using typescript. Otherwise the specs are listed below
 emit("eventName", eventParameters)
  • Listen for events by calling useBYTViewer() with the correct event name
 useBYTViewer(eventName, eventHandler);

For each event, you need to call useBYTViewer

  1. Call the setConfig function to preload all materials & textures used for all models.

  2. Wait until the config is loaded, your app can listen for the configLoaded event. You can also listen for the progress updates.

 useBYTViewer("configLoaded", () => {});
  1. Call the loadModel function to load a model. When the model is finished loading and parsed it will trigger the modelLoaded event. You can also listen for the progress updates.
emit("loadModel", modelToLoad);
...
useBYTViewer("modelLoaded", () => {});

Full list of functions & events

You can include Typescript types from tmhe-buildyourtruck-lib/dist/types

Functions

| function name | parameters | description | | --------------- | ----------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | setConfig | { decoderPath: string; materialsPath: string; modelsPath: string; states?: IdUpdate[] } | Configure the viewer so it knows where to find the materials, textures & model data files (Ommit the final trailing /). IdUpdate is an array of IDs you want to send on startup (see toggleId below). Decoderpath is the location of the DRACO decoder used to parse the highly compressed model files. | | loadModel | string | Load specific 3D model | | toggleId | { ID: string } | Send an ID to update the model. IDs are resolved into specific updates (toggle, material/position update(s)) | | setActiveCamera | CAMERA_TYPE | Switch the current camera. CAMERA_TYPE is an enum but accepts number too. INSIDE=0, OUTSIDE=1 | | resetCamera | none | Reset the current camera position and rotation to it's default / initial position | | showBackground | boolean | Show a clay-rendered background of a warehouse. Default is off |

Unused functions (for reference): toggleElement, toggleState, updateMaterial, sendId. These functions are not documented and not wired up at this moment as they require an in-depth knowledge of the 3D Node tree

Methods and events marked as __internal should not be used

Events

| event name | parameters | description | | -------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | configProgress | { progress: number; } | Percentage loaded of material library (0-1) | | configLoaded | none | Material library is loaded successfully. It's required to wait for this otherwise the model will not look correctly | | modelProgress | { progress: number; } | Percentage loaded of the model (0-1) | | modelLoaded | none | The model is fully loaded and being parsed. Depending on the device it'll take another 1-4s to parse the model and set it's intial look. | | cameraSwitched | { activeCam: CAMERA_TYPE } | The camera was switched. CAMERA_TYPE is an enum. INSIDE=0, OUTSIDE=1 |

Deployment

The library can be integrated into your project as is. The location of the external asset dependencies are defined at runtime. The paths to these assets can be relative or absolute to the location of the app URL. You can choose to use separate paths or put everything inside 1 directory.

  1. Draco directory (config.decoderPath):
    Should contain a subdirectory gltf with the following files *

    • draco_decoder.js
    • draco_decoder.wasm
    • draco_wasm_wrapper.js
  2. Materials directory (config.materialsPath):

    • File Material-library.glb
    • Directory textures *
  3. Models directory (config.modelsPath):
    Should contain a subdirectory for each model. Inside should have these 2 files

    • Config.json
    • Model.glb

* These assets can be copied from the library directory (node_modules/tmhe-buildyourtruck-lib/public).