Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Updated to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
RaananW committed Jan 3, 2015
1 parent b7eddae commit 7ba2880
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 78 deletions.
1 change: 1 addition & 0 deletions MaterialEditor/canvas/CanvasService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
});
}


public initLight(lightType: LightType = LightType.HEMISPHERIC) {
this._scene.lights.forEach((light) => {
light.dispose();
Expand Down
19 changes: 19 additions & 0 deletions MaterialEditor/material/MaterialController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@
}
}

public setPlaneForMirror() {
console.log("setPlane");
var pointsArray: Array<BABYLON.Vector3> = [];
//TODO maybe find a different way of computing the plane? trying to avoid getting the object in the constructor.
var meshWorldMatrix = this._object.computeWorldMatrix();
var verticesPosition = this._object.getVerticesData(BABYLON.VertexBuffer.PositionKind);
//handle submeshes
var offset = 0;
if (this.isMultiMaterial) {
offset = this._object.subMeshes[this.multiMaterialPosition].indexStart
}
for (var i = 0; i < 3; i++) {
var v = this._object.getIndices()[offset + i];
pointsArray.push(BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.FromArray(verticesPosition, v*3), meshWorldMatrix));
}
var plane = BABYLON.Plane.FromPoints(pointsArray[0], pointsArray[1], pointsArray[2]);
this.$scope.materialDefinition.materialSections["reflection"].texture.setMirrorPlane(plane);
}

