Skip to content

Commit

Permalink
Noise
Browse files Browse the repository at this point in the history
  • Loading branch information
1j01 committed Feb 7, 2018
1 parent d8f0149 commit 40f32be
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/Chunk.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

@chunks = []

SZ = 150
SZ = 32 #150

createChunkGeometry = ->

Expand Down Expand Up @@ -86,31 +86,40 @@ class @Chunk extends T.Object3D
@_sullied = no

canvas = document.createElement "canvas"
canvas.width = canvas.height = SZ
canvas.width = SZ
canvas.height = SZ #* SZ
tex = new T.Texture canvas
tex.minFilter = T.NearestFilter
tex.magFilter = T.NearestFilter
mat = new T.MeshBasicMaterial map: tex, side: T.DoubleSide, vertexColors: T.VertexColors
# mat = new T.MeshBasicMaterial wireframe: yes, vertexColors: T.VertexColors
mat.transparent = yes
mat.alphaTest = 0.5

ctx = canvas.getContext "2d"

# document.body.appendChild canvas
# canvas.style.position = "absolute"
# canvas.style.right = "0"
# canvas.style.top = "0"

ctx.fillStyle = "blue"
ctx.beginPath()
ctx.arc SZ/2, SZ/2, SZ/3, 0, Math.PI * 2, no
# ctx.arc SZ/2, SZ/2, SZ/2 * Math.sin(i/SZ), 0, Math.PI * 2, no
ctx.fill()
ctx.fillStyle = "white"
ctx.beginPath()
# ctx.arc SZ/2, SZ/2, SZ/2-0.01, 0, Math.PI * 2, no
ctx.arc SZ/2, SZ/2, SZ/3-0.2, 0, Math.PI * 2, no
ctx.fill()

ctx = canvas.getContext "2d"
image_data = ctx.createImageData(SZ, SZ)# * SZ)
for x in [0..SZ]
for y in [0..SZ]
for z in [0..SZ]
index = (x + y * SZ + z * SZ * SZ) * 4
# color = new THREE.Color @get(x, y, z)
# image_data.data[index + 0] = color.r
# image_data.data[index + 1] = color.g
# image_data.data[index + 2] = color.b
image_data.data[index + 0] = Math.random() * 255
image_data.data[index + 1] = Math.random() * 255
image_data.data[index + 2] = Math.random() * 255
image_data.data[index + 3] = 255
ctx.putImageData(image_data, 0, 0)

# ctx.fillStyle = "red"
# ctx.fillRect(0, 0, canvas.width, canvas.height)

tex.needsUpdate = yes

geom = createChunkGeometry()
Expand All @@ -136,10 +145,10 @@ class @Chunk extends T.Object3D
@voxels[x*SZ*SZ + y*SZ + z] = v

init: (fn)->
# for x in [0..SZ]
# for y in [0..SZ]
# for z in [0..SZ]
# @set x, y, z, fn(x+@x*SZ, y+@y*SZ, z+@z*SZ)
for x in [0..SZ]
for y in [0..SZ]
for z in [0..SZ]
@set x, y, z, fn(x+@x*SZ, y+@y*SZ, z+@z*SZ)

update: ->
@debug.visible = scene.debug

0 comments on commit 40f32be

Please sign in to comment.