JSFiddle - React, Tailwind, and code Playground
by adwait3301
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/aframe/1.2.0/aframe.min.js"></script>
<script src="https://unpkg.com/three@0.112/examples/jsm/loaders/ColladaLoader.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.150/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.150/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { ColladaLoader } from 'three/addons/loaders/ColladaLoader.js';
AFRAME.registerComponent('collada-loader', {
schema: {
colorCorrection: {
default: false
},
},
init: function() {
this.model = null;
this.loader = new ColladaLoader();
},
//function to add and update the scene with the mesh
update: function() {
const self = this;
const el = this.el;
const colorCorrection = this.data.colorCorrection;
if (!this.model) {return; }
this.remove();
this.loader.load('https://cdn.jsdelivr.net/gh/gftruj/webzamples@master/aframe/assets/models/elf/elf.dae', function(collada) {
self.model = collada.scene;
if (colorCorrection) {
const rendererSystem = el.sceneE1.systems.renderer;
self.model.traverse(function(object) {
if (object.isMesh) {
// if the mesh doesn't have normals
object.material.flatShading = true;
object.material.depthTest = true;
if (object.material.color)
rendererSystem.applyColorCorrection(object.material.color);
if (object.material.map)
rendererSystem.applyColorCorrection(object.material.map);
if (object.material.emissive)
rendererSystem.applyColorCorrection(object.material.emissive);
if (object.material)
rendererSystem.applyColorCorrection(object.material.emissivemap);
}
...