Skip to content

Commit

Permalink
Progress with shaders etc
Browse files Browse the repository at this point in the history
  • Loading branch information
DVLP committed Feb 28, 2019
1 parent bf70cf7 commit f35863e
Show file tree
Hide file tree
Showing 8 changed files with 441 additions and 411 deletions.
2 changes: 1 addition & 1 deletion server/build/main.build.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
} }
}, },
paths: { paths: {
"THREE": "../js/three-r54" // .min "THREE": "../js/three-r101" // .min
, "async": "../js/async.min" // .min , "async": "../js/async.min" // .min
, "backbone": "../js/backbone-min" // -min , "backbone": "../js/backbone-min" // -min
, "cs": "../js/cs" , "cs": "../js/cs"
Expand Down
Binary file added server/public/a/meshes/car1-diff.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 54 additions & 32 deletions server/public/scripts/client/array_geometry.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -88,43 +88,58 @@ define [
return return


addGeometry: (geom) -> addGeometry: (geom) ->
@addAttribute("index", new THREE.BufferAttribute(new Uint32Array(100), 1)) unless @index index = [];
@addAttribute("position", new THREE.BufferAttribute(new Float32Array(300), 3)) unless @attributes["position"] position = [];
@addAttribute("normal", new THREE.BufferAttribute(new Float32Array(300), 3)) unless @attributes["normal"] normal = [];
@addAttribute("uv", new THREE.BufferAttribute(new Float32Array(200), 1)) unless @attributes["uv"] 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' ] pts = [ 'a', 'b', 'c', 'd' ]
offsetPosition = @attributes["position"].array.length offsetPosition = position.length


for v in geom.vertices 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 for face, faceIndex in geom.faces
if face.d? if face.d?
@index.array.push face.a, face.b, face.d index.push face.a, face.b, face.d
@index.array.push face.b, face.c, face.d index.push face.b, face.c, face.d
else else
@index.array.push face.a, face.b, face.c index.push face.a, face.b, face.c


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


# We support only one channel of UVs. # We support only one channel of UVs.
uvs = geom.faceVertexUvs[0][faceIndex] uvs = geom.faceVertexUvs[0][faceIndex]
for uv, pt in uvs for uv, pt in uvs
@attributes["uv"].array[face[pts[pt]] * 2 + 0] = uv.x uv[face[pts[pt]] * 2 + 0] = uv.x
@attributes["uv"].array[face[pts[pt]] * 2 + 1] = uv.y 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 return


mergeMesh: (mesh) -> mergeMesh: (mesh) ->
@addAttribute("index", new THREE.BufferAttribute(new Uint32Array(100), 1)) unless @index index = [];
@addAttribute("position", new THREE.BufferAttribute(new Float32Array(300), 3)) unless @attributes["position"] position = [];
@addAttribute("normal", new THREE.BufferAttribute(new Float32Array(300), 3)) unless @attributes["normal"] normal = [];
@addAttribute("uv", new THREE.BufferAttribute(new Float32Array(200), 1)) unless @attributes["uv"] 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 geom2 = mesh.geometry
tmpVec3 = new THREE.Vector3 tmpVec3 = new THREE.Vector3


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


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


# Copy indices. # Copy indices.
indexArray = @index.array indexArray = index
for idx in geom2.index.array for idx in geom2.index.array
indexArray.push idx + vertexOffset 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 return


computeBoundingSphere: -> @computeBounds() computeBoundingSphere: -> @computeBounds()
Expand All @@ -166,12 +187,12 @@ define [
max: new THREE.Vector3(-Infinity, -Infinity, -Infinity) max: new THREE.Vector3(-Infinity, -Infinity, -Infinity)
maxRadius = 0 maxRadius = 0
i = 0 i = 0
posns = @attributes["position"].array positions2 = @attributes["position"].array
numVerts = posns.length numVerts = positions2.length
while i < numVerts while i < numVerts
x = posns[i + 0] x = positions2[i + 0]
y = posns[i + 1] y = positions2[i + 1]
z = posns[i + 2] z = positions2[i + 2]
bb.min.x = Math.min bb.min.x, x bb.min.x = Math.min bb.min.x, x
bb.max.x = Math.max bb.max.x, x bb.max.x = Math.max bb.max.x, x
bb.min.y = Math.min bb.min.y, y bb.min.y = Math.min bb.min.y, y
Expand All @@ -185,4 +206,5 @@ define [
@boundingBox = bb @boundingBox = bb
@boundingSphere = @boundingSphere =
radius: maxRadius radius: maxRadius
center: new THREE.Vector2()
return return
14 changes: 11 additions & 3 deletions server/public/scripts/client/misc.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ define [
ringMesh = new THREE.Mesh ringGeom, checkpointMat ringMesh = new THREE.Mesh ringGeom, checkpointMat
ringMesh.rotation.order = 'ZYX' ringMesh.rotation.order = 'ZYX'
ringMesh.rotation.x = 1.1 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 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 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 selectionGeom = new THREE.IcosahedronGeometry 1, 2
selectionMat = new THREE.MeshBasicMaterial selectionMat = new THREE.MeshBasicMaterial
Expand Down
6 changes: 4 additions & 2 deletions server/public/scripts/client/scenery.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ define [
'cs!util/quiver' 'cs!util/quiver'
], (THREE, array_geometry, quiver) -> ], (THREE, array_geometry, quiver) ->


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

mergedGeom.updateOffsets() mergedGeom.updateOffsets()
# Clone the material so that we can adjust opacity per tile. # Clone the material so that we can adjust opacity per tile.
material = object.material.clone() material = object.material.clone()
Expand Down
Loading

0 comments on commit f35863e

Please sign in to comment.