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

load-collada-dae

v0.6.7

Published

Load the WebGL graphics buffer data from a collada .dae model and return a draw command that accepts options

Downloads

17

Readme

load-collada-dae npm version Build Status

WORK IN PROGRESS

Loads the WebGL graphics buffer data from a .dae file that's been parsed using a .dae parser and return a draw command that accepts options

TODO: View demo

To Install

$ npm install --save load-collada-dae

Running the demo locally

// TODO

Usage

var loadDae = require('load-collada-dae')

// You would usually parse your .dae files before runtime and then `xhr` GET request the pre-parsed JSON
var parseDae = require('collada-dae-parser')
var modelJSON = parseDae(GetColladaFileSomehow())

// Get your WebGL context directly from a canvas, or the context exposed by your favorite library / framework
var gl = GetCanvasWebGLContextSomehow()

// This can be a DOM image element or a Uint8Array of pixel data
var image = document.getElementById('some-already-loaded-image')

var model = loadDae(gl, modelJSON, {texure: image})

// Later inside of your render function
gl.useProgram(model.shaderProgram)
model.draw({
  attributes: model.attributes,
  uniforms: {
    uUseLighting: true,
    uAmbientColor: [0, 0, 0],
    uLightingDirection: [0, 0, 0],
    uDirectionalColor: [0, 0, 0],
    uMVMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.0, 0.0, -17.0, 1],
    uPMatrix: mat4Perspective([], Math.PI / 4, 256 / 256, 0.1, 100),
    // These might come from `skeletal-animation-system`
    boneRotQuaternions0: jointDualQuats.rotQuaternions[0],
    boneRotQuaternions1: jointDualQuats.rotQuaternions[1],
    boneTransQuaternions0: jointDualQuats.transQuaternions[0],
    boneTransQuaternions1: jointDualQuats.transQuaternions[1]
  }
})

See something broken, confusing or ripe for improvement? Feel free to open an issue or PR!

API

loadDae(parsedDae, loadOptions) -> object

parsedDae

Required

Type: string

A collada .dae file that has been parsed into JSON.

Usually you'd use collada-dae-parser to parser the .dae file pre-runtime. But any parser that outputs the same format will do.

loadOptions

Optional

type: object

load-collada-dae comes with default options, but you'll likely want to override some.

var myOptions = {
  textureImage: document.getElementById('some-already-loaded-image') || new Uint8Array([255, 0, 0, 255])
}
loadOptions.textureImage

type HTMLImageElement or Uint8Array

Optional

You pass in an HTMLImageElement or Uint8Array for your model's texture

If using an image element, make sure that the onload event has already fired

// example of loading the image
var image = document.getElementById('my-image') || new window.Image()
image.onload = function () {
  loadDae(gl, modelJSON, {texture: image})
}
image.src = 'https://cool-image-texture.com/cool-image.jpg'

TODO: Uint8Array example

loadOptions.fragmentShaderFunc

Optional

A function that will be passed the number of joints and returns a fragment shader for your skinned 3d model.

load-collada-dae comes with a default vertex shader generator.

You would typically override it if the default shader didn't match your needs. For example, if you wanted to add in point lighting.

function generatefragmentShader (opts) {
  console.log(opts.numJoints)
  // Some Number.. i.e. `12` (or however many joints your model has)

  return `
    // Some fragment shader
  `
}
loadOptions.vertexShaderFunc

Optional

A function that will be passed the number of joints and returns a vertex shader for your skinned 3d model.

load-collada-dae comes with a default vertex shader generator.

You would typically override it if the default shader didn't match your needs. For example, if you wanted to add in point lighting.

function generateVertexShader (opts) {
  console.log(opts.numJoints)
  // Some Number.. i.e. `12` (or however many joints your model has)

  return `
    // Your custom vertex shader
  `
}

Returned Model Object

We return a model object with a draw function

model.draw([drawOptions]) -> render to canvas

drawOptions

TODO: Flesh out example.. For now look at the test directory

// Example draw options
var myDrawOptions = {
  attributes: {},
  uniforms: {}
}
drawOptions.attributes
drawOptions.uniforms

TODO:

  • [ ] Demo in raw WebGL using an orbiting light source and materials
  • [ ] Add unit test with default lighting turned on

To Test:

Our test suite requires imagemagick to be installed locally, due to our image-diff dependency

$ npm run test

See Also

License

MIT