public exportMaterial() {
var modalInstance = this.$modal.open({
templateUrl: 'materialExport.html',
Expand Down
22 changes: 11 additions & 11 deletions MaterialEditor/material/MaterialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
public sectionNames: Array<string>;


constructor(object: BABYLON.AbstractMesh, material: BABYLON.Material, onSuccess?: () => void) {
constructor(material: BABYLON.Material, onSuccess?: () => void) {
this.sectionNames = ["diffuse", "emissive", "ambient", "opacity", "specular", "reflection", "bump"]
this.initFromObject(object, material, onSuccess);
this.initFromMaterial(material, onSuccess);
}

public initFromObject(object: BABYLON.AbstractMesh, material: BABYLON.Material, onSuccess?: () => void) {
public initFromMaterial(material: BABYLON.Material, onSuccess?: () => void) {
this.material = material;
this.materialSections = {};
this.materialSections["diffuse"] = new MaterialDefinitionSection("diffuse", object, true, true, true, material, onSuccess);
this.materialSections["emissive"] = new MaterialDefinitionSection("emissive", object, true, true, true, material, onSuccess);
this.materialSections["ambient"] = new MaterialDefinitionSection("ambient", object, true, true, false, material, onSuccess);
this.materialSections["opacity"] = new MaterialDefinitionSection("opacity", object, false, true, true, material, onSuccess);
this.materialSections["specular"] = new MaterialDefinitionSection("specular", object, true, true, false, material, onSuccess);
this.materialSections["reflection"] = new MaterialDefinitionSection("reflection", object, false, true, true, material, onSuccess);
this.materialSections["bump"] = new MaterialDefinitionSection("bump", object, false, true, false, material, onSuccess);
this.materialSections["diffuse"] = new MaterialDefinitionSection("diffuse", true, true, true, material, onSuccess);
this.materialSections["emissive"] = new MaterialDefinitionSection("emissive", true, true, true, material, onSuccess);
this.materialSections["ambient"] = new MaterialDefinitionSection("ambient", true, true, false, material, onSuccess);
this.materialSections["opacity"] = new MaterialDefinitionSection("opacity", false, true, true, material, onSuccess);
this.materialSections["specular"] = new MaterialDefinitionSection("specular", true, true, false, material, onSuccess);
this.materialSections["reflection"] = new MaterialDefinitionSection("reflection", false, true, true, material, onSuccess);
this.materialSections["bump"] = new MaterialDefinitionSection("bump", false, true, false, material, onSuccess);
}

public getMaterialSectionsArray(): string[] {
Expand Down Expand Up @@ -109,7 +109,7 @@
material = object.material;
}

return new MaterialDefinition(object, material, onSuccess);
return new MaterialDefinition(material, onSuccess);
}

public exportAsBabylonScene(materialId: string, materialDefinition: MaterialDefinition) {
Expand Down
4 changes: 2 additions & 2 deletions MaterialEditor/material/model/MaterialDefinitionSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
public color: HexToBabylon;
public fresnel: FresnelDefinition;
public texture: TextureDefinition;
constructor(public name: string, private _object: BABYLON.AbstractMesh, public hasColor, public hasTexture, public hasFresnel, public material: BABYLON.Material, onSuccess?: () => void) {
constructor(public name: string, public hasColor, public hasTexture, public hasFresnel, public material: BABYLON.Material, onSuccess?: () => void) {
/*var material: BABYLON.Material;
if (angular.isDefined(multiMaterialPosition)) {
material = (<BABYLON.MultiMaterial> _object.material).subMaterials[multiMaterialPosition];
Expand All @@ -15,7 +15,7 @@
this.color = new HexToBabylon(name, material);
}
if (hasTexture) {
this.texture = new TextureDefinition(name, material, _object, onSuccess);
this.texture = new TextureDefinition(name, material, onSuccess);
}
if (hasFresnel) {
this.fresnel = new FresnelDefinition(name, material);
Expand Down
31 changes: 13 additions & 18 deletions MaterialEditor/texture/ImageDragAndDropDirective.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module RW.TextureEditor {

export var textureImage = ["$parse", function ($parse:ng.IParseService) {
export var textureImage = ["$parse", function ($parse: ng.IParseService) {
return {
restrict: 'E',
templateUrl: function (elem, attr) {
Expand All @@ -12,7 +12,7 @@
tex: '=',
updateTexture: '&onUpdateTexture'
},
transclude:true,
transclude: true,
link: function (scope, element, attr) {
var texture = <TextureDefinition> scope.tex;

Expand All @@ -32,7 +32,7 @@
image.height *= width / image.width;
image.width = width;
}

canvas.width = max;
canvas.height = max;
ctx.drawImage(image, 0, 0, max, max);
Expand Down Expand Up @@ -61,22 +61,17 @@
};
reader.readAsDataURL(src);
}
//preparing for 6 images.
//for (var i = 0; i < 6; i++) {

//var pos = i;
element.on("dragover", ".texture-canvas-drop", function (e) {
e.preventDefault();
});
element.on("dragleave", ".texture-canvas-drop", function (e) {
e.preventDefault();
});
element.on("drop", ".texture-canvas-drop", function (e) {
e.preventDefault();
loadImage(e.originalEvent.dataTransfer.files[0], <HTMLCanvasElement> $(this).find("canvas")[0]);
});
//}

element.on("dragover", ".texture-canvas-drop", function (e) {
e.preventDefault();
});
element.on("dragleave", ".texture-canvas-drop", function (e) {
e.preventDefault();
});
element.on("drop", ".texture-canvas-drop", function (e) {
e.preventDefault();
loadImage(e.originalEvent.dataTransfer.files[0], <HTMLCanvasElement> $(this).find("canvas")[0]);
});
}
}
}]
Expand Down
22 changes: 12 additions & 10 deletions MaterialEditor/texture/TextureDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ module RW.TextureEditor {

private _isMirror: boolean;

private _mirrorPlane: BABYLON.Plane;

public textureVariable: BABYLON.BaseTexture;

constructor(public name: string, private _material: BABYLON.Material, private _connectedMesh: BABYLON.AbstractMesh, onSuccess?: () => void) {
constructor(public name: string, private _material: BABYLON.Material, onSuccess?: () => void) {
this.propertyInMaterial = this.name.toLowerCase() + "Texture";
this.canvasId = this.name + "Canvas";
this.numberOfImages = 1;
this._mirrorPlane = new BABYLON.Plane(0, 0, 0, 0);
if (this._material[this.propertyInMaterial]) {
if (this._material[this.propertyInMaterial] instanceof BABYLON.MirrorTexture) {
this.babylonTextureType = BabylonTextureType.MIRROR;
Expand Down Expand Up @@ -101,6 +104,13 @@ module RW.TextureEditor {
}
}

public setMirrorPlane(plane: BABYLON.Plane) {
//if (this.babylonTextureType == BabylonTextureType.MIRROR) {
this._mirrorPlane.normal = plane.normal;
this._mirrorPlane.d = plane.d;
//}
}

public mirrorEnabled(enabled: boolean) {
if (angular.isDefined(enabled)) {
if (enabled) {
Expand All @@ -111,15 +121,7 @@ module RW.TextureEditor {
//create the mirror
this.textureVariable = new BABYLON.MirrorTexture("mirrorTex", 512, this._material.getScene());
this.textureVariable['renderList'] = this._material.getScene().meshes;
//calculate plane
var pointsArray: Array<BABYLON.Vector3> = [];
//TODO maybe find a different way of computing the plane? trying to avoid getting the object in the constructor.
var meshWorldMatrix = this._connectedMesh.computeWorldMatrix();
var verticesPos = this._connectedMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
for (var i = 0; i < 3; i++) {
pointsArray.push(BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.FromArray(verticesPos, i * 3), meshWorldMatrix));
}
this.textureVariable['mirrorPlane'] = BABYLON.Plane.FromPoints(pointsArray[0], pointsArray[1], pointsArray[2]);
this.textureVariable['mirrorPlane'] = this._mirrorPlane;
this.init = true;
//if (!this._isEnabled) {
this.enabled(true);
Expand Down
75 changes: 44 additions & 31 deletions application.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion application.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion application.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions application.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 7ba2880

Please sign in to comment.