Rename MtlExporter
This commit is contained in:
parent
b6ee9e851b
commit
2e636f5205
@ -1,11 +1,16 @@
|
|||||||
package net.sf.openrocket.file.wavefrontobj.export;
|
package net.sf.openrocket.file.wavefrontobj.export;
|
||||||
|
|
||||||
|
import de.javagl.obj.FloatTuple;
|
||||||
import net.sf.openrocket.appearance.Appearance;
|
import net.sf.openrocket.appearance.Appearance;
|
||||||
|
import net.sf.openrocket.appearance.Decal;
|
||||||
import net.sf.openrocket.appearance.defaults.DefaultAppearance;
|
import net.sf.openrocket.appearance.defaults.DefaultAppearance;
|
||||||
|
import net.sf.openrocket.file.wavefrontobj.DefaultFloatTuple;
|
||||||
import net.sf.openrocket.file.wavefrontobj.DefaultMtl;
|
import net.sf.openrocket.file.wavefrontobj.DefaultMtl;
|
||||||
import net.sf.openrocket.file.wavefrontobj.DefaultObj;
|
import net.sf.openrocket.file.wavefrontobj.DefaultObj;
|
||||||
|
import net.sf.openrocket.file.wavefrontobj.DefaultTextureOptions;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.util.Color;
|
import net.sf.openrocket.util.Color;
|
||||||
|
import net.sf.openrocket.util.Coordinate;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -14,11 +19,11 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
||||||
*/
|
*/
|
||||||
public class MtlExpoter {
|
public class AppearanceExporter {
|
||||||
private final DefaultObj obj;
|
private final DefaultObj obj;
|
||||||
private final RocketComponent component;
|
private final RocketComponent component;
|
||||||
private final String materialName;
|
private final String materialName;
|
||||||
private List<DefaultMtl> materials;
|
private final List<DefaultMtl> materials;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export the appearance of a rocket component
|
* Export the appearance of a rocket component
|
||||||
@ -28,7 +33,7 @@ public class MtlExpoter {
|
|||||||
* @param materialName The name of the material to generate
|
* @param materialName The name of the material to generate
|
||||||
* @param materials The list of materials to add the new material(s) to
|
* @param materials The list of materials to add the new material(s) to
|
||||||
*/
|
*/
|
||||||
public MtlExpoter(DefaultObj obj, RocketComponent component, String materialName, List<DefaultMtl> materials) {
|
public AppearanceExporter(DefaultObj obj, RocketComponent component, String materialName, List<DefaultMtl> materials) {
|
||||||
this.obj = obj;
|
this.obj = obj;
|
||||||
this.component = component;
|
this.component = component;
|
||||||
this.materialName = materialName;
|
this.materialName = materialName;
|
||||||
@ -50,6 +55,46 @@ public class MtlExpoter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply coloring
|
// Apply coloring
|
||||||
|
applyColoring(appearance, material);
|
||||||
|
|
||||||
|
// Apply texture
|
||||||
|
applyTexture(appearance, material);
|
||||||
|
|
||||||
|
materials.add(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyTexture(Appearance appearance, DefaultMtl material) {
|
||||||
|
Decal texture = appearance.getTexture();
|
||||||
|
if (texture == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final DefaultTextureOptions textureOptions = new DefaultTextureOptions();
|
||||||
|
|
||||||
|
// TODO: file name (save externally if saved inside .ork)
|
||||||
|
//String filePath = texture.getImage().getDecalFile().getAbsolutePath();
|
||||||
|
String filePath = "/Users/SiboVanGool/Downloads/hello.jpeg";
|
||||||
|
textureOptions.setFileName(filePath);
|
||||||
|
|
||||||
|
// Texture offset
|
||||||
|
final Coordinate origin = texture.getOffset();
|
||||||
|
Float origX = (float) origin.x;
|
||||||
|
Float origY = (float) origin.y;
|
||||||
|
textureOptions.setO(origX, origY, 0f);
|
||||||
|
|
||||||
|
// Texture scale
|
||||||
|
final Coordinate scale = texture.getScale();
|
||||||
|
Float scaleX = (float) scale.x;
|
||||||
|
Float scaleY = (float) scale.y;
|
||||||
|
textureOptions.setS(scaleX, scaleY, 1f);
|
||||||
|
|
||||||
|
// TODO: rotation
|
||||||
|
|
||||||
|
// Apply the texture
|
||||||
|
material.setMapKdOptions(textureOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyColoring(Appearance appearance, DefaultMtl material) {
|
||||||
Color color = appearance.getPaint();
|
Color color = appearance.getPaint();
|
||||||
final float r = color.getRed()/255f;
|
final float r = color.getRed()/255f;
|
||||||
final float g = color.getGreen()/255f;
|
final float g = color.getGreen()/255f;
|
||||||
@ -60,9 +105,5 @@ public class MtlExpoter {
|
|||||||
material.setD(color.getAlpha()/255f); // Opacity
|
material.setD(color.getAlpha()/255f); // Opacity
|
||||||
material.setNs((float) appearance.getShine() * 750); // Shine (max is 1000, but this too strong compared to OpenRocket's max)
|
material.setNs((float) appearance.getShine() * 750); // Shine (max is 1000, but this too strong compared to OpenRocket's max)
|
||||||
material.setIllum(2); // Use Phong reflection (specular highlights etc.)
|
material.setIllum(2); // Use Phong reflection (specular highlights etc.)
|
||||||
|
|
||||||
// TODO: Apply texture
|
|
||||||
|
|
||||||
materials.add(material);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -197,7 +197,7 @@ public class OBJExporterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void writeObj(DefaultObj obj, String filePath) {
|
private static void writeObj(DefaultObj obj, String filePath) {
|
||||||
try (OutputStream objOutputStream = new FileOutputStream(filePath)) {
|
try (OutputStream objOutputStream = new FileOutputStream(filePath, false)) {
|
||||||
ObjWriter.write(obj, objOutputStream);
|
ObjWriter.write(obj, objOutputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -223,8 +223,8 @@ public class OBJExporterFactory {
|
|||||||
|
|
||||||
// Export material
|
// Export material
|
||||||
if (options.isExportAppearance()) {
|
if (options.isExportAppearance()) {
|
||||||
MtlExpoter mtlExpoter = new MtlExpoter(obj, component, "mat_" + groupName, materials);
|
AppearanceExporter appearanceExporter = new AppearanceExporter(obj, component, "mat_" + groupName, materials);
|
||||||
mtlExpoter.doExport();
|
appearanceExporter.doExport();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export component
|
// Export component
|
||||||
|
Loading…
x
Reference in New Issue
Block a user