Rename MtlExporter
This commit is contained in:
parent
b6ee9e851b
commit
2e636f5205
@ -1,11 +1,16 @@
|
||||
package net.sf.openrocket.file.wavefrontobj.export;
|
||||
|
||||
import de.javagl.obj.FloatTuple;
|
||||
import net.sf.openrocket.appearance.Appearance;
|
||||
import net.sf.openrocket.appearance.Decal;
|
||||
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.DefaultObj;
|
||||
import net.sf.openrocket.file.wavefrontobj.DefaultTextureOptions;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.util.Color;
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -14,11 +19,11 @@ import java.util.List;
|
||||
*
|
||||
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
||||
*/
|
||||
public class MtlExpoter {
|
||||
public class AppearanceExporter {
|
||||
private final DefaultObj obj;
|
||||
private final RocketComponent component;
|
||||
private final String materialName;
|
||||
private List<DefaultMtl> materials;
|
||||
private final List<DefaultMtl> materials;
|
||||
|
||||
/**
|
||||
* Export the appearance of a rocket component
|
||||
@ -28,7 +33,7 @@ public class MtlExpoter {
|
||||
* @param materialName The name of the material to generate
|
||||
* @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.component = component;
|
||||
this.materialName = materialName;
|
||||
@ -50,6 +55,46 @@ public class MtlExpoter {
|
||||
}
|
||||
|
||||
// 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();
|
||||
final float r = color.getRed()/255f;
|
||||
final float g = color.getGreen()/255f;
|
||||
@ -60,9 +105,5 @@ public class MtlExpoter {
|
||||
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.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) {
|
||||
try (OutputStream objOutputStream = new FileOutputStream(filePath)) {
|
||||
try (OutputStream objOutputStream = new FileOutputStream(filePath, false)) {
|
||||
ObjWriter.write(obj, objOutputStream);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@ -223,8 +223,8 @@ public class OBJExporterFactory {
|
||||
|
||||
// Export material
|
||||
if (options.isExportAppearance()) {
|
||||
MtlExpoter mtlExpoter = new MtlExpoter(obj, component, "mat_" + groupName, materials);
|
||||
mtlExpoter.doExport();
|
||||
AppearanceExporter appearanceExporter = new AppearanceExporter(obj, component, "mat_" + groupName, materials);
|
||||
appearanceExporter.doExport();
|
||||
}
|
||||
|
||||
// Export component
|
||||
|
Loading…
x
Reference in New Issue
Block a user