|
@@ -8,10 +8,11 @@ import REGL = require('regl');
|
|
|
import * as glContext from 'mol-gl/context'
|
|
|
import { Camera } from 'mol-gl/camera'
|
|
|
import { Vec3, Mat4 } from 'mol-math/linear-algebra'
|
|
|
-import PointRenderable from 'mol-gl/renderable/point'
|
|
|
-import MeshRenderable from 'mol-gl/renderable/mesh'
|
|
|
+import { PointRenderable, MeshRenderable } from 'mol-gl/renderable'
|
|
|
import Attribute from 'mol-gl/attribute';
|
|
|
import Model from 'mol-gl/model';
|
|
|
+import { createTransformAttributes } from 'mol-gl/renderable/util';
|
|
|
+import { calculateTextureInfo } from 'mol-gl/util';
|
|
|
// import { positionFromModel } from 'mol-geo/shape/point'
|
|
|
|
|
|
export default class State {
|
|
@@ -42,28 +43,54 @@ export default class State {
|
|
|
const model2 = Model(regl, { position: p1 })
|
|
|
const model3 = Model(regl, { position: p2 })
|
|
|
|
|
|
- const position = Attribute.create(regl, new Float32Array([0, -1, 0, -1, 0, 0, 1, 1, 0]), 3)
|
|
|
+ const position = Attribute.create(regl, new Float32Array([0, -1, 0, -1, 0, 0, 1, 1, 0]), { size: 3 })
|
|
|
|
|
|
const transformArray1 = new Float32Array(16)
|
|
|
const transformArray2 = new Float32Array(16 * 3)
|
|
|
const m4 = Mat4.identity()
|
|
|
- Mat4.toArray(m4, transformArray1)
|
|
|
- Mat4.toArray(m4, transformArray2)
|
|
|
+ Mat4.toArray(m4, transformArray1, 0)
|
|
|
+ Mat4.toArray(m4, transformArray2, 0)
|
|
|
Mat4.setTranslation(m4, p1)
|
|
|
Mat4.toArray(m4, transformArray2, 16)
|
|
|
Mat4.setTranslation(m4, p2)
|
|
|
Mat4.toArray(m4, transformArray2, 32)
|
|
|
- const transform1 = Attribute.create(regl, transformArray1, 16, 1)
|
|
|
- const transform2 = Attribute.create(regl, transformArray2, 16, 1)
|
|
|
|
|
|
- // TODO use https://github.com/substack/glsl-matrix-texture
|
|
|
+ const colorTexInfo = calculateTextureInfo(3, 3)
|
|
|
+ const color = new Uint8Array(colorTexInfo.length)
|
|
|
+ color.set([
|
|
|
+ 0, 0, 255,
|
|
|
+ 0, 255, 0,
|
|
|
+ 255, 0, 0
|
|
|
+ ])
|
|
|
+ console.log(color, colorTexInfo)
|
|
|
+ const colorTex = regl.texture({
|
|
|
+ width: colorTexInfo.width,
|
|
|
+ height: colorTexInfo.height,
|
|
|
+ format: 'rgb',
|
|
|
+ type: 'uint8',
|
|
|
+ wrapS: 'clamp',
|
|
|
+ wrapT: 'clamp',
|
|
|
+ data: color
|
|
|
+ })
|
|
|
|
|
|
// position.update((array: Float32Array) => {
|
|
|
// positionFromModel({}, array, 0)
|
|
|
// })
|
|
|
|
|
|
- const points = PointRenderable.create(regl, { position, transform: transform1 })
|
|
|
- const mesh = MeshRenderable.create(regl, { position, transform: transform2 })
|
|
|
+ const points = PointRenderable.create(regl, {
|
|
|
+ position,
|
|
|
+ ...createTransformAttributes(regl, transformArray1)
|
|
|
+ })
|
|
|
+ const mesh = MeshRenderable.create(regl,
|
|
|
+ {
|
|
|
+ position,
|
|
|
+ ...createTransformAttributes(regl, transformArray2)
|
|
|
+ },
|
|
|
+ {
|
|
|
+ colorTex,
|
|
|
+ colorTexSize: [ colorTexInfo.width, colorTexInfo.height ]
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
const baseContext = regl({
|
|
|
context: {
|
|
@@ -80,11 +107,12 @@ export default class State {
|
|
|
camera.update((state: any) => {
|
|
|
if (!camera.isDirty()) return
|
|
|
baseContext(() => {
|
|
|
- console.log(ctx)
|
|
|
+ // console.log(ctx)
|
|
|
regl.clear({color: [0, 0, 0, 1]})
|
|
|
position.update(array => { array[0] = Math.random() })
|
|
|
// points.update(a => { a.position[0] = Math.random() })
|
|
|
mesh.draw()
|
|
|
+ points.draw()
|
|
|
model1({}, ({ transform }) => {
|
|
|
points.draw()
|
|
|
})
|