Terrain 删除Sample,Math相关修改 (#5062)

* 删除Sample,Math相关修改

* 删除Sample
This commit is contained in:
Myway
2019-08-02 10:50:25 +08:00
committed by Weiliang Wang
parent ae9129668a
commit 44b5d41ba4
7 changed files with 24 additions and 211 deletions
-1
View File
@@ -23,7 +23,6 @@ export * from './terrain/terrain-editor-paint';
export * from './terrain/terrain-editor-sculpt';
export * from './terrain/terrain-editor';
export * from './terrain/terrain-operation';
export * from './terrain/terrain-sample';
export * from './terrain/terrain';
export { default as ParticleBatchModel } from './models/particle-batch-model';
+1 -1
View File
@@ -1,4 +1,4 @@
import { clamp } from '../../core/vmath';
import { clamp } from '../../core/math';
export class HeightField {
public data: Uint16Array = new Uint16Array();
@@ -1,5 +1,4 @@
import { Rect, Vec3 } from '../../core/value-types';
import { clamp } from '../../core/vmath';
import { clamp, Rect, Vec3 } from '../../core/math';
import { Terrain, TERRAIN_BLOCK_TILE_COMPLEXITY } from './terrain';
import { TerrainBrush, TerrainCircleBrush } from './terrain-brush';
import { TerrainEditorMode } from './terrain-editor-mode';
@@ -156,7 +155,7 @@ export class TerrainEditorPaint extends TerrainEditorMode {
const sum = w.x + w.y + w.z + w.w;
if (sum > 0) {
w.multiply(1.0 / sum);
w.scale(1.0 / sum);
}
if (this._undo != null) {
@@ -1,5 +1,4 @@
import { Rect, Vec3 } from '../../core/value-types';
import { clamp } from '../../core/vmath';
import { clamp, Rect, Vec3 } from '../../core/math';
import { Terrain, TERRAIN_BLOCK_TILE_COMPLEXITY } from './terrain';
import { TerrainBrush, TerrainCircleBrush } from './terrain-brush';
import { TerrainEditorMode } from './terrain-editor-mode';
+1 -1
View File
@@ -1,4 +1,4 @@
import { Rect, Vec2, Vec4 } from '../../core/value-types';
import { Rect, Vec2, Vec4 } from '../../core/math';
import { Terrain, TerrainBlock } from './terrain';
export class TerrainHeightData {
-184
View File
@@ -1,184 +0,0 @@
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
import { Texture2D } from '../../assets';
import { Node } from '../../scene-graph/node';
import { Scene } from '../../scene-graph/scene';
import { Terrain, TerrainInfo, TerrainLayer } from './terrain';
import { TerrainEditor } from './terrain-editor';
import { TerrainEditorManage } from './terrain-editor-manage';
import { eTerrainEditorMode} from './terrain-editor-mode';
import { TerrainEditorPaint } from './terrain-editor-paint';
import { TerrainEditorSculpt } from './terrain-editor-sculpt';
export class TerrainSample {
public terrain: Terrain|null = null;
public editor: TerrainEditor|null = null;
public camera: Node|null = null;
public onInit (scene: Scene) {
console.log('TerrainSample::onInit1');
const info = new TerrainInfo();
info.tileSize = 1;
info.blockCount[0] = 1;
info.blockCount[1] = 1;
const _node = new Node('Terrain');
_node.setParent(scene);
this.terrain = _node.addComponent(Terrain);
if (this.terrain != null) {
// build terrain
this.terrain.build(info);
this.editor = new TerrainEditor();
this.editor.setEditTerrain(this.terrain as Terrain);
// load layer
cc.loader.loadRes('decal_1/texture', Texture2D, (err, asset) => {
const layer = new TerrainLayer();
layer.detailMap = asset;
layer.tileSize = 8.0;
if (this.terrain != null) {
this.terrain.addLayer(layer);
}
});
cc.loader.loadRes('decal_2/texture', Texture2D, (err, asset) => {
const layer = new TerrainLayer();
layer.detailMap = asset;
layer.tileSize = 8.0;
if (this.terrain != null) {
this.terrain.addLayer(layer);
}
});
const paintMode = this.editor.getMode(eTerrainEditorMode.PAINT) as TerrainEditorPaint;
paintMode.setCurrentLayer(0);
}
this.camera = scene.getChildByName('Camera');
if (this.camera == null) {
console.log('Camera is null');
}
}
public onUpdate (dtime: number) {
if (this.editor != null) {
this.editor.update(dtime);
}
}
public onKeyDown (id: number) {
if (this.terrain == null || this.editor == null) {
return;
}
const mode = this.editor.getCurrentModeType();
if (id === cc.macro.KEY.tab) {
// change editor mode
if (mode === eTerrainEditorMode.MANAGE) {
this.editor.setMode(eTerrainEditorMode.SCULPT);
}
else if (mode === eTerrainEditorMode.SCULPT) {
this.editor.setMode(eTerrainEditorMode.PAINT);
}
else if (mode === eTerrainEditorMode.PAINT) {
this.editor.setMode(eTerrainEditorMode.SCULPT);
}
}
else if (mode === eTerrainEditorMode.MANAGE) {
if (id === cc.macro.KEY[1]) {
this.onRebuildHeight();
}
else if (id === cc.macro.KEY[2]) {
this.onRebuildBlock();
}
}
else if (mode === eTerrainEditorMode.SCULPT) {
}
else if (mode === eTerrainEditorMode.PAINT) {
// change current layer
if (id === cc.macro.KEY[1]) {
this.editor.setCurrentLayer(0);
}
else if (id === cc.macro.KEY[2]) {
this.editor.setCurrentLayer(1);
}
}
}
public onMouseDown (id: number, x: number, y: number) {
this.editor!.onMouseDown(id, x, y);
}
public onMouseUp (id: number, x: number, y: number) {
this.editor!.onMouseUp(id, x, y);
}
public onMouseMove (x: number, y: number) {
if (this.editor == null || this.camera == null) {
return;
}
this.editor.onMouseMove(this.camera, x, y);
}
public onRebuildHeight () {
if (this.terrain == null || this.editor == null) {
return;
}
const info = new TerrainInfo();
info.tileSize = this.terrain.info.tileSize * 2;
info.blockCount[0] = this.terrain.info.blockCount[0];
info.blockCount[1] = this.terrain.info.blockCount[1];
info.weightMapSize = this.terrain.info.weightMapSize;
info.lightMapSize = this.terrain.info.lightMapSize;
this.terrain!.rebuild(info);
if (this.camera != null) {
const pos = this.camera.getPosition();
pos.x = info.size.width / 2;
this.camera.setPosition(pos);
}
}
public onRebuildBlock () {
if (this.terrain == null || this.editor == null) {
return;
}
const info = new TerrainInfo();
info.tileSize = this.terrain.info.tileSize;
info.blockCount[0] = this.terrain.info.blockCount[0] + 1;
info.blockCount[1] = this.terrain.info.blockCount[1] + 1;
info.weightMapSize = this.terrain.info.weightMapSize;
info.lightMapSize = this.terrain.info.lightMapSize;
this.terrain.rebuild(info);
if (this.camera != null) {
const pos = this.camera.getPosition();
pos.x = info.size.width / 2;
this.camera.setPosition(pos);
}
}
public onRebuildWeight () {
if (this.terrain == null || this.editor == null) {
return;
}
const info = new TerrainInfo();
info.tileSize = this.terrain.info.tileSize;
info.blockCount[0] = this.terrain.info.blockCount[0];
info.blockCount[1] = this.terrain.info.blockCount[1];
info.weightMapSize = 256;
info.lightMapSize = this.terrain.info.lightMapSize;
this.terrain.rebuild(info);
}
}
+19 -19
View File
@@ -8,14 +8,14 @@ import { Texture2D } from '../../assets';
import { Filter, PixelFormat, WrapMode } from '../../assets/asset-enum';
import { Component } from '../../components';
import { ccclass, executeInEditMode, menu, property } from '../../core/data/class-decorator';
import { Rect, Size, Vec2, Vec3, Vec4 } from '../../core/value-types';
import { clamp, vec3, vec4 } from '../../core/vmath';
import { clamp, Rect, Size, Vec2, Vec3, Vec4 } from '../../core/math';
import { GFXBuffer } from '../../gfx/buffer';
import { GFXAttributeName, GFXBufferUsageBit, GFXFormat, GFXMemoryUsageBit, GFXPrimitiveMode } from '../../gfx/define';
import { GFXDevice } from '../../gfx/device';
import { IGFXAttribute } from '../../gfx/input-assembler';
import { Model } from '../../renderer/scene/model';
import { Node } from '../../scene-graph/node';
import { INode } from '../../core/utils/interfaces';
import { PrivateNode } from '../../scene-graph/private-node';
import { IDefineMap } from '../core/pass';
import { HeightField } from './height-field';
@@ -200,7 +200,7 @@ export class TerrainBlock {
this._index[1] = j;
this._node = new PrivateNode('');
this._node.setParent(this._terrain.node);
this._node.setParent(this._terrain.node as Node);
this._node._objFlags |= cc.Object.Flags.DontSave;
this._renderable = this._node.addComponent(TerrainRenderable) as TerrainRenderable;
@@ -866,7 +866,7 @@ export class Terrain extends Component {
const c = this.getNormal(ix0, iz1);
const d = this.getNormal(ix1, iz1);
const m = new Vec3();
vec3.add(m, b, c).multiply(0.5);
Vec3.add(m, b, c).scale(0.5);
if (dx + dz <= 1.0) {
d.set(m);
@@ -882,9 +882,9 @@ export class Terrain extends Component {
const n1 = new Vec3();
const n2 = new Vec3();
const n = new Vec3();
vec3.lerp(n1, a, b, dx);
vec3.lerp(n2, c, d, dx);
vec3.lerp(n, n1, n2, dz);
Vec3.lerp(n1, a, b, dx);
Vec3.lerp(n2, c, d, dx);
Vec3.lerp(n, n1, n2, dz);
return n;
}
@@ -935,23 +935,23 @@ export class Terrain extends Component {
const c = this.getWeight(ix0, iz1);
let d = this.getWeight(ix1, iz1);
const m = new Vec4();
vec4.add(m, b, c).multiply(0.5);
Vec4.add(m, b, c).scale(0.5);
if (dx + dz <= 1.0) {
d = new Vec4();
vec3.sub(d, m, a).add(m);
Vec4.subtract(d, m, a).add(m);
}
else {
a = new Vec4();
vec3.sub(a, m, d).add(m);
Vec4.subtract(a, m, d).add(m);
}
const n1 = new Vec4();
const n2 = new Vec4();
const n = new Vec4();
vec3.lerp(n1, a, b, dx);
vec3.lerp(n2, c, d, dx);
vec3.lerp(n, n1, n2, dz);
Vec4.lerp(n1, a, b, dx);
Vec4.lerp(n2, c, d, dx);
Vec4.lerp(n, n1, n2, dz);
return n;
}
@@ -981,7 +981,7 @@ export class Terrain extends Component {
const dstep = new Vec3();
dstep.set(dir);
dstep.multiply(step);
dstep.scale(step);
if (dir.equals(new Vec3(0, 1, 0))) {
const y = this.getHeightAt(trace.x, trace.z);
@@ -1039,7 +1039,7 @@ export class Terrain extends Component {
const normal = new Vec3();
normal.set(up);
normal.cross(right);
normal.multiply(flip);
normal.scale(flip);
normal.normalize();
return normal;
@@ -1215,7 +1215,7 @@ export class Terrain extends Component {
const c = getWeight(ix0 + xoff, iz1 + yoff, this._weights);
const d = getWeight(ix1 + xoff, iz1 + yoff, this._weights);
const m = new Vec4();
vec4.add(m, b, c).multiply(0.5);
Vec4.add(m, b, c).scale(0.5);
if (dx + dz <= 1.0) {
d.set(m);
@@ -1231,9 +1231,9 @@ export class Terrain extends Component {
const n1 = new Vec4();
const n2 = new Vec4();
const n = new Vec4();
vec3.lerp(n1, a, b, dx);
vec3.lerp(n2, c, d, dx);
vec3.lerp(n, n1, n2, dz);
Vec4.lerp(n1, a, b, dx);
Vec4.lerp(n2, c, d, dx);
Vec4.lerp(n, n1, n2, dz);
const du = i * this.info.weightMapSize + u;
const dv = j * this.info.weightMapSize + v;