Comments (6)
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.
I've been able the object at local 0,0,0 in stress:
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)
}))
}
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.
from noa.
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.
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.
Thanks for checking! Let's hope this is the last we see of this one...
from noa.
Related Issues (20)
- Is there any way to use this as an es6 module? HOT 10
- Support gamepad input
- Outdated comment + note on blockMesh registration HOT 2
- Alpha blended mesh ordering issue HOT 2
- Terrain remeshing bug when block is neither solid nor opaque HOT 3
- Custom voxel occasionally leaves one side after removal. HOT 4
- UV offsets wrapping at edges of blocks HOT 2
- Meshing with non-opaque blocks is incredibly slow + block textures with alpha dont work HOT 4
- custom renderMaterial performance (for animated textures) HOT 2
- Supporting noa HOT 2
- Does NOA support child meshes? HOT 3
- webgpu? HOT 2
- How to define new objects in NOA engine. HOT 5
- Optimal octreeBlockSize
- What is the best way to manually build worlds? HOT 2
- render all blocks even if covered HOT 1
- How to import an obj model?
- refresh the registry on the go HOT 2
- Making a set world.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from noa.