-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#10 got it to display textured tree from set of arrays
- Loading branch information
Showing
22 changed files
with
44,884 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as THREE from 'three'; | ||
export class RuleApplyer { | ||
constructor(inputArray) { | ||
this.theArray = inputArray; | ||
this.theMesh = new THREE.Group(); | ||
this.textureLoader = new THREE.TextureLoader(); | ||
this.textureLoader.crossOrigin = ""; | ||
this.texturesArray = new Array(); | ||
this.geometryArray = new Array(); | ||
this.materialsArray = new Array(); | ||
this.colorArray = new Array(); | ||
var texture = this.textureLoader.load("./resources/textures/oak.png"); | ||
this.materialsArray.push(new THREE.MeshPhongMaterial({ map: texture })); | ||
texture = this.textureLoader.load("./resources/textures/leaves.jpg"); | ||
this.materialsArray.push(new THREE.MeshPhongMaterial({ map: texture })); | ||
this.geometryArray.push(new THREE.CylinderGeometry(0.5, 0.5, 1, 16)); | ||
this.geometryArray.push(new THREE.BoxGeometry(1, 1, 1)); | ||
this.colorArray.push(0x664611); | ||
this.colorArray.push(0x00ff00); | ||
/** | ||
* These Length variables are used to re-centre the group object as each object | ||
* will be placed at the index values of the arrays so we need to push them back | ||
* in order to have the centre object be at (or relatively be at) postion 0,0,0 | ||
*/ | ||
var xLength = Math.floor(inputArray.length / 2); | ||
var yLength = Math.floor(inputArray[0].length / 2); | ||
var zLength = Math.floor(inputArray[0][0].length / 2); | ||
for (var x = 0; x < this.theArray.length; x++) { | ||
for (var y = 0; y < this.theArray[x].length; y++) { | ||
for (var z = 0; z < this.theArray[x][y].length; z++) { | ||
if (this.theArray[x][y][z] == null) { | ||
//do nothing | ||
} | ||
else { | ||
for (var i = 0; i < this.colorArray.length; i++) { | ||
if (this.theArray[x][y][z] == this.colorArray[i]) { | ||
let newObject = new THREE.Mesh(this.geometryArray[i], this.materialsArray[i]); | ||
newObject.position.set(-x + xLength, y - yLength, z - zLength); | ||
this.theMesh.add(newObject); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
output() { | ||
return this.theMesh; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as THREE from 'three'; | ||
|
||
export class RuleApplyer | ||
{ | ||
private theArray : number[][][]; | ||
private theMesh : THREE.Group; | ||
private textureLoader : THREE.TextureLoader; | ||
private texturesArray : THREE.Texture[]; | ||
private geometryArray : THREE.Geometry[]; | ||
private materialsArray : THREE.MeshPhongMaterial[]; | ||
private colorArray : number[]; | ||
|
||
constructor(inputArray : number[][][]) | ||
{ | ||
this.theArray = inputArray; | ||
this.theMesh = new THREE.Group(); | ||
|
||
|
||
this.textureLoader = new THREE.TextureLoader(); | ||
this.textureLoader.crossOrigin = ""; | ||
this.texturesArray = new Array<THREE.Texture>(); | ||
this.geometryArray = new Array<THREE.Geometry>(); | ||
this.materialsArray = new Array<THREE.MeshPhongMaterial>(); | ||
this.colorArray = new Array<number>(); | ||
|
||
var texture = this.textureLoader.load("./resources/textures/oak.png"); | ||
this.materialsArray.push(new THREE.MeshPhongMaterial({map : texture})); | ||
texture = this.textureLoader.load("./resources/textures/leaves.jpg"); | ||
this.materialsArray.push(new THREE.MeshPhongMaterial({map : texture})); | ||
|
||
this.geometryArray.push(new THREE.CylinderGeometry(0.5, 0.5, 1, 16)); | ||
this.geometryArray.push(new THREE.BoxGeometry(1, 1, 1)); | ||
|
||
this.colorArray.push(0x664611); | ||
this.colorArray.push(0x00ff00); | ||
|
||
/** | ||
* These Length variables are used to re-centre the group object as each object | ||
* will be placed at the index values of the arrays so we need to push them back | ||
* in order to have the centre object be at (or relatively be at) postion 0,0,0 | ||
*/ | ||
var xLength = Math.floor(inputArray.length/2); | ||
var yLength = Math.floor(inputArray[0].length/2); | ||
var zLength = Math.floor(inputArray[0][0].length/2); | ||
|
||
for(var x=0;x<this.theArray.length;x++) | ||
{ | ||
for(var y=0;y<this.theArray[x].length;y++) | ||
{ | ||
for(var z=0;z<this.theArray[x][y].length;z++) | ||
{ | ||
if(this.theArray[x][y][z] == null) | ||
{ | ||
//do nothing | ||
} | ||
else | ||
{ | ||
for(var i=0;i<this.colorArray.length;i++) | ||
{ | ||
if(this.theArray[x][y][z] == this.colorArray[i]) | ||
{ | ||
|
||
let newObject = new THREE.Mesh(this.geometryArray[i], this.materialsArray[i] ); | ||
newObject.position.set(-x+xLength,y-yLength,z-zLength); | ||
|
||
this.theMesh.add(newObject); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
output() : THREE.Group | ||
{ | ||
return this.theMesh; | ||
} | ||
} |
Oops, something went wrong.