webpack简易配置

目录结构

1
2
3
4
5
6
7
8
9
webpack-demo
|- tsconfig.json
|- webpack.config.js
|- /dist
|- bundle.js
|- index.html
|- /src
|- index.ts
|- /node_modules

tsconfig

1
2
3
4
5
6
7
8
9
10
11
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"jsx": "react",
"allowJs": true,
"sourceMap":true
}
}

阅读更多

three.js的线与三角形的笔记

线line:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var line3 = new THREE.Line3();

line3.start = new THREE.Vector3(0,0,0);
line3.end = new THREE.Vector3(0,0,10);

var center = new THREE.Vector3();
//line3.getCenter(center);
//center = center.addVectors(line3.start,line3.end).multiplyScalar(0.5);
let distance = line3.distance();

console.log(distance);//10

//console.log(Math.sqrt(2*2 + 2*2));
//console.log(line3.start.distanceTo(line3.end))

阅读更多

node保存图片

环境是前端发出一张BASE64编码的图片,后端将base64建立缓冲区,并转为字符串,通过fs进行写入

1
2
3
4
5
6
7
8
9
let headImgSave = function (image){
let binaryData = Buffer.from(image,"base64").toString("binary");
let openid = Math.random().toString(26).substr(2,8);
let imgPath = path.join(__dirname, `upload`);
let headImg = `${imgPath}/${openid}.jpg`;
fs.writeFile(headImg,binaryData,'binary',function (err){
if(err) throw err;
})
}

pixi的webgl导出异常

Canvas导出图片是没有问题的,但是WebGL模式下导出图片,在IOS上会导致上下逆转,如何解决这个问题,PIXI有专门的插件

1
const img = app.renderer.plugins.extract.image(app.stage);

这样的话,就不用先导出base64,然后再创建图片,而且也不会发生上下逆转