Skip to content

Instantly share code, notes, and snippets.

View shrinktofit's full-sized avatar

Leslie Leigh (李的序) shrinktofit

View GitHub Profile
@shrinktofit
shrinktofit / SkeletonDisplay.ts
Created May 7, 2020 08:05
Visualize skeleton in Cocos Creator 3D
import { _decorator, Component, Node, renderer, director, Material, GFXPrimitiveMode, Mesh, GFXBufferUsageBit, GFXMemoryUsageBit, Mat4, Vec3, IGFXAttribute, GFXFormat, GFXAttributeName, Scene, GFXBuffer, GFXComparisonFunc } from 'cc';
type RenderingSubMesh = Parameters<renderer.Model['initSubModel']>[1];
class VisualRelations {
private _buffer: Float32Array;
private _relationIndices: number[] = [];
private _watchedNodes: Node[] = [];
private _minPos: Vec3 = new Vec3();
private _maxPos: Vec3 = new Vec3();
@shrinktofit
shrinktofit / index.md
Last active June 5, 2020 06:07
An animation system for Cocos Creator(3D): NewGenAnim

An animation system for Cocos Creator(3D): NewGenAnim

Introduction

This article introduces an animation system for Cocos Creator(3D). "NewGenAnim" is its name during development.

Motivation

:)

@shrinktofit
shrinktofit / gist:d49a258e1ae4c76be9d45255ea111d30
Created September 22, 2020 06:26
[WebGL] Print shader numeric type precisions
const shaderTypes: [number, string][] = [
[gl.VERTEX_SHADER, 'Vertex shader'],
[gl.FRAGMENT_SHADER, 'Fragment shader'],
];
const precisionTypes: [number, string][] = [
[gl.HIGH_FLOAT, 'High float'],
[gl.MEDIUM_FLOAT, 'Medium float'],
[gl.LOW_FLOAT, 'Low float'],
[gl.HIGH_INT, 'High int'],
[gl.MEDIUM_INT, 'Medium int'],
@shrinktofit
shrinktofit / index.md
Last active September 28, 2020 07:18
关于 Node.JS spawn() 的 shell 选项

spawn(command, args, options) 时, 若 options 指定了 shell: true ,将用 shell 来启动目标进程; 否则,(在 Windows 上)将直接调用 command 来创建进程。

一个重要的差别就是 shell 会处理执行参数 args,例如,(在 Windows 上)解释引号:

spawn(command, ['"<含有空格的路径>"'], { shell: true })
@shrinktofit
shrinktofit / Snake.ts
Created September 30, 2020 07:47
Simple snake implementation
interface IVec2 {
x: number;
y: number;
}
interface IBounds {
min: IVec2;
max: IVec2;
@shrinktofit
shrinktofit / Snake.java
Created September 30, 2020 10:39
Snake in Java
class Vec2 {
public int x = 0;
public int y = 0;
public Vec2(int p_x, int p_y) {
this.x = p_x;
this.y = p_y;
}
public Vec2 copy() {
return new Vec2(this.x, this.y);
@shrinktofit
shrinktofit / protobuf.md
Created January 22, 2021 10:00
protobuf 最佳实践

pbjs

执行以下命令生成协议 .js 文件:

pbjs --target static-module --wrap commonjs --out <.js 输出路径> <.proto 输入路径,可为通配符>

pbts

@shrinktofit
shrinktofit / index.js
Last active August 22, 2021 11:59
Copy preserve and redirect symbol link
const { link, copy, ensureDir, stat, readdir, realpath, symlink } = require('fs-extra');
const { relative, join } = require('path');
(async () => {
await myCopy(
String.raw`X:\Temp\editor-ci-build-test\editor-3d\app`,
// String.raw`X:\Temp\6`,
String.raw`X:\Temp\editor-ci-build-test\editor-3d\.publish\CocosCreator\resources\app`,
);
})();
@shrinktofit
shrinktofit / words.md
Last active November 8, 2021 10:44
今天又学会了几个单词
  • elementary

  • rudimentary

  • feasible

  • viable

  • impair

  • interconnect

@shrinktofit
shrinktofit / index.md
Last active November 30, 2021 07:23
线性混合多个指定了权重的值,不要遍历两遍计算出权重的和

image

也就是说,下面两种算法是等价的,我们不需要遍历两遍:

// 预先累加权重和
function blend(samples: ReadonlyArray<readonly [value: number, weight: number]>) {
  let result = 0.0;
  let sumWeights = 0.0;
  for (const [v, w] of samples) {