#Looking for help understanding the CEM model format

74 messages · Page 1 of 1 (latest)

slender anvil
#

I am looking to reimplement a parser to render models myself from scratch, this might not be the best place to ask but I feel the documentation is pretty scarce outside of

https://optifine.readthedocs.io/

and the blockbench jem plugin

https://github.com/JannisX11/blockbench/blob/b549e4c06004ba095ce61772bf74132d5c189d4c/js/io/formats/optifine_jem.js

If anyone is willing to take time to help me out, or even point me to the right direction, I would be very grateful !

GitHub

Blockbench - A low poly 3D model editor. Contribute to JannisX11/blockbench development by creating an account on GitHub.

lilac shardBOT
#
Welcome to the help forum!

Please make sure to read #1029373817119838218 as it may answer your question!

Once your question has been resolved, please mark the post as closed by using the </close:1163944441741049897> command.

slender anvil
# real frost what would this be for?

Essentially I am working on making a online schematic viewer, and I want to be able to support block entities like chests for example, and extend it to all entities, but I have been banging my head against the wall thinking the CEM format is stupid for the past 2 days ( I know I'm probably the stupid one in this case )

real frost
#

why not use the bedrock entity format instead, since thats an official format for minecraft

#

or make it even simpler and just use GLTF models

slender anvil
#

I would want to make it easy to get models CEM looked like the best way to get most models

#

Just as context my bell looks like this, I am pretty sure invertAxis is messing with me ( its before applying the rotation )

real frost
#

no matter what you do, you will need to manually provide the model files for it to load.

three.js has native support for glTF models. just get the model for the entity in blockbench, export it into glTF, then you can load it in three.js nice and simply

#

unless you want to support people providing custom CEM models

slender anvil
#

I guess I could do that, one downside with gltf , is that idk how I would map a minecraft texture to it after the fact.
Nah I'm fine with a default set of models, but it would be a nice to have to have user provided resource packs

real frost
#

loading the texture is no different

#

you just load the model into a mesh in threejs, then assign it the texture

#

1 sec

slender anvil
#

I'll have to look into it then, any idea where I can find a db of all mc entites in gltf format ? I guess mojang has default asset packs for bedrock

real frost
#

it has a gltf loader

#

then you can just map the material to it ```js
const gltf = await loadGLTF(args.model)

const material = new THREE.MeshLambertMaterial({
map: await loadTexture(canvas),
side: args.singleSide ? THREE.BackSide : THREE.DoubleSide,
alphaTest: 0.1
})
material.transparent = true
material.map.magFilter = THREE.NearestFilter
material.map.needsUpdate = true

gltf.scene.traverse(child => {
if (child.isMesh) child.material = material
})

#

for example

slender anvil
#

Honestly thanks for the advice btw, I think it's probably time to try something else, is there a reason I seem to think you are making me move away from CEM ?

Also for gltf i'd probably want to automate the export, I would go through the T&C first, but I guess I'll ask you first, since most is only front end / client side I guess it doesn't really cause a problem ?

slender anvil
#

Well I feel like I am 95% there but it's maybe sunken cost

real frost
#

the last 5% is always the longest bit.

if you want to continue with CEM, then you have the blockbench implementation of it to reference, which imports it straight into three.js. i cant help much with that though

slender anvil
#

Well you've already been a big help tbh, I'll try a bit longer with the CEM, and if I give up i'll probably give bedrock a try since it's the most official, and probably easiest available models. and if not GLTF sounds good because three will do the heavy lifting for me

real frost
#

ive done the gltf one before, and yeah it was straightforward

#

for this

teal edgeBOT
slender anvil
slender anvil
real frost
#

yeah

slender anvil
#

Ohhh

#

interesting 🤔

real frost
#

still three.js, just in node rather than browser

slender anvil
#

never tried running it in node, I was thinking of getting a browser environment since I wanted api rendering exactly like this

#

if it runs, it's great, might want hardware acceleration tho :/

real frost
#

my friend made this for making three.js work in node

slender anvil
real frost
#
import { Canvas, Image, ImageData, loadImage } from "skia-canvas"
import fetch, { Request, Response, Headers } from "node-fetch"
import createContext from "gl"
import sharp from "sharp"

const { THREE, loadGLTF, loadTexture } = (await getTHREE({ Canvas, Image, ImageData, fetch, Request, Response, Headers })).withGLTFLoader()
slender anvil
#

This is really really cool

real frost
#

then just setup three.js scene & camera as normal

slender anvil
#

You just single handedly saved my a ton of work, time and made my idea so much more concrete

real frost
#
const renderer = new THREE.WebGLRenderer({
  context: gl
})
renderer.setSize(w, h)
renderer.render(scene, camera, new THREE.WebGLRenderTarget(w, h))
const buff = Buffer.alloc(w * h * 4)
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, buff)
return await sharp(buff, {
  raw: {
    width: w,
    height: h,
    channels: 4
  }
}).png().toBuffer()

and that renders it

slender anvil
#

I wrote a whole consumer worker system to be able to start browser that would just consume a work queue to render stuff

Since I couldn't get three working headlessly

#

And as reference this is the kind of schematic renders that it outputs ( I broke glass transparency in that version )

real frost
#

cool

slender anvil
real frost
#

yes

#

specifically the parse function

slender anvil
#

Thanks for everything !

real frost
#

you dont need multi texture support

#

so you can go back to an older version and it will be simpler

#

you can also ignore animations

lilac shardBOT
#

<:e:1311744042664726618>

slender anvil
real frost
#

lol

slender anvil
#

Ran it in my browser, it downloaded 300 ish files

real frost
#

there will be loads you dont need

slender anvil
#

i would guess 95% won't be needed

real frost
#

you only need the ones in the supported tab, maybe some from unsupported

#

you dont need most variants. you will need boat.jem for example, but none of the oak_boat, birch_boat, etc

#

you dont need any of the baby models, except baby horse because that model is actually different

slender anvil
#

ok 98% then

#

Honestly it's the kind of thing I didn't really think about until I put my nose into it, also the scale of the bb comunity

slender anvil
#

welp that was easy

real frost
#

very dark

slender anvil
#

It’s just loading the mesh as a standalone the actual scene itself is only for dev so didn’t really look too much into lighting etc. I thought having the block mesh / entity mesh loader as a standalone would be good

I will integrate that into my actual renderer when I get some sleep