| 9 | |
| 10 | class PlyReaderToMesh { |
| 11 | fun load(fn: String, target: MeshBuilder) { |
| 12 | val m = PlyReader.readMesh(File(fn)) |
| 13 | target.open() |
| 14 | |
| 15 | val startAt = target.vertexCursor |
| 16 | |
| 17 | m.first.forEach { |
| 18 | |
| 19 | var color: Vec4? = null |
| 20 | var normal: Vec3? = null |
| 21 | |
| 22 | // println(" attributes at this vertex are? :"+it.attributes.keys) |
| 23 | |
| 24 | it.attributes.forEach { |
| 25 | |
| 26 | if (it.key.contains("red")) { |
| 27 | if (color == null) color = Vec4(0.0, 0.0, 0.0, 255.0) |
| 28 | color!!.x = it.value.get(0).toDouble() |
| 29 | } |
| 30 | if (it.key.contains("green")) { |
| 31 | if (color == null) color = Vec4(0.0, 0.0, 0.0, 255.0) |
| 32 | color!!.y = it.value.get(0).toDouble() |
| 33 | } |
| 34 | if (it.key.contains("blue")) { |
| 35 | if (color == null) color = Vec4(0.0, 0.0, 0.0, 255.0) |
| 36 | color!!.z = it.value.get(0).toDouble() |
| 37 | } |
| 38 | if (it.key.contains("alpha")) { |
| 39 | if (color == null) color = Vec4(0.0, 0.0, 0.0, 255.0) |
| 40 | color!!.w = it.value.get(0).toDouble() |
| 41 | } |
| 42 | |
| 43 | if (it.key.contains("nx")) { |
| 44 | if (normal == null) normal = Vec3(0.0, 0.0, 0.0) |
| 45 | normal!!.x = it.value.get(0).toDouble() |
| 46 | } |
| 47 | if (it.key.contains("ny")) { |
| 48 | if (normal == null) normal = Vec3(0.0, 0.0, 0.0) |
| 49 | normal!!.y = it.value.get(0).toDouble() |
| 50 | } |
| 51 | if (it.key.contains("nz")) { |
| 52 | if (normal == null) normal = Vec3(0.0, 0.0, 0.0) |
| 53 | normal!!.z = it.value.get(0).toDouble() |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if (color != null) { |
| 58 | target.aux(1, color!! * 1/255.0) |
| 59 | } |
| 60 | if (normal != null) { |
| 61 | target.aux(4, normal) |
| 62 | } |
| 63 | |
| 64 | target.v(it.at) |
| 65 | |
| 66 | } |
| 67 | |
| 68 | val nowAt = target.vertexCursor |