Skip to content

Commit

Permalink
Merge branch 'drms' of github.com:/Retera/ReterasModelStudio into drms
Browse files Browse the repository at this point in the history
  • Loading branch information
Retera committed Aug 13, 2022
2 parents 10ca6fa + 1e2771a commit 5b88003
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 49 deletions.
31 changes: 16 additions & 15 deletions craft3data/src/com/hiveworkshop/rms/editor/render3d/NGGLDP.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private int createShader(final int shaderType, final String shaderSource) {
@Override
public void glBegin(final int type) {
pipelineVertexBuffer.clear();
this.glBeginType = type;
glBeginType = type;
vertexCount = 0;
uvCount = 0;
normalCount = 0;
Expand Down Expand Up @@ -590,7 +590,7 @@ public void glLightModel(final int lightModel, final FloatBuffer ambientColor) {

@Override
public void glMatrixMode(final int mode) {
this.matrixMode = mode;
matrixMode = mode;

}

Expand Down Expand Up @@ -720,7 +720,7 @@ public static final class HDDiffuseShaderPipeline implements Pipeline {
" mat3 mv = mat3(u_projection);\r\n" + //
" mat3 TBN = transpose(mat3(normalize(mv*tangent), normalize(mv*binormal), normalize(mv*a_normal.xyz)));\r\n"
+ //
" v_tangentLightPos = TBN * (mv * u_lightDirection).xyz;\r\n" + //
" v_tangentLightPos = TBN * normalize(u_lightDirection - gl_Position.xyz).xyz;\r\n" + //
" v_tangentViewPos = TBN * u_viewPos;\r\n" + //
" v_tangentFragPos = TBN * (u_projection * a_position).xyz;\r\n" + //
"}\r\n\0";
Expand Down Expand Up @@ -802,15 +802,15 @@ public static final class HDDiffuseShaderPipeline implements Pipeline {
" vec4 emissiveTexel = texture2D(u_textureEmissive, v_uv);\r\n" + //
" vec4 reflectionsTexel = clamp(0.2+2.0*texture2D(u_textureReflections, vec2(gl_FragCoord.x/u_viewportSize.x, -gl_FragCoord.y/u_viewportSize.y)), 0.0, 1.0);\r\n"
+ //
" vec3 lightDir = normalize(v_tangentViewPos);\r\n" + //
" vec3 lightDir = v_tangentLightPos;\r\n" + //
" float cosTheta = dot(lightDir, normal);\r\n" + //
" float lambertFactor = clamp(cosTheta, 0.0, 1.0);\r\n" + //
" vec3 diffuse = (clamp(lambertFactor * (ormTexel.r) + 0.1, 0.0, 1.0)) * color.xyz;\r\n" + //
" float lambertFactor = abs(cosTheta);\r\n" + //
" vec3 diffuse = (clamp(lambertFactor, 0.0, 1.0)) * color.xyz;\r\n" + //
" vec3 viewDir = normalize(v_tangentViewPos - v_tangentFragPos);\r\n" + //
" vec3 reflectDir = reflect(-lightDir, normal);\r\n" + //
" vec3 halfwayDir = normalize(lightDir + viewDir);\r\n" + //
" float spec = pow(max(dot(normal, halfwayDir), 0.0), 32.0);\r\n" + //
" vec3 specular = vec3(max(ormTexel.b-0.5, 0.0)) * spec /* * reflectionsTexel.xyz*/;\r\n" + //
" vec3 specular = vec3(max(ormTexel.b-0.5, 0.0)) * spec * reflectionsTexel.xyz;\r\n" + //
" vec3 fresnelColor = vec3(u_fresnelColor.rgb * (1.0 - u_fresnelTeamColor) + teamColorTexel.rgb * u_fresnelTeamColor) * v_color.rgb;\r\n"
+ //
" vec3 fresnel = fresnelColor*pow(1.0 - cosTheta, 1.0)*u_fresnelColor.a;\r\n" + //
Expand Down Expand Up @@ -865,7 +865,7 @@ private int createShader(final int shaderType, final String shaderSource) {
@Override
public void glBegin(final int type) {
pipelineVertexBuffer.clear();
this.glBeginType = type;
glBeginType = type;
vertexCount = 0;
uvCount = 0;
normalCount = 0;
Expand Down Expand Up @@ -980,8 +980,9 @@ public void glEnd() {
textureUsed = 0;
GL20.glUniform1i(GL20.glGetUniformLocation(shaderProgram, "u_alphaTest"), alphaTest);
GL20.glUniform1i(GL20.glGetUniformLocation(shaderProgram, "u_lightingEnabled"), lightingEnabled);
GL20.glUniform3f(GL20.glGetUniformLocation(shaderProgram, "u_lightDirection"), -24.1937f, 444.411f,
30.4879f);
// GL20.glUniform3f(GL20.glGetUniformLocation(shaderProgram, "u_lightDirection"), -24.1937f, 444.411f,
// 30.4879f);
GL20.glUniform3f(GL20.glGetUniformLocation(shaderProgram, "u_lightDirection"), 0.0f, 0.0f, -10000f);
GL20.glUniform3f(GL20.glGetUniformLocation(shaderProgram, "u_viewPos"), 0, 0, -1);
GL20.glUniform2f(GL20.glGetUniformLocation(shaderProgram, "u_viewportSize"), viewportWidth, viewportHeight);
GL20.glUniform1f(GL20.glGetUniformLocation(shaderProgram, "u_fresnelTeamColor"), fresnelTeamColor);
Expand Down Expand Up @@ -1083,12 +1084,12 @@ public void glColor3f(final float r, final float g, final float b) {

@Override
public void glFresnelTeamColor1f(final float v) {
this.fresnelTeamColor = v;
fresnelTeamColor = v;
}

@Override
public void glFresnelOpacity1f(final float v) {
this.fresnelOpacity = v;
fresnelOpacity = v;
}

@Override
Expand Down Expand Up @@ -1182,7 +1183,7 @@ public void glLightModel(final int lightModel, final FloatBuffer ambientColor) {

@Override
public void glMatrixMode(final int mode) {
this.matrixMode = mode;
matrixMode = mode;

}

Expand Down Expand Up @@ -1257,8 +1258,8 @@ public void glActiveHDTexture(final int textureUnit) {

@Override
public void glViewport(final int x, final int y, final int w, final int h) {
this.viewportWidth = w;
this.viewportHeight = h;
viewportWidth = w;
viewportHeight = h;
GL11.glViewport(x, y, w, h);
}

Expand Down
83 changes: 50 additions & 33 deletions craft3data/src/com/hiveworkshop/wc3/mdl/ParticleEmitter2.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,58 +162,65 @@ public ParticleEmitter2(final ParticleEmitter2Chunk.ParticleEmitter2 emitter) {
if (emitter.particleEmitter2Visibility != null) {
add(new AnimFlag(emitter.particleEmitter2Visibility));
}
if ((node.flags >> 15 & 1) == 1) {
if (((node.flags >> 15) & 1) == 1) {
add("Unshaded");
}
if ((node.flags >> 16 & 1) == 1) {
if (((node.flags >> 16) & 1) == 1) {
add("SortPrimsFarZ");
}
if ((node.flags >> 17 & 1) == 1) {
if (((node.flags >> 17) & 1) == 1) {
add("LineEmitter");
}
if ((node.flags >> 18 & 1) == 1) {
if (((node.flags >> 18) & 1) == 1) {
add("Unfogged");
}
if ((node.flags >> 19 & 1) == 1) {
if (((node.flags >> 19) & 1) == 1) {
add("ModelSpace");
}
if ((node.flags >> 20 & 1) == 1) {
if (((node.flags >> 20) & 1) == 1) {
add("XYQuad");
}
if (emitter.particleEmitter2Speed != null) {
add(new AnimFlag(emitter.particleEmitter2Speed));
} else {
}
else {
setSpeed(emitter.speed);
}
if (emitter.particleEmitter2Variation != null) {
add(new AnimFlag(emitter.particleEmitter2Variation));
} else {
}
else {
setVariation(emitter.variation);
}
if (emitter.particleEmitter2Latitude != null) {
add(new AnimFlag(emitter.particleEmitter2Latitude));
} else {
}
else {
setLatitude(emitter.latitude);
}
if (emitter.particleEmitter2Gravity != null) {
add(new AnimFlag(emitter.particleEmitter2Gravity));
} else {
}
else {
setGravity(emitter.gravity);
}
setLifeSpan(emitter.lifespan);
if (emitter.particleEmitter2EmissionRate != null) {
add(new AnimFlag(emitter.particleEmitter2EmissionRate));
} else {
}
else {
setEmissionRate(emitter.emissionRate);
}
if (emitter.particleEmitter2Length != null) {
add(new AnimFlag(emitter.particleEmitter2Length));
} else {
}
else {
setLength(emitter.length);
}
if (emitter.particleEmitter2Width != null) {
add(new AnimFlag(emitter.particleEmitter2Width));
} else {
}
else {
setWidth(emitter.width);
}
switch (emitter.filterMode) {
Expand Down Expand Up @@ -258,8 +265,8 @@ public ParticleEmitter2(final ParticleEmitter2Chunk.ParticleEmitter2 emitter) {
setTime(emitter.time);
// SegmentColor - Inverse order for MDL!
for (int i = 0; i < 3; i++) {
setSegmentColor(i, new Vertex(emitter.segmentColor[i * 3 + 2], emitter.segmentColor[i * 3 + 1],
emitter.segmentColor[i * 3 + 0]));
setSegmentColor(i, new Vertex(emitter.segmentColor[(i * 3) + 2], emitter.segmentColor[(i * 3) + 1],
emitter.segmentColor[(i * 3) + 0]));
}
setAlpha(new Vertex((256 + emitter.segmentAlpha[0]) % 256, (256 + emitter.segmentAlpha[1]) % 256,
(256 + emitter.segmentAlpha[2]) % 256));
Expand Down Expand Up @@ -306,7 +313,10 @@ public IdObject copy() {
}

public void updateTextureRef(final ArrayList<Bitmap> textures) {
texture = textures.get(getTextureId());
int textureId = getTextureId();
if ((textureId >= 0) && (textureId < textures.size())) {
texture = textures.get(textureId);
}
}

public int getTextureId() {
Expand All @@ -333,69 +343,73 @@ public static ParticleEmitter2 read(final BufferedReader mdl) {
foundType = true;
// JOptionPane.showMessageDialog(null,"ObjectId from line:
// "+line);
} else if (line.contains("Parent")) {
}
else if (line.contains("Parent")) {
pe.parentId = MDLReader.splitToInts(line)[0];
foundType = true;
// JOptionPane.showMessageDialog(null,"Parent from line:
// "+line);
// lit.parent = mdlr.getIdObject(lit.parentId);
} else if (line.contains("SegmentColor")) {
}
else if (line.contains("SegmentColor")) {
boolean reading = true;
foundType = true;
// JOptionPane.showMessageDialog(null,"SegmentColor from
// line: "+line);
for (int i = 0; reading && i < 3; i++) {
for (int i = 0; reading && (i < 3); i++) {
line = MDLReader.nextLine(mdl);
if (line.contains("Color")) {
pe.segmentColor[i] = Vertex.parseText(line);
} else {
}
else {
reading = false;
MDLReader.reset(mdl);
line = MDLReader.nextLine(mdl);
}
}
line = MDLReader.nextLine(mdl);
}
for (int i = 0; i < vertexDataNames.length && !foundType; i++) {
for (int i = 0; (i < vertexDataNames.length) && !foundType; i++) {
if (line.contains("\t" + vertexDataNames[i] + " ")) {
foundType = true;
pe.vertexData[i] = Vertex.parseText(line);
// JOptionPane.showMessageDialog(null,vertexDataNames[i]+"
// from line: "+line);
}
}
for (int i = 0; i < loneDoubleNames.length && !foundType; i++) {
for (int i = 0; (i < loneDoubleNames.length) && !foundType; i++) {
if (line.contains(loneDoubleNames[i])) {
foundType = true;
pe.loneDoubleData[i] = MDLReader.readDouble(line);
// JOptionPane.showMessageDialog(null,loneDoubleNames[i]+"
// from line: "+line);
}
}
for (int i = 0; i < loneIntNames.length && !foundType; i++) {
for (int i = 0; (i < loneIntNames.length) && !foundType; i++) {
if (line.contains(loneIntNames[i])) {
foundType = true;
pe.loneIntData[i] = MDLReader.readInt(line);
// JOptionPane.showMessageDialog(null,loneIntNames[i]+"
// from line: "+line);
}
}
for (int i = 0; i < knownFlagNames.length && !foundType; i++) {
for (int i = 0; (i < knownFlagNames.length) && !foundType; i++) {
if (line.contains(knownFlagNames[i])) {
foundType = true;
pe.knownFlags[i] = true;
// JOptionPane.showMessageDialog(null,knownFlagNames[i]+"
// from line: "+line);
}
}
for (int i = 0; i < timeDoubleNames.length && !foundType; i++) {
for (int i = 0; (i < timeDoubleNames.length) && !foundType; i++) {
if (line.contains(timeDoubleNames[i])) {
foundType = true;
// JOptionPane.showMessageDialog(null,timeDoubleNames[i]+"
// from line: "+line);
if (line.contains("static")) {
pe.timeDoubleData[i] = MDLReader.readDouble(line);
} else {
}
else {
MDLReader.reset(mdl);
pe.animFlags.add(AnimFlag.read(mdl));
}
Expand All @@ -419,7 +433,8 @@ public static ParticleEmitter2 read(final BufferedReader mdl) {
line = MDLReader.nextLine(mdl);
}
return pe;
} else {
}
else {
JOptionPane.showMessageDialog(MDLReader.getDefaultContainer(),
"Unable to parse ParticleEmitter2: Missing or unrecognized open statement.");
}
Expand All @@ -433,7 +448,7 @@ public void printTo(final PrintWriter writer) {
// -- uses parentId value of idObject superclass
// -- uses the parent (java Object reference) of idObject superclass
// -- uses the TextureID value
final ArrayList<AnimFlag> pAnimFlags = new ArrayList<>(this.animFlags);
final ArrayList<AnimFlag> pAnimFlags = new ArrayList<>(animFlags);
writer.println(MDLReader.getClassName(this.getClass()) + " \"" + getName() + "\" {");
if (objectId != -1) {
writer.println("\tObjectId " + objectId + ",");
Expand All @@ -451,9 +466,10 @@ public void printTo(final PrintWriter writer) {
currentFlag = timeDoubleNames[i];
if (timeDoubleData[i] != 0) {
writer.println("\tstatic " + currentFlag + " " + MDLReader.doubleToString(timeDoubleData[i]) + ",");
} else {
}
else {
boolean set = false;
for (int a = 0; a < pAnimFlags.size() && !set; a++) {
for (int a = 0; (a < pAnimFlags.size()) && !set; a++) {
if (pAnimFlags.get(a).getName().equals(currentFlag)) {
pAnimFlags.get(a).printTo(writer, 1);
pAnimFlags.remove(a);
Expand Down Expand Up @@ -484,9 +500,10 @@ public void printTo(final PrintWriter writer) {
currentFlag = timeDoubleNames[i];
if (timeDoubleData[i] != 0) {
writer.println("\tstatic " + currentFlag + " " + MDLReader.doubleToString(timeDoubleData[i]) + ",");
} else {
}
else {
boolean set = false;
for (int a = 0; a < pAnimFlags.size() && !set; a++) {
for (int a = 0; (a < pAnimFlags.size()) && !set; a++) {
if (pAnimFlags.get(a).getName().equals(currentFlag)) {
pAnimFlags.get(a).printTo(writer, 1);
pAnimFlags.remove(a);
Expand Down Expand Up @@ -827,7 +844,7 @@ public void setTailDecayUVAnim(final Vertex tailDecayUVAnim) {
@Override
public void add(final String flag) {
boolean isKnownFlag = false;
for (int i = 0; i < knownFlagNames.length && !isKnownFlag; i++) {
for (int i = 0; (i < knownFlagNames.length) && !isKnownFlag; i++) {
if (knownFlagNames[i].equals(flag)) {
knownFlags[i] = true;
isKnownFlag = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;

import javax.swing.AbstractAction;
import javax.swing.Icon;
Expand Down Expand Up @@ -65,6 +66,7 @@ public static ImageIcon getIcon(final DataTable worldEditorData, final String ic
if (!iconTexturePath.toString().endsWith(".blp")) {
iconTexturePath += ".blp";
}
return new ImageIcon(BLPHandler.get().getGameTex(iconTexturePath));
BufferedImage gameTex = BLPHandler.get().getGameTex(iconTexturePath);
return gameTex == null ? null : new ImageIcon(gameTex);
}
}

0 comments on commit 5b88003

Please sign in to comment.