I convert a 3d file with Aspose.3D lib but can’t display it in html viewer. There is only the grid in the viewer. But in the demo of you can display the 3d model.
my code:
public class Main {
public static void main(String[] args) throws IOException {
File[] originFiles= new File(getOriginDir()).listFiles();
if (originFiles==null){
return;
}
for(File originFile:originFiles){
File outFile=new File(getOutputDir() + "/"+originFile.getName().split("\\.")[0]+"/index.html");
File outDir=new File(getOutputDir() + "/"+originFile.getName().split("\\.")[0]);
if (!outDir.exists()){
outDir.mkdir();
}
if(!outFile.exists()){
outFile.createNewFile();
}
// ExStart:html5SaveOption
// Initialize a scene
Scene scene = new Scene();
StlLoadOptions loadSTLOpts = new StlLoadOptions();
// Flip the coordinate system.
loadSTLOpts.setFlipCoordinateSystem(true);
// Configure the look up paths to allow importer to find external dependencies.
loadSTLOpts.getLookupPaths().add(originFile.getAbsolutePath());
scene.open(originFile.getAbsolutePath(),LoadOption.stlLoadOption(originFile.getAbsolutePath()));
// Initialize a node
// Node node = scene.getRootNode().createChildNode(new Cylinder());
// // Set child node properties
// LambertMaterial mat = new LambertMaterial();
// mat.setDiffuseColor(new Vector3(0.34, 0.59, 0.41));
// node.setMaterial(mat);
Light light = new Light();
light.setLightType(LightType.POINT);
scene.getRootNode().createChildNode(light).getTransform().setTranslation(10, 0, 10);
// Initialize HTML5SaveOptions
Html5SaveOptions opt = new Html5SaveOptions();
// Turn off the grid
opt.setShowGrid(true);
//Turn off the user interface
opt.setShowUI(true);
scene.save(outFile.getAbsolutePath(), FileFormat.HTML5);
// ExEnd:html5SaveOption
}
}
public static String getDataDir() {
return (new File("testdata")).getAbsolutePath() + "/";
}
public static String getOriginDir() {
File file = new File(getDataDir()+"origin/");
if(!file.isDirectory())
file.mkdirs();
return file.getAbsolutePath();
}
private static String getOutputDir() {
File file = new File(getDataDir()+"output/");
if(!file.isDirectory())
file.mkdirs();
return file.getAbsolutePath();
}
public static String getOutputFilePath(String s) {
return Paths.get(getOutputDir(), s).toString();
}
}