Skip to content

Export Feature (THREE.js) #2

@Bug-Reaper

Description

@Bug-Reaper

Wondering if I can put in some work here to buff out a three.js flavored export. For re-usable ShaderMaterials, I usually have them as their own little factory function like so:

// File named - ShaderNameHere.js
import * as THREE from 'three';

export function ShaderNameHere() {
    this.uniforms = {
        iTime: { value: 70.0 },
        iMouse: { value: [0, 0] },
        iResolution: { value: [2000.0, 1000.0] },
    }
    this.render = (delta) => { this.uniforms.iTime.value += delta}
    this.material = new THREE.ShaderMaterial({
        uniforms: this.uniforms,
        side: THREE.BackSide,
        vertexShader:`...`,
        fragmentShader:`...`
    })
}

Then to use the custom shader material, you can:

import * as THREE from 'three';
import { ShaderNameHere } from './ShaderNameHere.js'

const shaderController = new ShaderNameHere();
const geometry = new THREE.SphereGeometry()
const mesh = new THREE.Mesh(geometry, shaderController.material)

/*
... Then somewhere in your render loop
*/
shaderController.render(delta) 

Wanted to see how you feel about the three.js flavored export to be a .js file similar to the first snippet?

Think I could bang out a PR for the exporter and have some good ideas for handling stuff like textures etc... Also happy to throw together a more robust export usage explanation page as part of the PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions