We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

I convert a 3d file with Aspose.3D lib but can't display in html viewer

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();
    }
}

@Alex_Chen

Would you please make sure that you are using the API with a valid or 30-days temporary license? In case issue still persists, please share your sample file with us so that we can further proceed to assist you accordingly.

I downloaded the lib directly on this page: Download 3D Model & Graphic Processing JAR Files | Aspose.3D

And then use it in my code for testing, I am not sure whether I have the license.

I try to upload the test file on this topic, but the .stl format is not allowed. do I have another way to share the test file?

@Alex_Chen

You can please get a license in order to evaluate the API without any trial version limitations. Once you get the license, you can set it in your code before using any method of the API. In case you still face any issues, please share your sample files with us so that we can try to replicate the issue and address it accordingly.

Got it, thanks

1 Like