agentscript
Version:
AgentScript Model in Model/View architecture
74 lines (62 loc) • 2.22 kB
HTML
<html>
<head>
<title>terrain1</title>
</head>
<body>
<script type="module">
import * as util from 'https://code.agentscript.org/src/utils.js'
import World from 'https://code.agentscript.org/src/World.js'
import Animator from 'https://code.agentscript.org/src/Animator.js'
import { redfishUSA } from 'https://code.agentscript.org/src/TileData.js'
import Model from 'https://code.agentscript.org/models/HelloModel.js'
import { THREE } from 'https://code.agentscript.org/vendor/three.js'
import ThreeDraw from 'https://code.agentscript.org/src/ThreeDraw.js'
const [Z, X, Y] = [13, 1594, 3339]
const elevation = await redfishUSA.zxyToDataSet(Z, X, Y)
const el0to10 = elevation.scale(0, 10)
const model = new Model(World.defaultOptions(50))
model.population = 0
model.patches.importDataSet(el0to10, 'z')
await model.startup()
model.setup()
// REMIND: fix patches to update only once
const drawOptions = {
patchesMesh: {
meshClass: 'PatchesMesh',
useSegments: true,
},
patchesMap: 'Jet',
patchesColor: p => {
const map = view.drawOptions.patchesMap
const color = map.scaleColor(p.z, 0, 10)
return color
},
}
const view = new ThreeDraw(
model,
{ div: 'modelDiv' },
drawOptions
)
const data = el0to10.resample(102, 102).data
const geometry = view.meshes.patches.mesh.geometry
const pos = geometry.getAttribute('position')
const a = pos.array
util.repeat(a.length / 3, (i, a) => (a[i * 3 + 2] = data[i]), a)
geometry.setAttribute(
'position',
new THREE.BufferAttribute(a, 3)
)
util.toWindow({ util, model, view })
await new Animator(
() => {
model.step()
view.draw()
},
1, // just draw once, is static
30
)
view.idle()
</script>
<div id="modelDiv"></div>
</body>
</html>