Skip to content

Commit

Permalink
Minor fixes to create RMS build 0.04.4c
Browse files Browse the repository at this point in the history
  • Loading branch information
Retera committed Sep 5, 2022
1 parent ff45edc commit 9307fc1
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 78 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Reteras Model Studio
This repository contains the sourcecode for the Reteras Model Studio application, which is available for download on the Hive Workshop.
![Image of ReterasModelStudio](https://www.hiveworkshop.com/data/ratory-images/159/159964-e1b13fddb241fe69a198f443b00b1637.png)
[![GAMEPLAY VIDEO](http://img.youtube.com/vi/kerN0cRhSAo/0.jpg)](http://www.youtube.com/watch?v=kerN0cRhSAo)

Reteras Model Studio is a Java-based Warcraft III model file editor that supports both the legacy 2003 MDX model format and game as well as the new Warcraft III Reforged MDX model files.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -13,14 +14,16 @@
import com.hiveworkshop.wc3.gui.modeledit.selection.VertexSelectionHelper;
import com.hiveworkshop.wc3.mdl.Animation;
import com.hiveworkshop.wc3.mdl.Bitmap;
import com.hiveworkshop.wc3.mdl.EditableModel;
import com.hiveworkshop.wc3.mdl.ExtLog;
import com.hiveworkshop.wc3.mdl.Geoset;
import com.hiveworkshop.wc3.mdl.GeosetAnim;
import com.hiveworkshop.wc3.mdl.GeosetVertex;
import com.hiveworkshop.wc3.mdl.Layer;
import com.hiveworkshop.wc3.mdl.Layer.FilterMode;
import com.hiveworkshop.wc3.mdl.EditableModel;
import com.hiveworkshop.wc3.mdl.LayerShader;
import com.hiveworkshop.wc3.mdl.Material;
import com.hiveworkshop.wc3.mdl.ShaderTextureTypeHD;
import com.hiveworkshop.wc3.mdl.Triangle;
import com.hiveworkshop.wc3.mdl.Vertex;

Expand Down Expand Up @@ -74,6 +77,15 @@ public TeamColorAddAction(final Collection<Triangle> trisToSeparate, final Edita
}
geosetCreated.setParentModel(model);
final Material newMaterial = new Material(geoset.getMaterial());
if (newMaterial.getLayers().size() == 1 && newMaterial.firstLayer().getLayerShader() == LayerShader.HD) {
newMaterial.firstLayer().setLayerShader(LayerShader.SD);
final EnumMap<ShaderTextureTypeHD, Bitmap> shaderTextures = newMaterial.firstLayer()
.getShaderTextures();
final Bitmap diffuseTexture = shaderTextures.get(ShaderTextureTypeHD.Diffuse);
shaderTextures.clear();
shaderTextures.put(ShaderTextureTypeHD.Diffuse, diffuseTexture);
}

if (newMaterial.getLayers().get(0).getFilterMode() == FilterMode.NONE) {
newMaterial.getLayers().get(0).setFilterMode(FilterMode.BLEND);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ public void render(final Geoset geo, final boolean renderOpaque, final int forma

NGGLDP.pipeline.glTangent4f(normalSumHeap3.x, normalSumHeap3.y, normalSumHeap3.z,
v.getTangent()[3]);
} else {
NGGLDP.pipeline.glTangent4f(0, 0, 1, 1);
}
int coordId = layer.getCoordId();
if (coordId >= v.getTverts().size()) {
Expand Down Expand Up @@ -1178,6 +1180,17 @@ public void render(final Geoset geo, final boolean renderOpaque, final int forma

NGGLDP.pipeline.glNormal3f(normalSumHeap.x, normalSumHeap.y, normalSumHeap.z);
}
if (pipeline.getCurrentPipelineIndex() != 0) {
if (v.getTangent() != null) {
normalHeap3.set(v.getTangent()[0], v.getTangent()[1], v.getTangent()[2]);
Matrix3f.transform(skinBonesMatrixSumHeap3, normalHeap3, normalSumHeap3);

NGGLDP.pipeline.glTangent4f(normalSumHeap3.x, normalSumHeap3.y, normalSumHeap3.z,
v.getTangent()[3]);
} else {
NGGLDP.pipeline.glTangent4f(0, 0, 1, 1);
}
}
int coordId = layer.getCoordId();
if (coordId >= v.getTverts().size()) {
coordId = v.getTverts().size() - 1;
Expand Down
10 changes: 8 additions & 2 deletions craft3data/src/com/hiveworkshop/wc3/mdl/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,15 @@ public QuaternionRotation getRenderRotation(final AnimatedRenderEnvironment anim
final Object interpolated = translationFlag.interpolateAt(animatedRenderEnvironment);
if (interpolated instanceof Double) {
final Double angle = (Double) interpolated;
final Vertex targetTranslation = parent.targetNode.getRenderTranslation(animatedRenderEnvironment);
Vertex targetTranslation = parent.targetNode.getRenderTranslation(animatedRenderEnvironment);
if (targetTranslation == null) {
targetTranslation = AnimFlag.TRANSLATE_IDENTITY;
}
final Vertex targetPosition = parent.targetPosition;
final Vertex sourceTranslation = getRenderTranslation(animatedRenderEnvironment);
Vertex sourceTranslation = getRenderTranslation(animatedRenderEnvironment);
if (sourceTranslation == null) {
sourceTranslation = AnimFlag.TRANSLATE_IDENTITY;
}
final Vertex sourcePosition = parent.Position;
axisHeap.x = targetPosition.x + targetTranslation.x - (sourcePosition.x + sourceTranslation.x);
axisHeap.y = targetPosition.y + targetTranslation.y - (sourcePosition.y + sourceTranslation.y);
Expand Down
135 changes: 116 additions & 19 deletions craft3data/src/com/hiveworkshop/wc3/mdl/EditableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.EnumMap;
import java.util.HashMap;
Expand Down Expand Up @@ -3084,7 +3085,7 @@ public static void convertToV800(final int targetLevelOfDetail, final EditableMo
if (!Double.isNaN(layer.getEmissive())) {
layer.setEmissive(Double.NaN);
}
final AnimFlag flag = layer.getFlag("Emissive");
final AnimFlag flag = layer.getFlag("EmissiveGain");
if (flag != null) {
layer.getAnims().remove(flag);
}
Expand Down Expand Up @@ -3183,6 +3184,19 @@ public static void convertToV800(final int targetLevelOfDetail, final EditableMo

public static void convertToV800BakingTextures(final int targetLevelOfDetail, final EditableModel model,
final File outputDirectory) {
convertToV800BakingTextures(targetLevelOfDetail, model, outputDirectory, null);
}

public static void convertToV800BakingTextures(final int targetLevelOfDetail, final EditableModel model,
final File outputDirectorySetting, final String assetDirectoryRelativePath) {
File outputDirectory;
if (assetDirectoryRelativePath != null) {
outputDirectory = new File(
outputDirectorySetting.getPath() + File.separatorChar + assetDirectoryRelativePath);
outputDirectory.mkdirs();
} else {
outputDirectory = outputDirectorySetting;
}
// Things to fix:
// 1.) format version
model.setFormatVersion(800);
Expand All @@ -3193,7 +3207,7 @@ class BakingInfo {
}
final Map<Triangle, Integer> triangleToTeamColorPixelCount = new HashMap<>();
final Map<Layer, BakingInfo> layerToBakingInfo = new HashMap<>();
for (final Material material : new HashSet<>(model.getMaterials())) {
for (final Material material : model.getMaterials()) {
for (final Layer layer : material.getLayers()) {
if (layer.getLayerShader() == LayerShader.HD) {
final BakingInfo bakingInfo = new BakingInfo();
Expand All @@ -3208,27 +3222,36 @@ class BakingInfo {
final com.etheller.collections.List<Layer> additionalLayers = new com.etheller.collections.ArrayList<>();
for (final Layer layer : material.getLayers()) {
final BakingInfo bakingInfo = layerToBakingInfo.get(layer);
bakingInfo.alphaFlag = layer.getFlag("Alpha");
if (layer.getLayerShader() == LayerShader.HD) {
if (layer.getLayerShader() == LayerShader.HD && bakingInfo != null) {
bakingInfo.alphaFlag = layer.getFlag("Alpha");
layer.getAnims().remove(bakingInfo.alphaFlag);
layer.setLayerShader(LayerShader.SD);
final EnumMap<ShaderTextureTypeHD, Bitmap> shaderTextures = layer.getShaderTextures();
final Bitmap diffuseBitmap = shaderTextures.get(ShaderTextureTypeHD.Diffuse);

final Bitmap emissive = shaderTextures.get(ShaderTextureTypeHD.Emissive);
if (emissive != null && emissive.getPath().toLowerCase().contains("black32")) {
if (emissive != null && !emissive.getPath().toLowerCase().contains("black32")) {
final Layer layerThree = new Layer(FilterMode.ADDITIVE, LayerShader.SD);
layerThree.getShaderTextures().put(ShaderTextureTypeHD.Diffuse, emissive);
layerThree.setFilterMode(FilterMode.ADDITIVE);
layerThree.add("Unshaded");
layerThree.add("Unfogged");
additionalLayers.add(layer);
additionalLayers.add(layerThree);
}
if (bakingInfo.bakedTexturePath != null) {
shaderTextures.clear();
final Bitmap newBitmap = new Bitmap(diffuseBitmap);
shaderTextures.put(ShaderTextureTypeHD.Diffuse, newBitmap);
newBitmap.setPath(bakingInfo.bakedTexturePath);
if (assetDirectoryRelativePath != null) {
String usedPath = assetDirectoryRelativePath + "\\" + bakingInfo.bakedTexturePath;
final int lastIndexOfMod = usedPath.lastIndexOf(".w3mod");
if (lastIndexOfMod != -1) {
usedPath = usedPath.substring(lastIndexOfMod + ".w3mod/".length());
}
newBitmap.setPath(usedPath);
} else {
newBitmap.setPath(bakingInfo.bakedTexturePath);
}
if (material.getFlags().contains("TwoSided")) {
material.getFlags().remove("TwoSided");
layer.add("TwoSided");
Expand All @@ -3238,7 +3261,7 @@ class BakingInfo {
if (!Double.isNaN(layer.getEmissive())) {
layer.setEmissive(Double.NaN);
}
final AnimFlag flag = layer.getFlag("Emissive");
final AnimFlag flag = layer.getFlag("EmissiveGain");
if (flag != null) {
layer.getAnims().remove(flag);
}
Expand All @@ -3247,16 +3270,22 @@ class BakingInfo {
}
for (final Bitmap tex : model.getTextures()) {
String path = tex.getPath();
if (path != null && !path.isEmpty() && !path.toLowerCase().contains("_bake")) {
final int dotIndex = path.lastIndexOf('.');
if (dotIndex != -1 && !path.endsWith(".blp")) {
path = path.substring(0, dotIndex);
}
if (!path.endsWith(".blp")) {
path = "_HD.w3mod:" + path;
path += ".blp";
if (path != null && !path.isEmpty()) {
if (!path.toLowerCase().contains("_bake")) {
final int dotIndex = path.lastIndexOf('.');
if (dotIndex != -1 && !path.endsWith(".blp")) {
path = path.substring(0, dotIndex);
}
if (!path.endsWith(".blp")) {
if (assetDirectoryRelativePath == null) {
path = "_HD.w3mod:" + path;
path += ".blp";
} else {
path += ".tga";
}
}
tex.setPath(path);
}
tex.setPath(path);
}
}
// 3.) geosets:
Expand Down Expand Up @@ -3312,15 +3341,25 @@ class BakingInfo {
final Bone dummyHeroGlowNode = new Bone("hero_reforged");
// this model needs hero glow
final Geoset heroGlow = new Geoset();
final Mesh heroGlowPlane = ModelUtils.createPlane((byte) 0, (byte) 1, new Vertex(0, 0, 1), 0, -64,
-64, 64, 64, 1);
final Mesh heroGlowPlane = ModelUtils.createPlane((byte) 0, (byte) 1, new Vertex(0, 0, 1), 0, -128,
-128, 128, 128, 1);
final Mesh heroGlowPlane2 = ModelUtils.createPlane((byte) 0, (byte) 1, new Vertex(0, 0, 1), 0, -100,
-100, 100, 100, 1);
for (final Vertex v : heroGlowPlane.getVertices()) {
v.z = 10;
}
for (final Vertex v : heroGlowPlane2.getVertices()) {
v.z = 8;
}
heroGlow.getVertices().addAll(heroGlowPlane.getVertices());
heroGlow.getVertices().addAll(heroGlowPlane2.getVertices());
for (final GeosetVertex gv : heroGlow.getVertices()) {
gv.setGeoset(heroGlow);
gv.getBones().clear();
gv.getBones().add(dummyHeroGlowNode);
}
heroGlow.getTriangles().addAll(heroGlowPlane.getTriangles());
heroGlow.getTriangles().addAll(heroGlowPlane2.getTriangles());
heroGlow.addFlag("Unselectable");
final Bitmap heroGlowBitmap = new Bitmap("");
heroGlowBitmap.setReplaceableId(2);
Expand Down Expand Up @@ -3422,6 +3461,64 @@ class BakingInfo {
faceSelectionManager.setSelection(selectedTriangles);
faceModelEditor.splitGeoset();
}

// final List<Animation> removedAnimations = new ArrayList<>();
final List<Animation> dupAnimations = new ArrayList<>();
final ArrayList<EventObject> allEventObjects = model.sortedIdObjects(EventObject.class);
final List<AnimFlag> allAnimFlags = model.getAllAnimFlags();
final Set<Integer> firstOfDups = new HashSet<>();
int greatestTime = 0;
for (final Animation anim : model.getAnims()) {
// if (anim.getName().toLowerCase(Locale.US).contains("cinematic")) {
// removedAnimations.add(anim);
// }
boolean dup = false;
for (final Animation otherAnim : model.getAnims()) {
if (otherAnim != anim) {
if (anim.getIntervalStart() == otherAnim.getIntervalStart()
&& anim.getIntervalEnd() == otherAnim.getIntervalEnd()) {
dup = true;
}
}
}
if (dup) {
if (!firstOfDups.add(anim.getIntervalStart())) {
// i need to copy & clone and stuff
dupAnimations.add(anim);
}
}
greatestTime = Math.max(greatestTime, Math.max(anim.getIntervalStart(), anim.getIntervalEnd()));
}
int nextTime = greatestTime + 1000;
for (final Animation dupAnimation : dupAnimations) {
final int newStart = nextTime;
final int newEnd = nextTime + dupAnimation.length();
dupAnimation.copyToInterval(newStart, newEnd, allAnimFlags, allEventObjects);
dupAnimation.setInterval(newStart, newEnd);
nextTime = newEnd + 1000;
}
Collections.sort(model.getAnims(), new Comparator<Animation>() {
@Override
public int compare(final Animation o1, final Animation o2) {
return Integer.compare(o1.getStart(), o2.getStart());
}
});

model.doSavePreps();
if (assetDirectoryRelativePath != null) {
for (final Bitmap tex : model.getTextures()) {
String path = tex.getPath();
if (path != null && !path.isEmpty()) {
int lastIndexOfMod = path.lastIndexOf(".w3mod");
if (lastIndexOfMod != -1) {
lastIndexOfMod += ".w3mod/".length();
path = path.substring(lastIndexOfMod);
tex.setPath(path);
}

}
}
}
}

public static void makeItHD(final EditableModel model) {
Expand Down
16 changes: 9 additions & 7 deletions craft3data/src/com/hiveworkshop/wc3/mdl/GeosetVertex.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,19 @@ public void un900Heuristic() {
for (final Bone bone : skinBones) {
if (bone != null) {
fallback = true;
if (skinBoneWeights[index] > 110) {
if (skinBoneWeights[index] > 60) {
bones.add(bone);
}
}
index++;
}
if (bones.isEmpty() && fallback) {
index = 0;
for (final Bone bone : skinBones) {
if (bone != null) {
if (bone != null && skinBoneWeights[index] > 0) {
bones.add(bone);
}
index++;
}
}
skinBones = null;
Expand Down Expand Up @@ -305,20 +307,20 @@ public static void rotateTangent(final double centerX, final double centerY, fin
break;
}
final double dy = y1 - cy;
final double r = Math.sqrt((dx * dx) + (dy * dy));
final double r = Math.sqrt(dx * dx + dy * dy);
double verAng = Math.acos(dx / r);
if (dy < 0) {
verAng = -verAng;
}
// if( getDimEditable(dim1) )
double nextDim = (Math.cos(verAng + radians) * r) + cx;
double nextDim = Math.cos(verAng + radians) * r + cx;
if (!Double.isNaN(nextDim)) {
vertex[firstXYZ] = (float) ((Math.cos(verAng + radians) * r) + cx);
vertex[firstXYZ] = (float) (Math.cos(verAng + radians) * r + cx);
}
// if( getDimEditable(dim2) )
nextDim = (Math.sin(verAng + radians) * r) + cy;
nextDim = Math.sin(verAng + radians) * r + cy;
if (!Double.isNaN(nextDim)) {
vertex[secondXYZ] = (float) ((Math.sin(verAng + radians) * r) + cy);
vertex[secondXYZ] = (float) (Math.sin(verAng + radians) * r + cy);
}
}

Expand Down
Loading

0 comments on commit 9307fc1

Please sign in to comment.