Skip to content
Permalink
Browse files

Progress with shaders etc

  • Loading branch information...
DVLP committed Feb 28, 2019
1 parent bf70cf7 commit f35863e1eaeb097bcfb9e6ecdc686fe65c927c56
@@ -22,7 +22,7 @@
}
},
paths: {
"THREE": "../js/three-r54" // .min
"THREE": "../js/three-r101" // .min
, "async": "../js/async.min" // .min
, "backbone": "../js/backbone-min" // -min
, "cs": "../js/cs"
Binary file not shown.
@@ -88,43 +88,58 @@ define [
return

addGeometry: (geom) ->
@addAttribute("index", new THREE.BufferAttribute(new Uint32Array(100), 1)) unless @index
@addAttribute("position", new THREE.BufferAttribute(new Float32Array(300), 3)) unless @attributes["position"]
@addAttribute("normal", new THREE.BufferAttribute(new Float32Array(300), 3)) unless @attributes["normal"]
@addAttribute("uv", new THREE.BufferAttribute(new Float32Array(200), 1)) unless @attributes["uv"]
index = [];
position = [];
normal = [];
uv = [];

index = Array.prototype.slice(@index.array) if @index
position = Array.prototype.slice(@attributes["position"].array) if @attributes["position"]
normal = Array.prototype.slice(@attributes["normal"].array) if @attributes["normal"]
uv = Array.prototype.slice(@attributes["uv"].array) if @attributes["uv"]

pts = [ 'a', 'b', 'c', 'd' ]
offsetPosition = @attributes["position"].array.length
offsetPosition = position.length

for v in geom.vertices
@attributes["position"].array.push v.x, v.y, v.z
position.push v.x, v.y, v.z

for face, faceIndex in geom.faces
if face.d?
@index.array.push face.a, face.b, face.d
@index.array.push face.b, face.c, face.d
index.push face.a, face.b, face.d
index.push face.b, face.c, face.d
else
@index.array.push face.a, face.b, face.c
index.push face.a, face.b, face.c

for norm, pt in face.vertexNormals
@attributes["normal"].array[face[pts[pt]] * 3 + 0] = norm.x
@attributes["normal"].array[face[pts[pt]] * 3 + 1] = norm.y
@attributes["normal"].array[face[pts[pt]] * 3 + 2] = norm.z
normal[face[pts[pt]] * 3 + 0] = norm.x
normal[face[pts[pt]] * 3 + 1] = norm.y
normal[face[pts[pt]] * 3 + 2] = norm.z

# We support only one channel of UVs.
uvs = geom.faceVertexUvs[0][faceIndex]
for uv, pt in uvs
@attributes["uv"].array[face[pts[pt]] * 2 + 0] = uv.x
@attributes["uv"].array[face[pts[pt]] * 2 + 1] = uv.y
uv[face[pts[pt]] * 2 + 0] = uv.x
uv[face[pts[pt]] * 2 + 1] = uv.y

@setIndex(new THREE.BufferAttribute(new Uint32Array(index), 1))
@addAttribute("position", new THREE.BufferAttribute(new Float32Array(position), 3))
@addAttribute("normal", new THREE.BufferAttribute(new Float32Array(normal), 3))
@addAttribute("uv", new THREE.BufferAttribute(new Float32Array(uv), 2))
return

mergeMesh: (mesh) ->
@addAttribute("index", new THREE.BufferAttribute(new Uint32Array(100), 1)) unless @index
@addAttribute("position", new THREE.BufferAttribute(new Float32Array(300), 3)) unless @attributes["position"]
@addAttribute("normal", new THREE.BufferAttribute(new Float32Array(300), 3)) unless @attributes["normal"]
@addAttribute("uv", new THREE.BufferAttribute(new Float32Array(200), 1)) unless @attributes["uv"]
index = [];
position = [];
normal = [];
uv = [];

index = Array.prototype.slice(@index.array) if @index
position = Array.prototype.slice(@attributes["position"].array) if @attributes["position"]
normal = Array.prototype.slice(@attributes["normal"].array) if @attributes["normal"]
uv = Array.prototype.slice(@attributes["uv"].array) if @attributes["uv"]

vertexOffset = @attributes["position"].array.length / 3
vertexOffset = position.length / 3
geom2 = mesh.geometry
tmpVec3 = new THREE.Vector3

@@ -136,26 +151,32 @@ define [

# Copy vertex data.
i = 0
posns = geom2.attributes["position"].array
positions2 = geom2.attributes["position"].array
norms = geom2.attributes["normal"].array
positionArray = @attributes["position"].array
normalArray = @attributes["normal"].array
hasNorms = norms? and norms.length == posns.length
while i < posns.length
tmpVec3.set posns[i + 0], posns[i + 1], posns[i + 2]
positionArray = position
normalArray = normal
hasNorms = norms? and norms.length == positions2.length
while i < positions2.length
tmpVec3.set positions2[i + 0], positions2[i + 1], positions2[i + 2]
tmpVec3.applyMatrix4 matrix
positionArray.push tmpVec3.x, tmpVec3.y, tmpVec3.z
if hasNorms
tmpVec3.set norms[i + 0], norms[i + 1], norms[i + 2]
tmpVec3.applyMatrix4 matrixRotation
normalArray.push tmpVec3.x, tmpVec3.y, tmpVec3.z
i += 3
@attributes["uv"].array = @attributes["uv"].array.concat geom2.attributes["uv"].array
uv = uv.concat geom2.attributes["uv"].array

# Copy indices.
indexArray = @index.array
indexArray = index
for idx in geom2.index.array
indexArray.push idx + vertexOffset

@setIndex(new THREE.BufferAttribute(new Uint32Array(index), 1))
@addAttribute("position", new THREE.BufferAttribute(new Float32Array(position), 3))
@addAttribute("normal", new THREE.BufferAttribute(new Float32Array(normal), 3))
@addAttribute("uv", new THREE.BufferAttribute(new Float32Array(uv), 2))

return

computeBoundingSphere: -> @computeBounds()
@@ -166,12 +187,12 @@ define [
max: new THREE.Vector3(-Infinity, -Infinity, -Infinity)
maxRadius = 0
i = 0
posns = @attributes["position"].array
numVerts = posns.length
positions2 = @attributes["position"].array
numVerts = positions2.length
while i < numVerts
x = posns[i + 0]
y = posns[i + 1]
z = posns[i + 2]
x = positions2[i + 0]
y = positions2[i + 1]
z = positions2[i + 2]
bb.min.x = Math.min bb.min.x, x
bb.max.x = Math.max bb.max.x, x
bb.min.y = Math.min bb.min.y, y
@@ -185,4 +206,5 @@ define [
@boundingBox = bb
@boundingSphere =
radius: maxRadius
center: new THREE.Vector2()
return
@@ -17,11 +17,19 @@ define [
ringMesh = new THREE.Mesh ringGeom, checkpointMat
ringMesh.rotation.order = 'ZYX'
ringMesh.rotation.x = 1.1
checkpointGeom.merge(ringMesh.geometry)
ringMesh.updateMatrix();
matrix = ringMesh.matrix;
checkpointGeom.merge(ringMesh.geometry, matrix)

ringMesh.rotation.z = Math.PI * 2 / 3
checkpointGeom.merge(ringMesh.geometry)
ringMesh.updateMatrix();
matrix = ringMesh.matrix;
checkpointGeom.merge(ringMesh.geometry, matrix)

ringMesh.rotation.z = Math.PI * 4 / 3
checkpointGeom.merge(ringMesh.geometry)
ringMesh.updateMatrix();
matrix = ringMesh.matrix;
checkpointGeom.merge(ringMesh.geometry, matrix)

selectionGeom = new THREE.IcosahedronGeometry 1, 2
selectionMat = new THREE.MeshBasicMaterial
@@ -8,6 +8,7 @@ define [
'cs!util/quiver'
], (THREE, array_geometry, quiver) ->

tmpVec3 = new THREE.Vector3()
RenderScenery: class RenderScenery
constructor: (@scene, @scenery, @loadFunc) ->
@fadeSpeed = 2
@@ -44,9 +45,10 @@ define [
mesh.scale.copy object.scale
if renderConfig.scale? then mesh.scale.multiplyScalar renderConfig.scale
mesh.scale.multiplyScalar entity.scale
mesh.position.sub entity.position, tile.position
mesh.rotation.add object.rotation, entity.rotation
mesh.position.subVectors entity.position, tile.position
mesh.rotation.copy tmpVec3.addVectors(object.rotation, entity.rotation)
mergedGeom.mergeMesh mesh

mergedGeom.updateOffsets()
# Clone the material so that we can adjust opacity per tile.
material = object.material.clone()
Oops, something went wrong.

0 comments on commit f35863e

Please sign in to comment.
You can’t perform that action at this time.