当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript painterState.addSystem函数代码示例

本文整理汇总了TypeScript中shared-utils/painterState.addSystem函数的典型用法代码示例。如果您正苦于以下问题:TypeScript addSystem函数的具体用法?TypeScript addSystem怎么用?TypeScript addSystem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了addSystem函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: addSystem

import { addSystem } from 'shared-utils/painterState'
import { events, paint } from './context'

const ctx = paint.getContext('2d')
if (!ctx) throw Error('unable to initialize 2d context')

const data = ctx.getImageData(0, 0, paint.width, paint.height)

for (let i = 0; i < data.data.length; i += 4) {
	data.data[i] = Math.random() > 0.5 ? 255 : 0
	data.data[i + 3] = 255
}

ctx.putImageData(data, 0, 0)

addSystem('paint', (e, s) => {
	if (e === events.CLEANUP_PAINT) {
		ctx.fillStyle = 'black'
		ctx.fillRect(0, 0, paint.width, paint.height)
	}

	const d = s.device
	if (e === events.PROCESS_PAINT && d.mouse.dragging && d.mouse.drag.event) {
		const { clientX, clientY } = d.mouse.drag.event
		const x = Math.floor((clientX / window.innerWidth) * paint.width)
		const y = Math.floor((clientY / window.innerHeight) * paint.height)
		ctx.fillStyle = 'white'
		ctx.fillRect(x, y, 1, 1)
	}
})
开发者ID:trivial-space,项目名称:playground,代码行数:30,代码来源:paint.ts

示例2: addSystem

export const floorTransform = mat4.create()

export const floorMirrorView = mat4.create()

const planeEquation = geo.planeFromNormalAndCoplanarPoint(
	[0, 1, 0],
	[0, groundHeight, 0]
)
export const floorMirrorMatrix = geo.mirrorMatrixFromPlane(planeEquation)

addSystem('state', (e, s) => {
	if (e === events.FRAME) {
		time += s.device.tpf

		quat.fromEuler(
			rotation,
			Math.sin(0.0007 * time) * 1.1,
			time * 0.001,
			Math.sin(0.0008 * time) * 1.1
		)

		mat4.fromRotationTranslationScaleOrigin(
			wallsTransform,
			rotation,
			[0, 0, 0],
			[1, 1, 1],
			[0, 100, 0]
		)
	}
})
开发者ID:trivial-space,项目名称:playground,代码行数:30,代码来源:state.ts

示例3: getEffect

	bufferStructure: [bufferSpec, bufferSpec, bufferSpec, bufferSpec],
})

const lightLayer = getEffect(painter, 'light').update({
	frag: lightFrag,
	uniforms: {
		eyePosition: () => state.viewPort.camera.position,
		lightMat: () => state.scene.lightTransforms[0],
		view: () => state.viewPort.camera.viewMat,
		tex: () => texture.image(),
		positions: scene.image(0),
		normals: scene.image(1),
		uvs: scene.image(2),
		colors: scene.image(3),
	},
	drawSettings: {
		enable: [gl.BLEND],
		clearBits: makeClear(gl, 'color'),
	},
})

export const light = getFrame(painter, 'light').update({
	layers: lightLayer,
})

addSystem<State>('renderer', e => {
	if (e === events.RESIZE) {
		scene.update()
	}
})
开发者ID:trivial-space,项目名称:playground,代码行数:30,代码来源:renderer.ts

示例4: getForm

const projection = mat4.perspective(mat4.create(), 45, 1, 0.01, 10)

const form = getForm(painter, 'plane').update(plane(2, 2))

const shade = getShade(painter, 'plane').update({
	vert: planeVert,
	frag: planeFrag,
})

export const sketch = getSketch(painter, 'plane').update({
	form,
	shade,
	uniforms: {
		projection,
		transform: () => mat4.rotateY(planMat, planMat, rotation),
		tex: () => automaton.image(),
	},
	drawSettings: {
		clearColor: [0.0, 1.0, 0.0, 1.0],
		clearBits: makeClear(gl, 'color'),
	},
})

// ===== state =====

addSystem('renderer', e => {
	if (e === events.FRAME) {
		paintFrame.update({ texture: { asset: paint } })
	}
})
开发者ID:trivial-space,项目名称:playground,代码行数:30,代码来源:renderer.ts

示例5:

import './state/tiles'
import './viewport'

import { addSystem, dispatch } from 'shared-utils/painterState'
import { repeat } from 'shared-utils/scheduler'
import { events, painter, State } from './context'
import { tiles } from './renderer'

// state.device.sizeMultiplier = window.devicePixelRatio

addSystem<State>('start', (e, s) => {
	if (e === events.ON_IMAGES_LOADED) {
		repeat(tpf => {
			s.device.tpf = tpf
			dispatch(events.FRAME)
			painter.draw(tiles)
		}, 'loop')
	}
})

dispatch(events.INIT)
开发者ID:trivial-space,项目名称:playground,代码行数:21,代码来源:index.ts

示例6: getBlurByAlphaEffect

const blurEffect = getBlurByAlphaEffect(painter, 'blur', {
	strength: 4,
	strengthOffset: 0.3,
	blurRatioVertical: 3,
	size: [256, 256],
})

export const mirrorScene = getFrame(painter, 'mirror').update({
	layers: [mirrorSceneLayer, blurEffect],
	width: 256,
	height: 256,
	bufferStructure: [
		{
			magFilter: 'LINEAR',
			minFilter: 'LINEAR',
		},
	],
})

export const scene = getFrame(painter, 'scene').update({
	layers: sceneLayer,
})

addSystem<State>('renderer', e => {
	switch (e) {
		case events.RESIZE:
			scene.update()
	}
})
开发者ID:trivial-space,项目名称:playground,代码行数:29,代码来源:renderer.ts

示例7: getFrame

addSystem<State>('render', (e, s) => {
	switch (e) {
		case events.ON_IMAGES_LOADED:
			each((img, key) => {
				textures[key] = getFrame(painter, key).update({
					texture: {
						minFilter: 'LINEAR_MIPMAP_LINEAR',
						magFilter: 'LINEAR',
						asset: img,
					},
				})
			}, s.tiles.images)
			return

		case events.NEW_ACTIVE_TILES:
			tiles.update({
				form,
				shade,
				uniforms: s.tiles.activeTiles.map(tile => ({
					view: () => state.viewPort.camera.viewMat,
					projection: () => state.viewPort.camera.projectionMat,
					transform: tile.transform,
					image: textures[tile.tileSpecId] && textures[tile.tileSpecId].image(),
					color: tile.color,
					connections: tile.connections,
				})),
			})
	}
})
开发者ID:trivial-space,项目名称:playground,代码行数:29,代码来源:renderer.ts


注:本文中的shared-utils/painterState.addSystem函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。