-
-
Save UndarkAido/515bfec5b5db20139b5496c5be12fad0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as THREE from 'three'; | |
import WebGL from 'three/addons/capabilities/WebGL.js'; | |
import {ModelLoader, ResourceManager, ResourcePack} from "@xmcl/resourcepack"; | |
import {BasicTextureManager, BlockModelFactory} from "@xmcl/model/dist"; | |
if (!WebGL.isWebGLAvailable()){ | |
const warning = WebGL.getWebGLErrorMessage(); | |
document.getElementById( 'container' ).appendChild( warning ); | |
throw warning; | |
} | |
const scene = new THREE.Scene(); | |
//const camera = new THREE.OrthographicCamera(window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, .1, 1000) | |
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ); | |
const renderer = new THREE.WebGLRenderer(); | |
renderer.setSize( window.innerWidth, window.innerHeight ); | |
document.body.appendChild( renderer.domElement ); | |
const geometry = new THREE.BoxGeometry( 1, 1, 1 ); | |
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } ); | |
const cube = new THREE.Mesh( geometry, material ); | |
scene.add( cube ); | |
//camera.position.z = 100; | |
camera.position.z = 5; | |
async function loadPack(url){ | |
return ResourcePack.open(new Uint8Array(await (await fetch(url)).arrayBuffer())); | |
} | |
const man = new ResourceManager(); | |
const textureRegistry = new BasicTextureManager (); | |
const factory = new BlockModelFactory(textureRegistry); | |
const loader = new ModelLoader(man); | |
let loaded_pack = false; | |
let o3d; | |
const res= loadPack("client-1.20.4.jar").then(async pack => { | |
loaded_pack = true; | |
await man.addResourcePack(pack); | |
await loader.loadModel("block/grass_block"); | |
console.log(loader.models); | |
o3d = factory.getObject(loader.models["minecraft:models/block/grass_block.json"]); | |
scene.add(o3d); | |
console.log(o3d); | |
console.log(cube); | |
}) | |
function animate(){ | |
requestAnimationFrame(animate); | |
if(loaded_pack){ | |
//console.log(o3d); | |
} | |
cube.rotation.x += 0.01; | |
cube.rotation.y += 0.01; | |
renderer.render(scene, camera); | |
} | |
animate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment