|
@@ -18,7 +18,7 @@ class TerrainRevertData {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class TileRevertData{
|
|
|
|
|
|
+class TileRevertData {
|
|
public var x : Int;
|
|
public var x : Int;
|
|
public var y : Int;
|
|
public var y : Int;
|
|
public var prevHeightMapPixels : hxd.Pixels.PixelsFloat;
|
|
public var prevHeightMapPixels : hxd.Pixels.PixelsFloat;
|
|
@@ -40,6 +40,7 @@ class TerrainEditor {
|
|
public var tmpTexPath : String;
|
|
public var tmpTexPath : String;
|
|
public var textureType = ["_Albedo", "_Normal", "_MetallicGlossAO"];
|
|
public var textureType = ["_Albedo", "_Normal", "_MetallicGlossAO"];
|
|
public var autoCreateTile = false;
|
|
public var autoCreateTile = false;
|
|
|
|
+ public var editContext : hide.prefab.EditContext;
|
|
var brushPreview : hide.prefab.terrain.Brush.BrushPreview;
|
|
var brushPreview : hide.prefab.terrain.Brush.BrushPreview;
|
|
var interactive : h2d.Interactive;
|
|
var interactive : h2d.Interactive;
|
|
var remainingDist = 0.0;
|
|
var remainingDist = 0.0;
|
|
@@ -66,7 +67,7 @@ class TerrainEditor {
|
|
var customRenderer : hide.prefab.terrain.CustomRenderer;
|
|
var customRenderer : hide.prefab.terrain.CustomRenderer;
|
|
var renderMode : RenderMode = PBR;
|
|
var renderMode : RenderMode = PBR;
|
|
|
|
|
|
- public function new(terrainPrefab, undo : hide.ui.UndoHistory){
|
|
|
|
|
|
+ public function new( terrainPrefab : hide.prefab.terrain.Terrain, undo : hide.ui.UndoHistory ) {
|
|
this.terrainPrefab = terrainPrefab;
|
|
this.terrainPrefab = terrainPrefab;
|
|
this.undo = undo;
|
|
this.undo = undo;
|
|
autoCreateTile = terrainPrefab.autoCreateTile;
|
|
autoCreateTile = terrainPrefab.autoCreateTile;
|
|
@@ -77,7 +78,7 @@ class TerrainEditor {
|
|
heightStrokeBufferArray = new hide.prefab.terrain.StrokeBuffer.StrokeBufferArray(RGBA32F, terrainPrefab.heightMapResolution + 1);
|
|
heightStrokeBufferArray = new hide.prefab.terrain.StrokeBuffer.StrokeBufferArray(RGBA32F, terrainPrefab.heightMapResolution + 1);
|
|
weightStrokeBufferArray = new hide.prefab.terrain.StrokeBuffer.StrokeBufferArray(R8, terrainPrefab.weightMapResolution);
|
|
weightStrokeBufferArray = new hide.prefab.terrain.StrokeBuffer.StrokeBufferArray(R8, terrainPrefab.weightMapResolution);
|
|
customRenderer = new hide.prefab.terrain.CustomRenderer("terrainUV");
|
|
customRenderer = new hide.prefab.terrain.CustomRenderer("terrainUV");
|
|
- customScene = new h3d.scene.Scene();
|
|
|
|
|
|
+ customScene = new h3d.scene.Scene(false, false);
|
|
customScene.renderer = customRenderer;
|
|
customScene.renderer = customRenderer;
|
|
#if debug
|
|
#if debug
|
|
customScene.checkPasses = false;
|
|
customScene.checkPasses = false;
|
|
@@ -85,39 +86,54 @@ class TerrainEditor {
|
|
renderMode = terrainPrefab.showChecker ? Checker : PBR;
|
|
renderMode = terrainPrefab.showChecker ? Checker : PBR;
|
|
}
|
|
}
|
|
|
|
|
|
- public function dispose(){
|
|
|
|
|
|
+ public function dispose() {
|
|
if(uvTex != null) uvTex.dispose();
|
|
if(uvTex != null) uvTex.dispose();
|
|
heightStrokeBufferArray.dispose();
|
|
heightStrokeBufferArray.dispose();
|
|
weightStrokeBufferArray.dispose();
|
|
weightStrokeBufferArray.dispose();
|
|
brushPreview.dispose();
|
|
brushPreview.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function save() {
|
|
|
|
+ if( editContext == null ) return;
|
|
|
|
+ var ctx = editContext;
|
|
|
|
+ var datPath = new haxe.io.Path(ctx.rootContext.shared.currentPath);
|
|
|
|
+ datPath.ext = "dat";
|
|
|
|
+ var fullPath = ctx.ide.getPath(datPath.toString() + "/" + terrainPrefab.name);
|
|
|
|
+ if( sys.FileSystem.isDirectory(fullPath) ) {
|
|
|
|
+ var files = sys.FileSystem.readDirectory(fullPath);
|
|
|
|
+ for( f in files )
|
|
|
|
+ sys.FileSystem.deleteFile(fullPath + "/" + f);
|
|
|
|
+ }
|
|
|
|
+ terrainPrefab.saveWeightTextures(ctx.rootContext);
|
|
|
|
+ terrainPrefab.saveHeightTextures(ctx.rootContext);
|
|
|
|
+ }
|
|
|
|
+
|
|
public function update( ?propName : String ) {
|
|
public function update( ?propName : String ) {
|
|
- if(propName == "editor.currentSurface.tilling"
|
|
|
|
|
|
+ if( propName == "editor.currentSurface.tilling"
|
|
|| propName == "editor.currentSurface.offset.x"
|
|
|| propName == "editor.currentSurface.offset.x"
|
|
|| propName == "editor.currentSurface.offset.y"
|
|
|| propName == "editor.currentSurface.offset.y"
|
|
|| propName == "editor.currentSurface.angle"
|
|
|| propName == "editor.currentSurface.angle"
|
|
|| propName == "editor.currentSurface.minHeight"
|
|
|| propName == "editor.currentSurface.minHeight"
|
|
|| propName == "editor.currentSurface.maxHeight"
|
|
|| propName == "editor.currentSurface.maxHeight"
|
|
- || propName == "editor.currentSurface.parallaxAmount")
|
|
|
|
|
|
+ || propName == "editor.currentSurface.parallaxAmount" )
|
|
terrainPrefab.terrain.updateSurfaceParams();
|
|
terrainPrefab.terrain.updateSurfaceParams();
|
|
autoCreateTile = terrainPrefab.autoCreateTile;
|
|
autoCreateTile = terrainPrefab.autoCreateTile;
|
|
- if(propName == "editor.renderMode") updateRender();
|
|
|
|
|
|
+ if( propName == "editor.renderMode" ) updateRender();
|
|
}
|
|
}
|
|
|
|
|
|
- public function refresh(){
|
|
|
|
|
|
+ public function refresh() {
|
|
brushPreview.refreshMesh();
|
|
brushPreview.refreshMesh();
|
|
heightStrokeBufferArray.refresh(terrainPrefab.heightMapResolution + 1);
|
|
heightStrokeBufferArray.refresh(terrainPrefab.heightMapResolution + 1);
|
|
weightStrokeBufferArray.refresh(terrainPrefab.weightMapResolution);
|
|
weightStrokeBufferArray.refresh(terrainPrefab.weightMapResolution);
|
|
}
|
|
}
|
|
|
|
|
|
- function updateRender(){
|
|
|
|
- for(tile in terrainPrefab.terrain.tiles)
|
|
|
|
|
|
+ function updateRender() {
|
|
|
|
+ for( tile in terrainPrefab.terrain.tiles )
|
|
tile.material.removePass(tile.material.getPass("overlay"));
|
|
tile.material.removePass(tile.material.getPass("overlay"));
|
|
terrainPrefab.terrain.showChecker = false;
|
|
terrainPrefab.terrain.showChecker = false;
|
|
terrainPrefab.terrain.showComplexity = false;
|
|
terrainPrefab.terrain.showComplexity = false;
|
|
terrainPrefab.showChecker = false;
|
|
terrainPrefab.showChecker = false;
|
|
- switch(renderMode){
|
|
|
|
|
|
+ switch( renderMode ) {
|
|
case PBR :
|
|
case PBR :
|
|
case ShaderComplexity : terrainPrefab.terrain.showComplexity = true;
|
|
case ShaderComplexity : terrainPrefab.terrain.showComplexity = true;
|
|
case Checker :
|
|
case Checker :
|
|
@@ -126,12 +142,12 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function renderTerrainUV(ctx : Context){
|
|
|
|
- if(customScene == null) return;
|
|
|
|
|
|
+ function renderTerrainUV( ctx : Context ) {
|
|
|
|
+ if( customScene == null ) return;
|
|
var engine = h3d.Engine.getCurrent();
|
|
var engine = h3d.Engine.getCurrent();
|
|
var mainScene = @:privateAccess ctx.local3d.getScene();
|
|
var mainScene = @:privateAccess ctx.local3d.getScene();
|
|
|
|
|
|
- if(uvTex == null || uvTex.width != Std.int(h3d.Engine.getCurrent().width * uvTexRes) || uvTex.height != Std.int(h3d.Engine.getCurrent().height * uvTexRes)){
|
|
|
|
|
|
+ if( uvTex == null || uvTex.width != Std.int(h3d.Engine.getCurrent().width * uvTexRes) || uvTex.height != Std.int(h3d.Engine.getCurrent().height * uvTexRes) ) {
|
|
if(uvTex != null) {
|
|
if(uvTex != null) {
|
|
uvTex.depthBuffer.dispose();
|
|
uvTex.depthBuffer.dispose();
|
|
uvTex.dispose();
|
|
uvTex.dispose();
|
|
@@ -145,7 +161,7 @@ class TerrainEditor {
|
|
brushPreview.reset();
|
|
brushPreview.reset();
|
|
|
|
|
|
var tiles = terrainPrefab.terrain.getVisibleTiles(mainScene.camera);
|
|
var tiles = terrainPrefab.terrain.getVisibleTiles(mainScene.camera);
|
|
- for(i in 0 ... tiles.length){
|
|
|
|
|
|
+ for( i in 0 ... tiles.length ) {
|
|
var tile = tiles[i];
|
|
var tile = tiles[i];
|
|
var p = new h3d.mat.Pass("terrainUV");
|
|
var p = new h3d.mat.Pass("terrainUV");
|
|
p.addShader(new h3d.shader.BaseMesh());
|
|
p.addShader(new h3d.shader.BaseMesh());
|
|
@@ -168,7 +184,7 @@ class TerrainEditor {
|
|
customScene.render(engine);
|
|
customScene.render(engine);
|
|
engine.popTarget();
|
|
engine.popTarget();
|
|
|
|
|
|
- for(tile in tiles)
|
|
|
|
|
|
+ for( tile in tiles )
|
|
tile.material.removePass(tile.material.getPass("terrainUV"));
|
|
tile.material.removePass(tile.material.getPass("terrainUV"));
|
|
|
|
|
|
mainScene.addChild(terrainPrefab.terrain);
|
|
mainScene.addChild(terrainPrefab.terrain);
|
|
@@ -177,12 +193,12 @@ class TerrainEditor {
|
|
uvTexPixels = uvTex.capturePixels();
|
|
uvTexPixels = uvTex.capturePixels();
|
|
}
|
|
}
|
|
|
|
|
|
- function checkTrashBin(){
|
|
|
|
- if(tileTrashBin.length > 0){
|
|
|
|
|
|
+ function checkTrashBin() {
|
|
|
|
+ if( tileTrashBin.length > 0 ) {
|
|
var tileTrashBinTmp = tileTrashBin.copy();
|
|
var tileTrashBinTmp = tileTrashBin.copy();
|
|
tileTrashBin = [];
|
|
tileTrashBin = [];
|
|
undo.change(Custom(function(undo) {
|
|
undo.change(Custom(function(undo) {
|
|
- for(t in tileTrashBinTmp){
|
|
|
|
|
|
+ for( t in tileTrashBinTmp ) {
|
|
undo ? terrainPrefab.terrain.addTile(t, true) : terrainPrefab.terrain.removeTile(t);
|
|
undo ? terrainPrefab.terrain.addTile(t, true) : terrainPrefab.terrain.removeTile(t);
|
|
}
|
|
}
|
|
}));
|
|
}));
|
|
@@ -190,15 +206,15 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function resetStrokeBuffers(){
|
|
|
|
|
|
+ function resetStrokeBuffers() {
|
|
heightStrokeBufferArray.reset();
|
|
heightStrokeBufferArray.reset();
|
|
weightStrokeBufferArray.reset();
|
|
weightStrokeBufferArray.reset();
|
|
}
|
|
}
|
|
|
|
|
|
- function applyStrokeBuffers(){
|
|
|
|
|
|
+ function applyStrokeBuffers() {
|
|
var revertDatas = new Array<TileRevertData>();
|
|
var revertDatas = new Array<TileRevertData>();
|
|
- for(strokeBuffer in heightStrokeBufferArray.strokeBuffers){
|
|
|
|
- if(strokeBuffer.used == true){
|
|
|
|
|
|
+ for( strokeBuffer in heightStrokeBufferArray.strokeBuffers ) {
|
|
|
|
+ if( strokeBuffer.used == true ) {
|
|
var tile = terrainPrefab.terrain.getTile(strokeBuffer.x, strokeBuffer.y);
|
|
var tile = terrainPrefab.terrain.getTile(strokeBuffer.x, strokeBuffer.y);
|
|
strokeBuffer.tempTex = tile.heightMap;
|
|
strokeBuffer.tempTex = tile.heightMap;
|
|
tile.heightMap = strokeBuffer.prevTex;
|
|
tile.heightMap = strokeBuffer.prevTex;
|
|
@@ -206,7 +222,7 @@ class TerrainEditor {
|
|
var revert = new TileRevertData(strokeBuffer.x, strokeBuffer.y);
|
|
var revert = new TileRevertData(strokeBuffer.x, strokeBuffer.y);
|
|
revert.prevHeightMapPixels = tile.getHeightPixels();
|
|
revert.prevHeightMapPixels = tile.getHeightPixels();
|
|
|
|
|
|
- switch(currentBrush.brushMode.mode){
|
|
|
|
|
|
+ switch( currentBrush.brushMode.mode ) {
|
|
case AddSub :
|
|
case AddSub :
|
|
copyPass.apply(strokeBuffer.tex, tile.heightMap, currentBrush.brushMode.subAction ? Sub : Add);
|
|
copyPass.apply(strokeBuffer.tex, tile.heightMap, currentBrush.brushMode.subAction ? Sub : Add);
|
|
tile.needNewPixelCapture = true;
|
|
tile.needNewPixelCapture = true;
|
|
@@ -233,33 +249,33 @@ class TerrainEditor {
|
|
revertDatas.push(revert);
|
|
revertDatas.push(revert);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- for(strokeBuffer in heightStrokeBufferArray.strokeBuffers){
|
|
|
|
- if(strokeBuffer.used == true){
|
|
|
|
|
|
+ for( strokeBuffer in heightStrokeBufferArray.strokeBuffers ) {
|
|
|
|
+ if( strokeBuffer.used == true ) {
|
|
var tile = terrainPrefab.terrain.getTile(strokeBuffer.x, strokeBuffer.y);
|
|
var tile = terrainPrefab.terrain.getTile(strokeBuffer.x, strokeBuffer.y);
|
|
tile.blendEdges();
|
|
tile.blendEdges();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
terrainPrefab.terrain.refreshTiles();
|
|
terrainPrefab.terrain.refreshTiles();
|
|
|
|
|
|
- if(revertDatas.length > 0){
|
|
|
|
|
|
+ if( revertDatas.length > 0 ) {
|
|
undo.change(Custom(function(undo) {
|
|
undo.change(Custom(function(undo) {
|
|
- for(revertData in revertDatas){
|
|
|
|
|
|
+ for( revertData in revertDatas ) {
|
|
var tile = terrainPrefab.terrain.getTile(revertData.x, revertData.y);
|
|
var tile = terrainPrefab.terrain.getTile(revertData.x, revertData.y);
|
|
- if(tile == null) continue;
|
|
|
|
|
|
+ if( tile == null ) continue;
|
|
tile.heightMap.uploadPixels(undo ? revertData.prevHeightMapPixels : revertData.nextHeightMapPixels);
|
|
tile.heightMap.uploadPixels(undo ? revertData.prevHeightMapPixels : revertData.nextHeightMapPixels);
|
|
tile.needNewPixelCapture = true;
|
|
tile.needNewPixelCapture = true;
|
|
}
|
|
}
|
|
- for(revertData in revertDatas){
|
|
|
|
|
|
+ for( revertData in revertDatas ) {
|
|
var tile = terrainPrefab.terrain.getTile(revertData.x, revertData.y);
|
|
var tile = terrainPrefab.terrain.getTile(revertData.x, revertData.y);
|
|
- if(tile == null) continue;
|
|
|
|
|
|
+ if( tile == null ) continue;
|
|
tile.blendEdges();
|
|
tile.blendEdges();
|
|
}
|
|
}
|
|
terrainPrefab.terrain.refreshTiles();
|
|
terrainPrefab.terrain.refreshTiles();
|
|
}));
|
|
}));
|
|
}
|
|
}
|
|
|
|
|
|
- for(strokeBuffer in weightStrokeBufferArray.strokeBuffers){
|
|
|
|
- if(strokeBuffer.used == true){
|
|
|
|
|
|
+ for( strokeBuffer in weightStrokeBufferArray.strokeBuffers ) {
|
|
|
|
+ if( strokeBuffer.used == true ) {
|
|
var tile = terrainPrefab.terrain.getTile(strokeBuffer.x, strokeBuffer.y);
|
|
var tile = terrainPrefab.terrain.getTile(strokeBuffer.x, strokeBuffer.y);
|
|
strokeBuffer.tempTex = tile.surfaceWeights[currentBrush.index];
|
|
strokeBuffer.tempTex = tile.surfaceWeights[currentBrush.index];
|
|
tile.surfaceWeights[currentBrush.index] = strokeBuffer.prevTex;
|
|
tile.surfaceWeights[currentBrush.index] = strokeBuffer.prevTex;
|
|
@@ -271,8 +287,8 @@ class TerrainEditor {
|
|
clampWeight.shader.weightTextures = tile.surfaceWeightArray;
|
|
clampWeight.shader.weightTextures = tile.surfaceWeightArray;
|
|
clampWeight.shader.weightCount = tile.surfaceWeights.length;
|
|
clampWeight.shader.weightCount = tile.surfaceWeights.length;
|
|
clampWeight.shader.baseTexIndex = currentBrush.index;
|
|
clampWeight.shader.baseTexIndex = currentBrush.index;
|
|
- for(i in 0 ... tile.surfaceWeights.length){
|
|
|
|
- if(i == currentBrush.index) continue;
|
|
|
|
|
|
+ for( i in 0 ... tile.surfaceWeights.length ) {
|
|
|
|
+ if( i == currentBrush.index ) continue;
|
|
clampWeight.shader.curTexIndex = i;
|
|
clampWeight.shader.curTexIndex = i;
|
|
h3d.Engine.getCurrent().pushTarget(tile.surfaceWeights[i]);
|
|
h3d.Engine.getCurrent().pushTarget(tile.surfaceWeights[i]);
|
|
clampWeight.render();
|
|
clampWeight.render();
|
|
@@ -282,7 +298,7 @@ class TerrainEditor {
|
|
normalizeWeight.shader.weightTextures = tile.surfaceWeightArray;
|
|
normalizeWeight.shader.weightTextures = tile.surfaceWeightArray;
|
|
normalizeWeight.shader.weightCount = tile.surfaceWeights.length;
|
|
normalizeWeight.shader.weightCount = tile.surfaceWeights.length;
|
|
normalizeWeight.shader.baseTexIndex = currentBrush.index;
|
|
normalizeWeight.shader.baseTexIndex = currentBrush.index;
|
|
- for(i in 0 ... tile.surfaceWeights.length){
|
|
|
|
|
|
+ for( i in 0 ... tile.surfaceWeights.length ) {
|
|
normalizeWeight.shader.curTexIndex = i;
|
|
normalizeWeight.shader.curTexIndex = i;
|
|
h3d.Engine.getCurrent().pushTarget(tile.surfaceWeights[i]);
|
|
h3d.Engine.getCurrent().pushTarget(tile.surfaceWeights[i]);
|
|
normalizeWeight.render();
|
|
normalizeWeight.render();
|
|
@@ -290,13 +306,13 @@ class TerrainEditor {
|
|
tile.generateWeightArray();
|
|
tile.generateWeightArray();
|
|
|
|
|
|
var revert : TileRevertData = null;
|
|
var revert : TileRevertData = null;
|
|
- for(r in paintRevertDatas)
|
|
|
|
- if(r.x == strokeBuffer.x && r.y == strokeBuffer.y){
|
|
|
|
|
|
+ for( r in paintRevertDatas )
|
|
|
|
+ if( r.x == strokeBuffer.x && r.y == strokeBuffer.y ) {
|
|
revert = r;
|
|
revert = r;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- if(revert != null)
|
|
|
|
- for(w in tile.surfaceWeights)
|
|
|
|
|
|
+ if( revert != null )
|
|
|
|
+ for( w in tile.surfaceWeights )
|
|
revert.nextWeightMapPixels.push(w.capturePixels());
|
|
revert.nextWeightMapPixels.push(w.capturePixels());
|
|
|
|
|
|
generateIndex.shader.weightTextures = tile.surfaceWeightArray;
|
|
generateIndex.shader.weightTextures = tile.surfaceWeightArray;
|
|
@@ -306,14 +322,14 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if(paintRevertDatas.length > 0){
|
|
|
|
|
|
+ if( paintRevertDatas.length > 0 ) {
|
|
var paintRevertdataTmp = paintRevertDatas.copy();
|
|
var paintRevertdataTmp = paintRevertDatas.copy();
|
|
paintRevertDatas = [];
|
|
paintRevertDatas = [];
|
|
undo.change(Custom(function(undo) {
|
|
undo.change(Custom(function(undo) {
|
|
- for(revertData in paintRevertdataTmp){
|
|
|
|
|
|
+ for( revertData in paintRevertdataTmp ) {
|
|
var tile = terrainPrefab.terrain.getTile(revertData.x, revertData.y);
|
|
var tile = terrainPrefab.terrain.getTile(revertData.x, revertData.y);
|
|
- if(tile == null) continue;
|
|
|
|
- for(i in 0 ... tile.surfaceWeights.length)
|
|
|
|
|
|
+ if (tile == null ) continue;
|
|
|
|
+ for (i in 0 ... tile.surfaceWeights.length )
|
|
tile.surfaceWeights[i].uploadPixels(undo ? revertData.prevWeightMapPixels[i] : revertData.nextWeightMapPixels[i]);
|
|
tile.surfaceWeights[i].uploadPixels(undo ? revertData.prevWeightMapPixels[i] : revertData.nextWeightMapPixels[i]);
|
|
tile.generateWeightArray();
|
|
tile.generateWeightArray();
|
|
generateIndex.shader.weightTextures = tile.surfaceWeightArray;
|
|
generateIndex.shader.weightTextures = tile.surfaceWeightArray;
|
|
@@ -325,11 +341,11 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function previewStrokeBuffers(){
|
|
|
|
- for(strokeBuffer in heightStrokeBufferArray.strokeBuffers){
|
|
|
|
- if(strokeBuffer.used == true){
|
|
|
|
|
|
+ function previewStrokeBuffers() {
|
|
|
|
+ for( strokeBuffer in heightStrokeBufferArray.strokeBuffers ) {
|
|
|
|
+ if( strokeBuffer.used == true ) {
|
|
var tile = terrainPrefab.terrain.getTile(strokeBuffer.x, strokeBuffer.y);
|
|
var tile = terrainPrefab.terrain.getTile(strokeBuffer.x, strokeBuffer.y);
|
|
- switch(currentBrush.brushMode.mode){
|
|
|
|
|
|
+ switch( currentBrush.brushMode.mode ) {
|
|
case AddSub :
|
|
case AddSub :
|
|
copyPass.apply(strokeBuffer.prevTex, tile.heightMap);
|
|
copyPass.apply(strokeBuffer.prevTex, tile.heightMap);
|
|
copyPass.apply(strokeBuffer.tex, tile.heightMap, currentBrush.brushMode.subAction ? Sub : Add);
|
|
copyPass.apply(strokeBuffer.tex, tile.heightMap, currentBrush.brushMode.subAction ? Sub : Add);
|
|
@@ -351,8 +367,8 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- for(strokeBuffer in weightStrokeBufferArray.strokeBuffers){
|
|
|
|
- if(strokeBuffer.used == true){
|
|
|
|
|
|
+ for( strokeBuffer in weightStrokeBufferArray.strokeBuffers ) {
|
|
|
|
+ if( strokeBuffer.used == true ) {
|
|
var tile = terrainPrefab.terrain.getTile(strokeBuffer.x, strokeBuffer.y);
|
|
var tile = terrainPrefab.terrain.getTile(strokeBuffer.x, strokeBuffer.y);
|
|
copyPass.apply(strokeBuffer.prevTex, strokeBuffer.tempTex);
|
|
copyPass.apply(strokeBuffer.prevTex, strokeBuffer.tempTex);
|
|
copyPass.apply(strokeBuffer.tex, strokeBuffer.tempTex, currentBrush.brushMode.subAction ? Sub : Add);
|
|
copyPass.apply(strokeBuffer.tex, strokeBuffer.tempTex, currentBrush.brushMode.subAction ? Sub : Add);
|
|
@@ -362,8 +378,8 @@ class TerrainEditor {
|
|
clampWeight.shader.weightTextures = tile.surfaceWeightArray;
|
|
clampWeight.shader.weightTextures = tile.surfaceWeightArray;
|
|
clampWeight.shader.weightCount = tile.surfaceWeights.length;
|
|
clampWeight.shader.weightCount = tile.surfaceWeights.length;
|
|
clampWeight.shader.baseTexIndex = currentBrush.index;
|
|
clampWeight.shader.baseTexIndex = currentBrush.index;
|
|
- for(i in 0 ... tile.surfaceWeights.length){
|
|
|
|
- if(i == currentBrush.index) continue;
|
|
|
|
|
|
+ for( i in 0 ... tile.surfaceWeights.length) {
|
|
|
|
+ if( i == currentBrush.index ) continue;
|
|
clampWeight.shader.curTexIndex = i;
|
|
clampWeight.shader.curTexIndex = i;
|
|
engine.pushTarget(tile.surfaceWeights[i]);
|
|
engine.pushTarget(tile.surfaceWeights[i]);
|
|
clampWeight.render();
|
|
clampWeight.render();
|
|
@@ -373,7 +389,7 @@ class TerrainEditor {
|
|
normalizeWeight.shader.weightTextures = tile.surfaceWeightArray;
|
|
normalizeWeight.shader.weightTextures = tile.surfaceWeightArray;
|
|
normalizeWeight.shader.weightCount = tile.surfaceWeights.length;
|
|
normalizeWeight.shader.weightCount = tile.surfaceWeights.length;
|
|
normalizeWeight.shader.baseTexIndex = currentBrush.index;
|
|
normalizeWeight.shader.baseTexIndex = currentBrush.index;
|
|
- for(i in 0 ... tile.surfaceWeights.length){
|
|
|
|
|
|
+ for( i in 0 ... tile.surfaceWeights.length ) {
|
|
normalizeWeight.shader.curTexIndex = i;
|
|
normalizeWeight.shader.curTexIndex = i;
|
|
engine.pushTarget(tile.surfaceWeights[i]);
|
|
engine.pushTarget(tile.surfaceWeights[i]);
|
|
normalizeWeight.render();
|
|
normalizeWeight.render();
|
|
@@ -388,7 +404,7 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function projectToGround(ray: h3d.col.Ray) {
|
|
|
|
|
|
+ function projectToGround( ray: h3d.col.Ray ) {
|
|
var minDist = -1.;
|
|
var minDist = -1.;
|
|
var normal = terrainPrefab.terrain.getAbsPos().up();
|
|
var normal = terrainPrefab.terrain.getAbsPos().up();
|
|
var plane = h3d.col.Plane.fromNormalPoint(normal.toPoint(), new h3d.col.Point(terrainPrefab.terrain.getAbsPos().tx, terrainPrefab.terrain.getAbsPos().ty, terrainPrefab.terrain.getAbsPos().tz));
|
|
var plane = h3d.col.Plane.fromNormalPoint(normal.toPoint(), new h3d.col.Point(terrainPrefab.terrain.getAbsPos().tx, terrainPrefab.terrain.getAbsPos().ty, terrainPrefab.terrain.getAbsPos().tz));
|
|
@@ -397,23 +413,23 @@ class TerrainEditor {
|
|
return minDist;
|
|
return minDist;
|
|
}
|
|
}
|
|
|
|
|
|
- function screenToWorld( u : Float, v : Float, ctx : Context) {
|
|
|
|
|
|
+ function screenToWorld( u : Float, v : Float, ctx : Context ) {
|
|
var camera = @:privateAccess ctx.local3d.getScene().camera;
|
|
var camera = @:privateAccess ctx.local3d.getScene().camera;
|
|
var ray = camera.rayFromScreen(u, v);
|
|
var ray = camera.rayFromScreen(u, v);
|
|
var dist = projectToGround(ray);
|
|
var dist = projectToGround(ray);
|
|
return dist >= 0 ? ray.getPoint(dist) : null;
|
|
return dist >= 0 ? ray.getPoint(dist) : null;
|
|
}
|
|
}
|
|
|
|
|
|
- function worldToScreen(wx: Float, wy: Float, wz: Float, ctx : Context) {
|
|
|
|
|
|
+ function worldToScreen( wx: Float, wy: Float, wz: Float, ctx : Context ) {
|
|
var s2d = @:privateAccess ctx.local2d.getScene();
|
|
var s2d = @:privateAccess ctx.local2d.getScene();
|
|
var camera = @:privateAccess ctx.local3d.getScene().camera;
|
|
var camera = @:privateAccess ctx.local3d.getScene().camera;
|
|
- var pt = camera.project(wx, wy, wz, h3d.Engine.getCurrent().width, h3d.Engine.getCurrent().height);
|
|
|
|
- return new h2d.col.Point( hxd.Math.abs(pt.x), hxd.Math.abs(pt.y));
|
|
|
|
|
|
+ var pt = camera.project(wx, wy, wz, h3d.Engine.getCurrent().width, h3d.Engine.getCurrent().height);
|
|
|
|
+ return new h2d.col.Point(hxd.Math.abs(pt.x), hxd.Math.abs(pt.y));
|
|
}
|
|
}
|
|
|
|
|
|
- function getBrushPlanePos(mouseX, mouseY, ctx){
|
|
|
|
|
|
+ function getBrushPlanePos( mouseX : Float, mouseY : Float, ctx : Context ) {
|
|
var worldPos = screenToWorld(mouseX, mouseY, ctx).toVector();
|
|
var worldPos = screenToWorld(mouseX, mouseY, ctx).toVector();
|
|
- if(currentBrush.brushMode.snapToGrid){
|
|
|
|
|
|
+ if( currentBrush.brushMode.snapToGrid ) {
|
|
var localPos = terrainPrefab.terrain.globalToLocal(worldPos.clone());
|
|
var localPos = terrainPrefab.terrain.globalToLocal(worldPos.clone());
|
|
localPos.x = hxd.Math.round(localPos.x / terrainPrefab.terrain.cellSize) * terrainPrefab.terrain.cellSize;
|
|
localPos.x = hxd.Math.round(localPos.x / terrainPrefab.terrain.cellSize) * terrainPrefab.terrain.cellSize;
|
|
localPos.y = hxd.Math.round(localPos.y / terrainPrefab.terrain.cellSize) * terrainPrefab.terrain.cellSize;
|
|
localPos.y = hxd.Math.round(localPos.y / terrainPrefab.terrain.cellSize) * terrainPrefab.terrain.cellSize;
|
|
@@ -423,7 +439,7 @@ class TerrainEditor {
|
|
return worldPos;
|
|
return worldPos;
|
|
}
|
|
}
|
|
|
|
|
|
- function getBrushWorldPosFromTex(worldPos : h3d.Vector, ctx : Context) : h3d.Vector {
|
|
|
|
|
|
+ function getBrushWorldPosFromTex( worldPos : h3d.Vector, ctx : Context ) : h3d.Vector {
|
|
if(currentBrush.brushMode.snapToGrid) return worldPos;
|
|
if(currentBrush.brushMode.snapToGrid) return worldPos;
|
|
var screenPos = worldToScreen(worldPos.x, worldPos.y, worldPos.z, ctx);
|
|
var screenPos = worldToScreen(worldPos.x, worldPos.y, worldPos.z, ctx);
|
|
var brushWorldPos : h3d.Vector = worldPos.clone();
|
|
var brushWorldPos : h3d.Vector = worldPos.clone();
|
|
@@ -432,19 +448,19 @@ class TerrainEditor {
|
|
fetchPos.y = hxd.Math.clamp(fetchPos.y, 0, uvTexPixels.height - 1);
|
|
fetchPos.y = hxd.Math.clamp(fetchPos.y, 0, uvTexPixels.height - 1);
|
|
var pixel = uvTexPixels.getPixelF( Std.int(fetchPos.x), Std.int(fetchPos.y));
|
|
var pixel = uvTexPixels.getPixelF( Std.int(fetchPos.x), Std.int(fetchPos.y));
|
|
var tiles = terrainPrefab.terrain.getVisibleTiles(@:privateAccess ctx.local3d.getScene().camera);
|
|
var tiles = terrainPrefab.terrain.getVisibleTiles(@:privateAccess ctx.local3d.getScene().camera);
|
|
- for(i in 0 ... tiles.length)
|
|
|
|
- if( hxd.Math.ceil(pixel.z) == i)
|
|
|
|
|
|
+ for( i in 0 ... tiles.length )
|
|
|
|
+ if( hxd.Math.ceil(pixel.z) == i )
|
|
brushWorldPos = tiles[i].localToGlobal(new h3d.Vector(pixel.x * terrainPrefab.tileSize, pixel.y * terrainPrefab.tileSize, 0));
|
|
brushWorldPos = tiles[i].localToGlobal(new h3d.Vector(pixel.x * terrainPrefab.tileSize, pixel.y * terrainPrefab.tileSize, 0));
|
|
return brushWorldPos;
|
|
return brushWorldPos;
|
|
}
|
|
}
|
|
|
|
|
|
- function drawBrushPreview( worldPos : h3d.Vector, ctx : Context){
|
|
|
|
|
|
+ function drawBrushPreview( worldPos : h3d.Vector, ctx : Context ) {
|
|
brushPreview.reset();
|
|
brushPreview.reset();
|
|
- if(currentBrush.brushMode.mode == Delete || currentBrush.bitmap == null) return;
|
|
|
|
|
|
+ if( currentBrush.brushMode.mode == Delete || currentBrush.bitmap == null ) return;
|
|
var brushWorldPos = uvTexPixels == null ? worldPos : getBrushWorldPosFromTex(worldPos, ctx);
|
|
var brushWorldPos = uvTexPixels == null ? worldPos : getBrushWorldPosFromTex(worldPos, ctx);
|
|
- if(brushWorldPos == null) return;
|
|
|
|
|
|
+ if( brushWorldPos == null ) return;
|
|
var tiles = terrainPrefab.terrain.getTiles(brushWorldPos.x, brushWorldPos.y, currentBrush.size / 2.0 , false);
|
|
var tiles = terrainPrefab.terrain.getTiles(brushWorldPos.x, brushWorldPos.y, currentBrush.size / 2.0 , false);
|
|
- for(i in 0 ... tiles.length){
|
|
|
|
|
|
+ for( i in 0 ... tiles.length) {
|
|
var tile = tiles[i];
|
|
var tile = tiles[i];
|
|
var brushPos = tile.globalToLocal(brushWorldPos.clone());
|
|
var brushPos = tile.globalToLocal(brushWorldPos.clone());
|
|
brushPos.scale3(1.0 / terrainPrefab.tileSize);
|
|
brushPos.scale3(1.0 / terrainPrefab.tileSize);
|
|
@@ -452,8 +468,8 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function applyBrush(pos, ctx : Context){
|
|
|
|
- switch (currentBrush.brushMode.mode){
|
|
|
|
|
|
+ function applyBrush( pos : h3d.Vector, ctx : Context ) {
|
|
|
|
+ switch ( currentBrush.brushMode.mode ) {
|
|
case Paint: drawSurface(pos, ctx);
|
|
case Paint: drawSurface(pos, ctx);
|
|
case AddSub: drawHeight(pos, ctx);
|
|
case AddSub: drawHeight(pos, ctx);
|
|
case Smooth: drawHeight(pos, ctx);
|
|
case Smooth: drawHeight(pos, ctx);
|
|
@@ -463,10 +479,10 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function useBrush( from : h3d.Vector, to : h3d.Vector, ctx : Context){
|
|
|
|
|
|
+ function useBrush( from : h3d.Vector, to : h3d.Vector, ctx : Context ) {
|
|
var dist = (to.sub(from)).length();
|
|
var dist = (to.sub(from)).length();
|
|
- if(currentBrush.firstClick){
|
|
|
|
- if( currentBrush.brushMode.mode == Set ){
|
|
|
|
|
|
+ if( currentBrush.firstClick ) {
|
|
|
|
+ if( currentBrush.brushMode.mode == Set ) {
|
|
if( currentBrush.brushMode.subAction )
|
|
if( currentBrush.brushMode.subAction )
|
|
currentBrush.brushMode.setHeightValue = terrainPrefab.terrain.getHeight(from.x, from.y);
|
|
currentBrush.brushMode.setHeightValue = terrainPrefab.terrain.getHeight(from.x, from.y);
|
|
else
|
|
else
|
|
@@ -477,14 +493,14 @@ class TerrainEditor {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
var dist = (to.sub(from)).length();
|
|
var dist = (to.sub(from)).length();
|
|
- if(dist + remainingDist >= currentBrush.step){
|
|
|
|
|
|
+ if( dist + remainingDist >= currentBrush.step ) {
|
|
var dir = to.sub(from);
|
|
var dir = to.sub(from);
|
|
dir.normalize();
|
|
dir.normalize();
|
|
var pos = from.clone();
|
|
var pos = from.clone();
|
|
var step = dir.clone();
|
|
var step = dir.clone();
|
|
step.scale3(currentBrush.step);
|
|
step.scale3(currentBrush.step);
|
|
- while(dist + remainingDist >= currentBrush.step){
|
|
|
|
- if(remainingDist > 0){
|
|
|
|
|
|
+ while( dist + remainingDist >= currentBrush.step ) {
|
|
|
|
+ if( remainingDist > 0 ) {
|
|
var firstStep = dir.clone();
|
|
var firstStep = dir.clone();
|
|
firstStep.scale3(currentBrush.step - remainingDist);
|
|
firstStep.scale3(currentBrush.step - remainingDist);
|
|
pos = pos.add(firstStep);
|
|
pos = pos.add(firstStep);
|
|
@@ -500,23 +516,23 @@ class TerrainEditor {
|
|
remainingDist += dist;
|
|
remainingDist += dist;
|
|
}
|
|
}
|
|
|
|
|
|
- public function deleteTile(pos : h3d.Vector, ctx : Context){
|
|
|
|
|
|
+ public function deleteTile( pos : h3d.Vector, ctx : Context ) {
|
|
var brushWorldPos = uvTexPixels == null ? pos : getBrushWorldPosFromTex(pos, ctx);
|
|
var brushWorldPos = uvTexPixels == null ? pos : getBrushWorldPosFromTex(pos, ctx);
|
|
- if(brushWorldPos == null) return;
|
|
|
|
|
|
+ if( brushWorldPos == null ) return;
|
|
var tile = terrainPrefab.terrain.getTileAtWorldPos(brushWorldPos.x, brushWorldPos.y);
|
|
var tile = terrainPrefab.terrain.getTileAtWorldPos(brushWorldPos.x, brushWorldPos.y);
|
|
- if(tile == null) return;
|
|
|
|
|
|
+ if( tile == null ) return;
|
|
terrainPrefab.terrain.removeTile(tile);
|
|
terrainPrefab.terrain.removeTile(tile);
|
|
tileTrashBin.push(tile);
|
|
tileTrashBin.push(tile);
|
|
renderTerrainUV(ctx);
|
|
renderTerrainUV(ctx);
|
|
}
|
|
}
|
|
|
|
|
|
- public function drawSurface(pos : h3d.Vector, ctx : Context){
|
|
|
|
- if(currentBrush.index == -1) return;
|
|
|
|
|
|
+ public function drawSurface( pos : h3d.Vector, ctx : Context ) {
|
|
|
|
+ if( currentBrush.index == -1 ) return;
|
|
var brushWorldPos = uvTexPixels == null ? pos : getBrushWorldPosFromTex(pos, ctx);
|
|
var brushWorldPos = uvTexPixels == null ? pos : getBrushWorldPosFromTex(pos, ctx);
|
|
- if(brushWorldPos == null) return;
|
|
|
|
|
|
+ if( brushWorldPos == null ) return;
|
|
var c = terrainPrefab.terrain.tiles.length;
|
|
var c = terrainPrefab.terrain.tiles.length;
|
|
var tiles = terrainPrefab.terrain.getTiles(pos.x, pos.y, currentBrush.size / 2.0, autoCreateTile);
|
|
var tiles = terrainPrefab.terrain.getTiles(pos.x, pos.y, currentBrush.size / 2.0, autoCreateTile);
|
|
- if(c != terrainPrefab.terrain.tiles.length){
|
|
|
|
|
|
+ if( c != terrainPrefab.terrain.tiles.length ) {
|
|
renderTerrainUV(ctx);
|
|
renderTerrainUV(ctx);
|
|
brushWorldPos = getBrushWorldPosFromTex(pos, ctx);
|
|
brushWorldPos = getBrushWorldPosFromTex(pos, ctx);
|
|
}
|
|
}
|
|
@@ -528,11 +544,11 @@ class TerrainEditor {
|
|
shader.strength = currentBrush.strength;
|
|
shader.strength = currentBrush.strength;
|
|
shader.size = currentBrush.size / terrainPrefab.tileSize;
|
|
shader.size = currentBrush.size / terrainPrefab.tileSize;
|
|
|
|
|
|
- for(tile in tiles){
|
|
|
|
|
|
+ for( tile in tiles ) {
|
|
var strokeBuffer = weightStrokeBufferArray.getStrokeBuffer(tile.tileX, tile.tileY);
|
|
var strokeBuffer = weightStrokeBufferArray.getStrokeBuffer(tile.tileX, tile.tileY);
|
|
- if(strokeBuffer.used == false){
|
|
|
|
|
|
+ if( strokeBuffer.used == false ) {
|
|
var revert = new TileRevertData(strokeBuffer.x, strokeBuffer.y);
|
|
var revert = new TileRevertData(strokeBuffer.x, strokeBuffer.y);
|
|
- for(w in tile.surfaceWeights)
|
|
|
|
|
|
+ for( w in tile.surfaceWeights )
|
|
revert.prevWeightMapPixels.push(w.capturePixels());
|
|
revert.prevWeightMapPixels.push(w.capturePixels());
|
|
paintRevertDatas.push(revert);
|
|
paintRevertDatas.push(revert);
|
|
strokeBuffer.prevTex = tile.surfaceWeights[currentBrush.index];
|
|
strokeBuffer.prevTex = tile.surfaceWeights[currentBrush.index];
|
|
@@ -546,12 +562,12 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public function drawHeight(pos : h3d.Vector, ctx : Context){
|
|
|
|
|
|
+ public function drawHeight( pos : h3d.Vector, ctx : Context ) {
|
|
var brushWorldPos = uvTexPixels == null ? pos : getBrushWorldPosFromTex(pos, ctx);
|
|
var brushWorldPos = uvTexPixels == null ? pos : getBrushWorldPosFromTex(pos, ctx);
|
|
- if(brushWorldPos == null) return;
|
|
|
|
|
|
+ if( brushWorldPos == null ) return;
|
|
var c = terrainPrefab.terrain.tiles.length;
|
|
var c = terrainPrefab.terrain.tiles.length;
|
|
var tiles = terrainPrefab.terrain.getTiles(brushWorldPos.x, brushWorldPos.y, currentBrush.size / 2.0, autoCreateTile);
|
|
var tiles = terrainPrefab.terrain.getTiles(brushWorldPos.x, brushWorldPos.y, currentBrush.size / 2.0, autoCreateTile);
|
|
- if(c != terrainPrefab.terrain.tiles.length){
|
|
|
|
|
|
+ if( c != terrainPrefab.terrain.tiles.length ) {
|
|
renderTerrainUV(ctx);
|
|
renderTerrainUV(ctx);
|
|
brushWorldPos = getBrushWorldPosFromTex(pos, ctx);
|
|
brushWorldPos = getBrushWorldPosFromTex(pos, ctx);
|
|
}
|
|
}
|
|
@@ -561,7 +577,7 @@ class TerrainEditor {
|
|
currentBrush.bitmap.color = new h3d.Vector(1.0);
|
|
currentBrush.bitmap.color = new h3d.Vector(1.0);
|
|
shader.size = currentBrush.size / terrainPrefab.tileSize;
|
|
shader.size = currentBrush.size / terrainPrefab.tileSize;
|
|
|
|
|
|
- switch(currentBrush.brushMode.mode){
|
|
|
|
|
|
+ switch( currentBrush.brushMode.mode ) {
|
|
case AddSub :
|
|
case AddSub :
|
|
currentBrush.bitmap.blendMode = currentBrush.brushMode.accumulate ? Add : Max;
|
|
currentBrush.bitmap.blendMode = currentBrush.brushMode.accumulate ? Add : Max;
|
|
shader.strength = currentBrush.strength;
|
|
shader.strength = currentBrush.strength;
|
|
@@ -574,11 +590,11 @@ class TerrainEditor {
|
|
default:
|
|
default:
|
|
}
|
|
}
|
|
|
|
|
|
- for(tile in tiles){
|
|
|
|
|
|
+ for( tile in tiles ) {
|
|
var localPos = tile.globalToLocal(brushWorldPos.clone());
|
|
var localPos = tile.globalToLocal(brushWorldPos.clone());
|
|
localPos.scale3(1.0 / terrainPrefab.tileSize);
|
|
localPos.scale3(1.0 / terrainPrefab.tileSize);
|
|
var strokeBuffer = heightStrokeBufferArray.getStrokeBuffer(tile.tileX, tile.tileY);
|
|
var strokeBuffer = heightStrokeBufferArray.getStrokeBuffer(tile.tileX, tile.tileY);
|
|
- if(strokeBuffer.used == false){
|
|
|
|
|
|
+ if( strokeBuffer.used == false ) {
|
|
strokeBuffer.prevTex = tile.heightMap;
|
|
strokeBuffer.prevTex = tile.heightMap;
|
|
tile.heightMap = strokeBuffer.tempTex;
|
|
tile.heightMap = strokeBuffer.tempTex;
|
|
strokeBuffer.used = true;
|
|
strokeBuffer.used = true;
|
|
@@ -589,7 +605,7 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
|
|
|
|
public function setSelected( ctx : Context, b : Bool ) {
|
|
public function setSelected( ctx : Context, b : Bool ) {
|
|
- if(b){
|
|
|
|
|
|
+ if( b ) {
|
|
var s2d = @:privateAccess ctx.local2d.getScene();
|
|
var s2d = @:privateAccess ctx.local2d.getScene();
|
|
interactive = new h2d.Interactive(10000, 10000, s2d);
|
|
interactive = new h2d.Interactive(10000, 10000, s2d);
|
|
interactive.propagateEvents = true;
|
|
interactive.propagateEvents = true;
|
|
@@ -606,11 +622,11 @@ class TerrainEditor {
|
|
currentBrush.brushMode.subAction = K.isDown(K.SHIFT);
|
|
currentBrush.brushMode.subAction = K.isDown(K.SHIFT);
|
|
currentBrush.brushMode.snapToGrid = K.isDown(K.CTRL);
|
|
currentBrush.brushMode.snapToGrid = K.isDown(K.CTRL);
|
|
var worldPos = getBrushPlanePos(s2d.mouseX, s2d.mouseY, ctx);
|
|
var worldPos = getBrushPlanePos(s2d.mouseX, s2d.mouseY, ctx);
|
|
- if(K.isDown( K.MOUSE_LEFT)){
|
|
|
|
|
|
+ if( K.isDown( K.MOUSE_LEFT) ) {
|
|
currentBrush.firstClick = true;
|
|
currentBrush.firstClick = true;
|
|
e.propagate = false;
|
|
e.propagate = false;
|
|
lastPos = worldPos.clone();
|
|
lastPos = worldPos.clone();
|
|
- if(currentBrush.isValid()){
|
|
|
|
|
|
+ if( currentBrush.isValid() ) {
|
|
useBrush( lastPos, worldPos, ctx);
|
|
useBrush( lastPos, worldPos, ctx);
|
|
previewStrokeBuffers();
|
|
previewStrokeBuffers();
|
|
drawBrushPreview(worldPos, ctx);
|
|
drawBrushPreview(worldPos, ctx);
|
|
@@ -634,22 +650,22 @@ class TerrainEditor {
|
|
currentBrush.brushMode.snapToGrid = K.isDown(K.CTRL);
|
|
currentBrush.brushMode.snapToGrid = K.isDown(K.CTRL);
|
|
var worldPos = getBrushPlanePos(s2d.mouseX, s2d.mouseY, ctx);
|
|
var worldPos = getBrushPlanePos(s2d.mouseX, s2d.mouseY, ctx);
|
|
|
|
|
|
- if( K.isDown( K.MOUSE_LEFT) ){
|
|
|
|
|
|
+ if( K.isDown( K.MOUSE_LEFT) ) {
|
|
currentBrush.firstClick = false;
|
|
currentBrush.firstClick = false;
|
|
e.propagate = false;
|
|
e.propagate = false;
|
|
if( lastPos == null ) return;
|
|
if( lastPos == null ) return;
|
|
- if( currentBrush.isValid() ){
|
|
|
|
|
|
+ if( currentBrush.isValid() ) {
|
|
if( currentBrush.brushMode.lockDir ){
|
|
if( currentBrush.brushMode.lockDir ){
|
|
var dir = worldPos.sub(lastPos);
|
|
var dir = worldPos.sub(lastPos);
|
|
trace(dir);
|
|
trace(dir);
|
|
if( currentBrush.brushMode.lockAxe == NoLock && dir.length() > 0.4 )
|
|
if( currentBrush.brushMode.lockAxe == NoLock && dir.length() > 0.4 )
|
|
currentBrush.brushMode.lockAxe = hxd.Math.abs(dir.x) > hxd.Math.abs(dir.y) ? LockX : LockY;
|
|
currentBrush.brushMode.lockAxe = hxd.Math.abs(dir.x) > hxd.Math.abs(dir.y) ? LockX : LockY;
|
|
- if( currentBrush.brushMode.lockAxe == LockX ){
|
|
|
|
|
|
+ if( currentBrush.brushMode.lockAxe == LockX ) {
|
|
var distX = worldPos.sub(lastPos).x;
|
|
var distX = worldPos.sub(lastPos).x;
|
|
worldPos.load(lastPos);
|
|
worldPos.load(lastPos);
|
|
worldPos.x += distX;
|
|
worldPos.x += distX;
|
|
}
|
|
}
|
|
- else if( currentBrush.brushMode.lockAxe == LockY ){
|
|
|
|
|
|
+ else if( currentBrush.brushMode.lockAxe == LockY ) {
|
|
var distY = worldPos.sub(lastPos).y;
|
|
var distY = worldPos.sub(lastPos).y;
|
|
worldPos.load(lastPos);
|
|
worldPos.load(lastPos);
|
|
worldPos.y += distY;
|
|
worldPos.y += distY;
|
|
@@ -665,25 +681,24 @@ class TerrainEditor {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
- if(interactive != null) interactive.remove();
|
|
|
|
|
|
+ if( interactive != null ) interactive.remove();
|
|
brushPreview.reset();
|
|
brushPreview.reset();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function removeSurface(index :Int, onChange : Void -> Void){
|
|
|
|
-
|
|
|
|
|
|
+ function removeSurface( index :Int, onChange : Void -> Void ) {
|
|
var terrainRevertData = new TerrainRevertData();
|
|
var terrainRevertData = new TerrainRevertData();
|
|
var tileRevertDatas = new Array<TileRevertData>();
|
|
var tileRevertDatas = new Array<TileRevertData>();
|
|
- for(tile in terrainPrefab.terrain.tiles)
|
|
|
|
|
|
+ for( tile in terrainPrefab.terrain.tiles )
|
|
tileRevertDatas.push(new TileRevertData(tile.tileX, tile.tileY));
|
|
tileRevertDatas.push(new TileRevertData(tile.tileX, tile.tileY));
|
|
|
|
|
|
var oldIndexes : Array<h3d.Vector> = [];
|
|
var oldIndexes : Array<h3d.Vector> = [];
|
|
var newIndexes : Array<h3d.Vector> = [];
|
|
var newIndexes : Array<h3d.Vector> = [];
|
|
- for(i in 0 ... terrainPrefab.terrain.surfaces.length)
|
|
|
|
|
|
+ for( i in 0 ... terrainPrefab.terrain.surfaces.length )
|
|
oldIndexes.push(new h3d.Vector(i));
|
|
oldIndexes.push(new h3d.Vector(i));
|
|
var offset = 0;
|
|
var offset = 0;
|
|
- for(i in 0 ... terrainPrefab.terrain.surfaces.length){
|
|
|
|
- if(i == index) {
|
|
|
|
|
|
+ for( i in 0 ... terrainPrefab.terrain.surfaces.length ) {
|
|
|
|
+ if( i == index ) {
|
|
offset = -1;
|
|
offset = -1;
|
|
newIndexes.push(new h3d.Vector(0));
|
|
newIndexes.push(new h3d.Vector(0));
|
|
}
|
|
}
|
|
@@ -696,11 +711,11 @@ class TerrainEditor {
|
|
swapIndex.shader.oldIndexes = oldIndexes;
|
|
swapIndex.shader.oldIndexes = oldIndexes;
|
|
swapIndex.shader.newIndexes = newIndexes;
|
|
swapIndex.shader.newIndexes = newIndexes;
|
|
var newSurfaceIndexMap = new h3d.mat.Texture(terrainPrefab.weightMapResolution, terrainPrefab.weightMapResolution, [Target], RGBA);
|
|
var newSurfaceIndexMap = new h3d.mat.Texture(terrainPrefab.weightMapResolution, terrainPrefab.weightMapResolution, [Target], RGBA);
|
|
- for(i in 0 ... terrainPrefab.terrain.tiles.length){
|
|
|
|
|
|
+ for( i in 0 ... terrainPrefab.terrain.tiles.length ) {
|
|
var tile = terrainPrefab.terrain.tiles[i];
|
|
var tile = terrainPrefab.terrain.tiles[i];
|
|
var revert = tileRevertDatas[i];
|
|
var revert = tileRevertDatas[i];
|
|
revert.prevSurfaceIndexMapPixels = tile.surfaceIndexMap.capturePixels();
|
|
revert.prevSurfaceIndexMapPixels = tile.surfaceIndexMap.capturePixels();
|
|
- for(w in tile.surfaceWeights) revert.prevWeightMapPixels.push(w.capturePixels());
|
|
|
|
|
|
+ for( w in tile.surfaceWeights ) revert.prevWeightMapPixels.push(w.capturePixels());
|
|
swapIndex.shader.surfaceIndexMap = tile.surfaceIndexMap;
|
|
swapIndex.shader.surfaceIndexMap = tile.surfaceIndexMap;
|
|
h3d.Engine.getCurrent().pushTarget(newSurfaceIndexMap);
|
|
h3d.Engine.getCurrent().pushTarget(newSurfaceIndexMap);
|
|
swapIndex.render();
|
|
swapIndex.render();
|
|
@@ -713,12 +728,12 @@ class TerrainEditor {
|
|
terrainPrefab.terrain.surfaces.remove(terrainPrefab.terrain.surfaces[index]);
|
|
terrainPrefab.terrain.surfaces.remove(terrainPrefab.terrain.surfaces[index]);
|
|
terrainPrefab.terrain.generateSurfaceArray();
|
|
terrainPrefab.terrain.generateSurfaceArray();
|
|
|
|
|
|
- for(i in 0 ... terrainPrefab.terrain.tiles.length){
|
|
|
|
|
|
+ for( i in 0 ... terrainPrefab.terrain.tiles.length ) {
|
|
var tile = terrainPrefab.terrain.tiles[i];
|
|
var tile = terrainPrefab.terrain.tiles[i];
|
|
normalizeWeight.shader.weightTextures = tile.surfaceWeightArray;
|
|
normalizeWeight.shader.weightTextures = tile.surfaceWeightArray;
|
|
normalizeWeight.shader.weightCount = tile.surfaceWeights.length;
|
|
normalizeWeight.shader.weightCount = tile.surfaceWeights.length;
|
|
normalizeWeight.shader.baseTexIndex = 0;
|
|
normalizeWeight.shader.baseTexIndex = 0;
|
|
- for(i in 0 ... tile.surfaceWeights.length){
|
|
|
|
|
|
+ for( i in 0 ... tile.surfaceWeights.length ) {
|
|
normalizeWeight.shader.curTexIndex = i;
|
|
normalizeWeight.shader.curTexIndex = i;
|
|
h3d.Engine.getCurrent().pushTarget(tile.surfaceWeights[i]);
|
|
h3d.Engine.getCurrent().pushTarget(tile.surfaceWeights[i]);
|
|
normalizeWeight.render();
|
|
normalizeWeight.render();
|
|
@@ -732,35 +747,35 @@ class TerrainEditor {
|
|
|
|
|
|
var revert = tileRevertDatas[i];
|
|
var revert = tileRevertDatas[i];
|
|
revert.nextSurfaceIndexMapPixels = tile.surfaceIndexMap.capturePixels();
|
|
revert.nextSurfaceIndexMapPixels = tile.surfaceIndexMap.capturePixels();
|
|
- for(w in tile.surfaceWeights) revert.nextWeightMapPixels.push(w.capturePixels());
|
|
|
|
|
|
+ for( w in tile.surfaceWeights ) revert.nextWeightMapPixels.push(w.capturePixels());
|
|
}
|
|
}
|
|
|
|
|
|
onChange();
|
|
onChange();
|
|
|
|
|
|
undo.change(Custom(function(undo) {
|
|
undo.change(Custom(function(undo) {
|
|
- if(undo)
|
|
|
|
|
|
+ if( undo )
|
|
terrainPrefab.terrain.surfaces.insert(terrainRevertData.surfaceIndex, terrainRevertData.surface);
|
|
terrainPrefab.terrain.surfaces.insert(terrainRevertData.surfaceIndex, terrainRevertData.surface);
|
|
else
|
|
else
|
|
terrainPrefab.terrain.surfaces.remove(terrainRevertData.surface);
|
|
terrainPrefab.terrain.surfaces.remove(terrainRevertData.surface);
|
|
terrainPrefab.terrain.generateSurfaceArray();
|
|
terrainPrefab.terrain.generateSurfaceArray();
|
|
|
|
|
|
- for(revertData in tileRevertDatas){
|
|
|
|
|
|
+ for( revertData in tileRevertDatas ) {
|
|
var tile = terrainPrefab.terrain.getTile(revertData.x, revertData.y);
|
|
var tile = terrainPrefab.terrain.getTile(revertData.x, revertData.y);
|
|
- if(tile == null) continue;
|
|
|
|
|
|
+ if( tile == null ) continue;
|
|
var oldArray = tile.surfaceWeights;
|
|
var oldArray = tile.surfaceWeights;
|
|
tile.surfaceWeights = new Array<h3d.mat.Texture>();
|
|
tile.surfaceWeights = new Array<h3d.mat.Texture>();
|
|
- tile.surfaceWeights = [for (i in 0...terrainPrefab.terrain.surfaces.length) null];
|
|
|
|
- for(i in 0 ... tile.surfaceWeights.length){
|
|
|
|
|
|
+ tile.surfaceWeights = [for( i in 0...terrainPrefab.terrain.surfaces.length ) null];
|
|
|
|
+ for( i in 0 ... tile.surfaceWeights.length ) {
|
|
tile.surfaceWeights[i] = new h3d.mat.Texture(terrainPrefab.weightMapResolution, terrainPrefab.weightMapResolution, [Target], R8);
|
|
tile.surfaceWeights[i] = new h3d.mat.Texture(terrainPrefab.weightMapResolution, terrainPrefab.weightMapResolution, [Target], R8);
|
|
tile.surfaceWeights[i].wrap = Clamp;
|
|
tile.surfaceWeights[i].wrap = Clamp;
|
|
tile.surfaceWeights[i].preventAutoDispose();
|
|
tile.surfaceWeights[i].preventAutoDispose();
|
|
}
|
|
}
|
|
- for(i in 0 ... oldArray.length)
|
|
|
|
|
|
+ for( i in 0 ... oldArray.length )
|
|
if( oldArray[i] != null) oldArray[i].dispose();
|
|
if( oldArray[i] != null) oldArray[i].dispose();
|
|
|
|
|
|
tile.surfaceIndexMap.uploadPixels(undo ? revertData.prevSurfaceIndexMapPixels : revertData.nextSurfaceIndexMapPixels);
|
|
tile.surfaceIndexMap.uploadPixels(undo ? revertData.prevSurfaceIndexMapPixels : revertData.nextSurfaceIndexMapPixels);
|
|
|
|
|
|
- for(i in 0 ... tile.surfaceWeights.length)
|
|
|
|
|
|
+ for( i in 0 ... tile.surfaceWeights.length )
|
|
tile.surfaceWeights[i].uploadPixels(undo ? revertData.prevWeightMapPixels[i] : revertData.nextWeightMapPixels[i]);
|
|
tile.surfaceWeights[i].uploadPixels(undo ? revertData.prevWeightMapPixels[i] : revertData.nextWeightMapPixels[i]);
|
|
|
|
|
|
tile.generateWeightArray();
|
|
tile.generateWeightArray();
|
|
@@ -774,18 +789,18 @@ class TerrainEditor {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- function loadTexture( ctx : hide.prefab.EditContext, propsName : String, ?wrap : h3d.mat.Data.Wrap){
|
|
|
|
|
|
+ function loadTexture( ctx : hide.prefab.EditContext, propsName : String, ?wrap : h3d.mat.Data.Wrap ) {
|
|
var texture = ctx.rootContext.shared.loadTexture(propsName);
|
|
var texture = ctx.rootContext.shared.loadTexture(propsName);
|
|
texture.wrap = wrap == null ? Repeat : wrap;
|
|
texture.wrap = wrap == null ? Repeat : wrap;
|
|
return texture;
|
|
return texture;
|
|
}
|
|
}
|
|
|
|
|
|
- inline function setRange(name, value, ctx : EditContext){
|
|
|
|
|
|
+ inline function setRange( name, value, ctx : EditContext ) {
|
|
var field = Lambda.find(ctx.properties.fields, f->f.fname==name);
|
|
var field = Lambda.find(ctx.properties.fields, f->f.fname==name);
|
|
if(field != null) @:privateAccess field.range.value = value;
|
|
if(field != null) @:privateAccess field.range.value = value;
|
|
}
|
|
}
|
|
|
|
|
|
- function refreshSurfaces(props : hide.Element, ctx : EditContext){
|
|
|
|
|
|
+ function refreshSurfaces( props : hide.Element, ctx : EditContext ) {
|
|
var surfacesContainer = props.find(".terrain-surfaces");
|
|
var surfacesContainer = props.find(".terrain-surfaces");
|
|
surfacesContainer.empty();
|
|
surfacesContainer.empty();
|
|
for( i in 0 ... terrainPrefab.terrain.surfaces.length ){
|
|
for( i in 0 ... terrainPrefab.terrain.surfaces.length ){
|
|
@@ -818,7 +833,7 @@ class TerrainEditor {
|
|
});
|
|
});
|
|
surfacesContainer.append(surfaceElem);
|
|
surfacesContainer.append(surfaceElem);
|
|
}
|
|
}
|
|
- if(currentSurface != null){
|
|
|
|
|
|
+ if( currentSurface != null ) {
|
|
setRange("editor.currentSurface.tilling", currentSurface.tilling, ctx);
|
|
setRange("editor.currentSurface.tilling", currentSurface.tilling, ctx);
|
|
setRange("editor.currentSurface.offset.x", currentSurface.offset.x, ctx);
|
|
setRange("editor.currentSurface.offset.x", currentSurface.offset.x, ctx);
|
|
setRange("editor.currentSurface.offset.y", currentSurface.offset.y, ctx);
|
|
setRange("editor.currentSurface.offset.y", currentSurface.offset.y, ctx);
|
|
@@ -828,7 +843,7 @@ class TerrainEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function refreshBrushMode(props : hide.Element, ctx : EditContext){
|
|
|
|
|
|
+ function refreshBrushMode (props : hide.Element, ctx : EditContext ) {
|
|
var brushIcons = ["icons/addsub.png", "icons/set.png", "icons/smooth.png", "icons/paint.png", "icons/delete.png"];
|
|
var brushIcons = ["icons/addsub.png", "icons/set.png", "icons/smooth.png", "icons/paint.png", "icons/delete.png"];
|
|
var brushMode = [Brush.Mode.AddSub, Brush.Mode.Set, Brush.Mode.Smooth, Brush.Mode.Paint, Brush.Mode.Delete];
|
|
var brushMode = [Brush.Mode.AddSub, Brush.Mode.Set, Brush.Mode.Smooth, Brush.Mode.Paint, Brush.Mode.Delete];
|
|
var brushDescription = [
|
|
var brushDescription = [
|
|
@@ -844,14 +859,14 @@ class TerrainEditor {
|
|
<i>Paint to delete tiles</i>'];
|
|
<i>Paint to delete tiles</i>'];
|
|
var brushModeContainer = props.find(".terrain-brushModeContainer");
|
|
var brushModeContainer = props.find(".terrain-brushModeContainer");
|
|
brushModeContainer.empty();
|
|
brushModeContainer.empty();
|
|
- for( i in 0 ... brushIcons.length){
|
|
|
|
|
|
+ for( i in 0 ... brushIcons.length ) {
|
|
var elem = new Element('<div class="terrain-brushMode"></div>');
|
|
var elem = new Element('<div class="terrain-brushMode"></div>');
|
|
var img = new Element('<div class="terrain-brushModeIcon"></div>');
|
|
var img = new Element('<div class="terrain-brushModeIcon"></div>');
|
|
img.css("background-image", 'url("file://${ctx.ide.getPath("${HIDE}/res/" + brushIcons[i])}")');
|
|
img.css("background-image", 'url("file://${ctx.ide.getPath("${HIDE}/res/" + brushIcons[i])}")');
|
|
elem.prepend(img);
|
|
elem.prepend(img);
|
|
elem.click(function(_) {
|
|
elem.click(function(_) {
|
|
var l = props.find(".terrain-brushModeIcon");
|
|
var l = props.find(".terrain-brushModeIcon");
|
|
- for(e in l){
|
|
|
|
|
|
+ for( e in l ) {
|
|
var elem = new Element(e);
|
|
var elem = new Element(e);
|
|
elem.toggleClass("selected", false);
|
|
elem.toggleClass("selected", false);
|
|
}
|
|
}
|
|
@@ -898,38 +913,38 @@ class TerrainEditor {
|
|
</div>
|
|
</div>
|
|
</div>';
|
|
</div>';
|
|
|
|
|
|
- public function setupUI(props : hide.Element, ctx : EditContext){
|
|
|
|
|
|
+ public function setupUI( props : hide.Element, ctx : EditContext ) {
|
|
props.append(brushMode);
|
|
props.append(brushMode);
|
|
props.append(brushParams);
|
|
props.append(brushParams);
|
|
props.append(surfaceParams);
|
|
props.append(surfaceParams);
|
|
refreshBrushMode(props, ctx);
|
|
refreshBrushMode(props, ctx);
|
|
- props.append(
|
|
|
|
|
|
+
|
|
|
|
+ // Save Button
|
|
|
|
+ /*props.append(
|
|
'<div align="center">
|
|
'<div align="center">
|
|
<input type="button" value="Save" class="save" />
|
|
<input type="button" value="Save" class="save" />
|
|
</div>');
|
|
</div>');
|
|
-
|
|
|
|
- // Save Button
|
|
|
|
props.find(".save").click(function(_) {
|
|
props.find(".save").click(function(_) {
|
|
var datPath = new haxe.io.Path(ctx.rootContext.shared.currentPath);
|
|
var datPath = new haxe.io.Path(ctx.rootContext.shared.currentPath);
|
|
datPath.ext = "dat";
|
|
datPath.ext = "dat";
|
|
var fullPath = ctx.ide.getPath(datPath.toString() + "/" + terrainPrefab.name);
|
|
var fullPath = ctx.ide.getPath(datPath.toString() + "/" + terrainPrefab.name);
|
|
- if( sys.FileSystem.isDirectory(fullPath)){
|
|
|
|
|
|
+ if( sys.FileSystem.isDirectory(fullPath) ) {
|
|
var files = sys.FileSystem.readDirectory(fullPath);
|
|
var files = sys.FileSystem.readDirectory(fullPath);
|
|
- for(file in files)
|
|
|
|
- sys.FileSystem.deleteFile(fullPath + "/" + file);
|
|
|
|
|
|
+ for( f in files )
|
|
|
|
+ sys.FileSystem.deleteFile(fullPath + "/" + f);
|
|
}
|
|
}
|
|
terrainPrefab.saveWeightTextures(ctx.rootContext);
|
|
terrainPrefab.saveWeightTextures(ctx.rootContext);
|
|
terrainPrefab.saveHeightTextures(ctx.rootContext);
|
|
terrainPrefab.saveHeightTextures(ctx.rootContext);
|
|
- });
|
|
|
|
|
|
+ });*/
|
|
|
|
|
|
var brushes : Array<Dynamic> = ctx.scene.config.get("terrain.brushes");
|
|
var brushes : Array<Dynamic> = ctx.scene.config.get("terrain.brushes");
|
|
var brushesContainer = props.find(".terrain-brushes");
|
|
var brushesContainer = props.find(".terrain-brushes");
|
|
- function refreshBrushes(){
|
|
|
|
|
|
+ function refreshBrushes() {
|
|
brushesContainer.empty();
|
|
brushesContainer.empty();
|
|
- for( brush in brushes){
|
|
|
|
|
|
+ for( brush in brushes ) {
|
|
var label = brush.name + "</br>Step : " + brush.step + "</br>Strength : " + brush.strength + "</br>Size : " + brush.size ;
|
|
var label = brush.name + "</br>Step : " + brush.step + "</br>Strength : " + brush.strength + "</br>Size : " + brush.size ;
|
|
var img : Element;
|
|
var img : Element;
|
|
- if( brush.name == currentBrush.name) img = new Element('<div class="brush-preview-selected"></div>');
|
|
|
|
|
|
+ if( brush.name == currentBrush.name ) img = new Element('<div class="brush-preview-selected"></div>');
|
|
else img = new Element('<div class="brush-preview"></div>');
|
|
else img = new Element('<div class="brush-preview"></div>');
|
|
img.css("background-image", 'url("file://${ctx.ide.getPath(brush.texture)}")');
|
|
img.css("background-image", 'url("file://${ctx.ide.getPath(brush.texture)}")');
|
|
var brushElem = new Element('<div class="brush"><span class="tooltiptext">$label</span></div>').prepend(img);
|
|
var brushElem = new Element('<div class="brush"><span class="tooltiptext">$label</span></div>').prepend(img);
|
|
@@ -940,7 +955,7 @@ class TerrainEditor {
|
|
currentBrush.texPath = ctx.ide.getPath(brush.texture);
|
|
currentBrush.texPath = ctx.ide.getPath(brush.texture);
|
|
currentBrush.tex = loadTexture(ctx, currentBrush.texPath);
|
|
currentBrush.tex = loadTexture(ctx, currentBrush.texPath);
|
|
currentBrush.name = brush.name;
|
|
currentBrush.name = brush.name;
|
|
- if(currentBrush.bitmap != null){
|
|
|
|
|
|
+ if( currentBrush.bitmap != null ) {
|
|
currentBrush.bitmap.tile.dispose();
|
|
currentBrush.bitmap.tile.dispose();
|
|
currentBrush.bitmap.tile = h2d.Tile.fromTexture(currentBrush.tex);
|
|
currentBrush.bitmap.tile = h2d.Tile.fromTexture(currentBrush.tex);
|
|
}
|
|
}
|
|
@@ -952,7 +967,7 @@ class TerrainEditor {
|
|
});
|
|
});
|
|
brushesContainer.append(brushElem);
|
|
brushesContainer.append(brushElem);
|
|
}
|
|
}
|
|
- if(currentBrush != null){
|
|
|
|
|
|
+ if( currentBrush != null ) {
|
|
setRange("editor.currentBrush.size", currentBrush.size, ctx);
|
|
setRange("editor.currentBrush.size", currentBrush.size, ctx);
|
|
setRange("editor.currentBrush.strength", currentBrush.strength, ctx);
|
|
setRange("editor.currentBrush.strength", currentBrush.strength, ctx);
|
|
setRange("editor.currentBrush.step", currentBrush.step, ctx);
|
|
setRange("editor.currentBrush.step", currentBrush.step, ctx);
|
|
@@ -962,15 +977,15 @@ class TerrainEditor {
|
|
refreshSurfaces(props, ctx);
|
|
refreshSurfaces(props, ctx);
|
|
}
|
|
}
|
|
|
|
|
|
- public function onChange(ctx : EditContext, pname, props){
|
|
|
|
- if(pname == "editor.tmpTexPath" && tmpTexPath != null){
|
|
|
|
|
|
+ public function onChange( ctx : EditContext, pname : String, props : Element ) {
|
|
|
|
+ if( pname == "editor.tmpTexPath" && tmpTexPath != null ) {
|
|
var split : Array<String> = [];
|
|
var split : Array<String> = [];
|
|
var curTypeIndex = 0;
|
|
var curTypeIndex = 0;
|
|
- while( split.length <= 1 && curTypeIndex < textureType.length){
|
|
|
|
|
|
+ while( split.length <= 1 && curTypeIndex < textureType.length) {
|
|
split = tmpTexPath.split(textureType[curTypeIndex]);
|
|
split = tmpTexPath.split(textureType[curTypeIndex]);
|
|
curTypeIndex++;
|
|
curTypeIndex++;
|
|
}
|
|
}
|
|
- if(split.length > 1) {
|
|
|
|
|
|
+ if( split.length > 1 ) {
|
|
var name = split[0];
|
|
var name = split[0];
|
|
var albedo = ctx.rootContext.shared.loadTexture(name + textureType[0] + ".png");
|
|
var albedo = ctx.rootContext.shared.loadTexture(name + textureType[0] + ".png");
|
|
var normal = ctx.rootContext.shared.loadTexture(name + textureType[1] + ".png");
|
|
var normal = ctx.rootContext.shared.loadTexture(name + textureType[1] + ".png");
|
|
@@ -979,7 +994,7 @@ class TerrainEditor {
|
|
if( albedo.flags.has(Loading) || normal.flags.has(Loading)|| pbr.flags.has(Loading))
|
|
if( albedo.flags.has(Loading) || normal.flags.has(Loading)|| pbr.flags.has(Loading))
|
|
haxe.Timer.delay(wait, 1);
|
|
haxe.Timer.delay(wait, 1);
|
|
else{
|
|
else{
|
|
- if(terrainPrefab.terrain.getSurfaceFromTex(name + textureType[0] + ".png", name + textureType[1] + ".png", name + textureType[2] + ".png") == null){
|
|
|
|
|
|
+ if( terrainPrefab.terrain.getSurfaceFromTex(name + textureType[0] + ".png", name + textureType[1] + ".png", name + textureType[2] + ".png") == null ) {
|
|
terrainPrefab.terrain.addSurface(albedo, normal, pbr);
|
|
terrainPrefab.terrain.addSurface(albedo, normal, pbr);
|
|
terrainPrefab.terrain.generateSurfaceArray();
|
|
terrainPrefab.terrain.generateSurfaceArray();
|
|
refreshSurfaces(props, ctx);
|
|
refreshSurfaces(props, ctx);
|
|
@@ -987,9 +1002,9 @@ class TerrainEditor {
|
|
terrainRevertData.surface = terrainPrefab.terrain.getSurface(terrainPrefab.terrain.surfaces.length - 1);
|
|
terrainRevertData.surface = terrainPrefab.terrain.getSurface(terrainPrefab.terrain.surfaces.length - 1);
|
|
terrainRevertData.surfaceIndex = terrainPrefab.terrain.surfaces.length - 1;
|
|
terrainRevertData.surfaceIndex = terrainPrefab.terrain.surfaces.length - 1;
|
|
undo.change(Custom(function(undo) {
|
|
undo.change(Custom(function(undo) {
|
|
- if(undo){
|
|
|
|
|
|
+ if( undo ) {
|
|
terrainPrefab.terrain.surfaces.remove(terrainRevertData.surface);
|
|
terrainPrefab.terrain.surfaces.remove(terrainRevertData.surface);
|
|
- if(currentSurface == terrainRevertData.surface) currentSurface = null;
|
|
|
|
|
|
+ if( currentSurface == terrainRevertData.surface ) currentSurface = null;
|
|
currentBrush.index = Std.int(hxd.Math.min(terrainPrefab.terrain.surfaces.length - 1, currentBrush.index));
|
|
currentBrush.index = Std.int(hxd.Math.min(terrainPrefab.terrain.surfaces.length - 1, currentBrush.index));
|
|
}
|
|
}
|
|
else
|
|
else
|