Code Monkey home page Code Monkey logo

Comments (6)

fenomas avatar fenomas commented on June 6, 2024

Hmm, I've not seen either of these. Can you share the code you're using to create the mesh you're using, and the code where you register it as an object block?

from noa.

MCArth avatar MCArth commented on June 6, 2024

I've been able the object at local 0,0,0 in stress:
image

With the following code:


import { Engine } from 'noa-engine'
// registration
import atlasURL from '../textures/terrain_atlas.png'
import tallgrass from '../textures/tallgrass.png'

import { Mesh, PBRMaterial, PlaneBuilder, Texture } from '@babylonjs/core'


var noa = new Engine({
    debug: true,
    showFPS: true,
    // inverseY: true,
    chunkSize: 48,
    chunkAddDistance: [1, 1],
    playerStart: [0, 10, 0],
    playerAutoStep: true,
})



noa.registry.registerMaterial('grass', { textureURL: atlasURL, atlasIndex: 0 })
noa.registry.registerMaterial('g_dirt', { textureURL: atlasURL, atlasIndex: 1 })
noa.registry.registerMaterial('dirt', { textureURL: atlasURL, atlasIndex: 2 })
noa.registry.registerMaterial('stone', { textureURL: atlasURL, atlasIndex: 3 })
noa.registry.registerMaterial('stone2', { textureURL: atlasURL, atlasIndex: 4 })
noa.registry.registerMaterial('cloud', { textureURL: atlasURL, atlasIndex: 5 })
noa.registry.registerMaterial('seethrough', { textureURL: atlasURL, atlasIndex: 6, texHasAlpha: true })


var id = 1
var dirt = noa.registry.registerBlock(id++, { material: 'dirt' })
var grass = noa.registry.registerBlock(id++, { material: 'grass' })
var stone = noa.registry.registerBlock(id++, { material: 'stone' })
var stone2 = noa.registry.registerBlock(id++, { material: 'stone2' })
// var cloud = noa.registry.registerBlock(id++, { material: 'cloud', opaque: false })
// var seethrough = noa.registry.registerBlock(id++, { material: 'seethrough', opaque: false })
var centrecross = noa.registry.registerBlock(id++, { 
    blockMesh: getCentreCrossModel(noa, tallgrass), 
    opaque: true,
    solid: true,
    onCustomMeshCreate: null,
})



function getCentreCrossModel(noa, tex) {
    const scene = noa.rendering.getScene()

    const plane1 = PlaneBuilder.CreatePlane(
        `BlkMdl1`,
        {
            size: 1,
            sideOrientation: Mesh.DOUBLESIDE,
        },
        scene
    )
    plane1.isPickable = false
    plane1.rotation.x = Math.PI
    plane1.position.y = 0.5
    plane1.bakeCurrentTransformIntoVertices()
	plane1.setEnabled(false)

    const plane2 = PlaneBuilder.CreatePlane(
        `BlkMdl2`,
        {size: 1, sideOrientation: Mesh.DOUBLESIDE},
        scene
    )
    plane2.isPickable = false

    plane2.rotation.y = Math.PI / 2
    plane2.rotation.z = Math.PI
    plane2.position.y = 0.5
    plane2.bakeCurrentTransformIntoVertices()
	plane2.setEnabled(false)

	const mat = new PBRMaterial(`BlockModelMeshMat`, scene)
    const texture = new Texture(tex, scene, null, null, 1)
    mat.unlit = true
    texture.hasAlpha = true
    mat.albedoTexture = texture
    mat.freeze()

    plane1.material = mat
    plane2.material = mat

    const mergedMesh = Mesh.MergeMeshes([plane1, plane2], true, false, null, false, true)
	mergedMesh.isPickable = false
	plane1.dispose()
	plane2.dispose()

    return mergedMesh
}



// worldgen
var decideVoxel = (x, y, z, ht, clo, chi, pillar) => {
    let id = 1+Math.floor(Math.random()*4)
    // if (Math.random() < 0.00002) {
        // id = 5
    // }
    if (y < ht) {
        return id
    }
    if (y < ht + pillar) return id
    if (y > clo && y < chi) return id

    if (y < ht+1 && Math.random() < 0.0002) {
        return 5
    }

    return 0
}
noa.world.on('worldDataNeeded', async (requestID, data, cx, cy, cz) => {
    await waitMs(1000)
    for (var i = 0; i < data.shape[0]; i++) {
        var x = cx + i
        for (var k = 0; k < data.shape[2]; k++) {
            var z = cz + k
            var ht = Math.sqrt(x * x + z * z) / 100
            var a = noise(x, 150)
            var b = noise(z + 50, 140)
            var c = noise(x - z - 50, 120)
            ht += 2 * a + b + c
            var pillar = (Math.random() < 0.002) ? 5 : 0
            var clo = 39 + 2 * (b - c)
            var chi = 35 + 2 * (a - b)
            for (var j = 0; j < data.shape[1]; j++) {
                var y = cy + j
                var id = decideVoxel(x, y, z, ht, clo, chi, pillar)
                data.set(i, j, k, id)
            }
        }
    }
    // tell noa the chunk's terrain data is now set
    noa.world.setChunkData(requestID, data)
})

async function waitMs(ms) {
	return new Promise(((resolve, reject) => {
		setTimeout(() => {
			resolve()
		}, ms)
	}))
}

add the following texture:
tallgrass

to repro just fly backwards on first load. you might have to do it a few times to get it to repro

(i havent seen the "briefly flashing on screen" bit, but hopefully that's related and can be fixed simultaneously)

from noa.

MCArth avatar MCArth commented on June 6, 2024

https://streamable.com/cohlbf

from noa.

fenomas avatar fenomas commented on June 6, 2024

Hey, thanks very much for the complete repro steps. This was really thorny, it seems to have been a timing issue with Babylon internals, which depended on the timing of the call to mat.freeze() (but only in the case of PBR materials).

I've pushed a fix that seems to resolve it - can you check? I was only really able to reproduce the issue sporadically, so it's hard to be sure about a fix.

from noa.

MCArth avatar MCArth commented on June 6, 2024

Thanks for looking into it. It's always the race conditions that get you 😅

Seems to fix it for me as well

something to consider: it could be good to lock to a specific babylon version in both noa and the examples (or at least only allow patch upgrades with ~). An awful amount of things seem to break with babylon updates

from noa.

fenomas avatar fenomas commented on June 6, 2024

Thanks for checking! Let's hope this is the last we see of this one...

from noa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.