Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylancyclone committed Jun 30, 2020
2 parents 770c29f + 5b973a5 commit c354e4e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Watch a demonstration video:

From the root directory, run:

`mvn package;java -jar ./target/VMF2OBJ-1.1.0-jar-with-dependencies.jar [VMF_FILE] [OUTPUT_FILE] [VPK_PATHS]`
`mvn package;java -jar ./target/VMF2OBJ-1.1.1-jar-with-dependencies.jar [VMF_FILE] [OUTPUT_FILE] [VPK_PATHS]`

```
usage: vmf2obj [VMF_FILE] [OUTPUT_FILE] [VPK_PATHS] [args...]
Expand Down
10 changes: 10 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
6/29/2020 1.1.1:
* Fix displacements
* Fix some models' QC being unfindable

6/28/2020 1.1.0:
+ Add support for multiple external paths
+ Add support for CS:GO's unformscale prop keyvalue

6/27/2020 1.0.0:
+ Initial Release
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.lathrum.VMF2OBJ</groupId>
<artifactId>VMF2OBJ</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>jar</packaging>

<name>VMF2OBJ</name>
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/com/lathrum/VMF2OBJ/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static int getEntryIndexByPath(ArrayList<Entry> object, String path) {
public static ArrayList<Integer> getEntryIndiciesByPattern(ArrayList<Entry> object, String pattern) {
ArrayList<Integer> indicies = new ArrayList<Integer>();
for (int i = 0; i < object.size(); i++) {
if (object != null && object.get(i).getFullPath().contains(pattern)) {
if (object != null && object.get(i).getFullPath().toLowerCase().contains(pattern.toLowerCase())) {
indicies.add(i);
}
// else{System.out.println(object.get(i).getFullPath());}
Expand Down Expand Up @@ -455,15 +455,17 @@ public static void main(String args[]) throws Exception {
// -or-
// A D
// B C
Vector3 ad = side.points[3].subtract(side.points[0]);
Vector3 ab = side.points[1].subtract(side.points[0]);
int startIndex = side.dispinfo.startposition.closestIndex(side.points);
//Get adjacent points by going around counter-clockwise
Vector3 ad = side.points[(startIndex+1)%4].subtract(side.points[startIndex]);
Vector3 ab = side.points[(startIndex+3)%4].subtract(side.points[startIndex]);
// System.out.println(ad);
// System.out.println(ab);
for (int i = 0; i < side.dispinfo.normals.length; i++) // rows
{
for (int j = 0; j < side.dispinfo.normals[0].length; j++) // columns
{
Vector3 point = side.points[0]
Vector3 point = side.points[startIndex]
.add(ad.normalize().multiply(ad.divide(side.dispinfo.normals[0].length - 1).abs().multiply(j)))
.add(ab.normalize().multiply(ab.divide(side.dispinfo.normals.length - 1).abs().multiply(i)))
.add(side.dispinfo.normals[i][j].multiply(side.dispinfo.distances[i][j]));
Expand Down Expand Up @@ -728,14 +730,16 @@ public static void main(String args[]) throws Exception {
// -or-
// A D
// B C
Vector3 ad = side.points[3].subtract(side.points[0]);
Vector3 ab = side.points[1].subtract(side.points[0]);
int startIndex = side.dispinfo.startposition.closestIndex(side.points);
//Get adjacent points by going around counter-clockwise
Vector3 ad = side.points[(startIndex+1)%4].subtract(side.points[startIndex]);
Vector3 ab = side.points[(startIndex+3)%4].subtract(side.points[startIndex]);
for (int i = 0; i < side.dispinfo.normals.length - 1; i++) // all rows but last
{
for (int j = 0; j < side.dispinfo.normals[0].length - 1; j++) // all columns but last
{
buffer = "";
Vector3 point = side.points[0]
Vector3 point = side.points[startIndex]
.add(ad.normalize().multiply(ad.divide(side.dispinfo.normals[0].length - 1).abs().multiply(j)))
.add(ab.normalize().multiply(ab.divide(side.dispinfo.normals.length - 1).abs().multiply(i)))
.add(side.dispinfo.normals[i][j].multiply(side.dispinfo.distances[i][j]));
Expand All @@ -749,7 +753,7 @@ public static void main(String args[]) throws Exception {
buffer += (uniqueVerticiesList.indexOf(point) + vertexOffset) + "/"
+ ((((side.dispinfo.normals.length - 1) * i) + j) * 4 + vertexTextureOffset) + " ";

point = side.points[0]
point = side.points[startIndex]
.add(ad.normalize().multiply(ad.divide(side.dispinfo.normals[0].length - 1).abs().multiply(j)))
.add(ab.normalize().multiply(ab.divide(side.dispinfo.normals.length - 1).abs().multiply(i + 1)))
.add(side.dispinfo.normals[i + 1][j].multiply(side.dispinfo.distances[i + 1][j]));
Expand All @@ -763,7 +767,7 @@ public static void main(String args[]) throws Exception {
buffer += (uniqueVerticiesList.indexOf(point) + vertexOffset) + "/"
+ ((((side.dispinfo.normals.length - 1) * i) + j) * 4 + vertexTextureOffset + 1) + " ";

point = side.points[0]
point = side.points[startIndex]
.add(ad.normalize().multiply(ad.divide(side.dispinfo.normals[0].length - 1).abs().multiply(j + 1)))
.add(ab.normalize().multiply(ab.divide(side.dispinfo.normals.length - 1).abs().multiply(i + 1)))
.add(side.dispinfo.normals[i + 1][j + 1].multiply(side.dispinfo.distances[i + 1][j + 1]));
Expand All @@ -777,7 +781,7 @@ public static void main(String args[]) throws Exception {
buffer += (uniqueVerticiesList.indexOf(point) + vertexOffset) + "/"
+ ((((side.dispinfo.normals.length - 1) * i) + j) * 4 + vertexTextureOffset + 2) + " ";

point = side.points[0]
point = side.points[startIndex]
.add(ad.normalize().multiply(ad.divide(side.dispinfo.normals[0].length - 1).abs().multiply(j + 1)))
.add(ab.normalize().multiply(ab.divide(side.dispinfo.normals.length - 1).abs().multiply(i)))
.add(side.dispinfo.normals[i][j + 1].multiply(side.dispinfo.distances[i][j + 1]));
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/lathrum/VMF2OBJ/dataStructure/Vector3.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,34 @@ public Vector3 normalize() {
return this.divide(new Vector3(length,length,length));
}

public static double distance(Vector3 vectorA, Vector3 vectorB) {
return Math.sqrt(
Math.pow(vectorA.x - vectorB.x, 2) + Math.pow(vectorA.y - vectorB.y, 2) + Math.pow(vectorA.z - vectorB.z, 2));
}

public double distance(Vector3 vector) {
return Math.sqrt(Math.pow(this.x - vector.x, 2) + Math.pow(this.y - vector.y, 2) + Math.pow(this.z - vector.z, 2));
}

public int closestIndex(Vector3[] vectors) {
if (vectors.length == 0) {
return -1;
} else if (vectors.length == 1) {
return 0;
} else {
int index = 0;
double distance = this.distance(vectors[0]);
for (int i = 1; i < vectors.length; i++) {
double thisDistance = this.distance(vectors[i]);
if (thisDistance < distance) {
index = i;
distance = thisDistance;
}
}
return index;
}
}

public static Vector3 GetPlaneIntersectionPoint(Vector3[] side1, Vector3[] side2, Vector3[] side3) {
Plane plane1 = new Plane(side1);
Vector3 plane1Normal = plane1.normal().normalize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class Displacement {
public int power;
public Vector3 startposition;

public Vector3[][] normals;
public double[][] distances;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static VMF parseVMF(String text) {
disp = disp.replaceAll(objectRegex, ",\"$1\":$2");
disp = disp.replaceAll(keyValueRegex, "$1:$2,");
disp = disp.replaceAll(",,", ",");
disp = disp.replaceAll("\"startposition\":\"\\[(.+?) (.+?) (.+?)\\]\"", "\"startposition\":{\"x\":$1,\"y\":$2,\"z\":$3}"); // Format start position
normals = ",\"normals\":[" + normals.substring(0, normals.length() - 1) + "]";
disp = splice(disp, normals, disp.length() - 1);
distances = ",\"distances\":[" + distances.substring(0, distances.length() - 1) + "]";
Expand Down

0 comments on commit c354e4e

Please sign in to comment.