Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volume is not calculated #32

Open
tjasa-karas opened this issue Nov 30, 2023 · 6 comments
Open

Volume is not calculated #32

tjasa-karas opened this issue Nov 30, 2023 · 6 comments

Comments

@tjasa-karas
Copy link

Hello,
i have noticed that the get_info function returns a null value. i believe that there is a problem with one of the libraries.
this is the code i've used to try and acess the volume and other info using the get_model_info() method.

<title>Viewstl Javascript Plugin - Simple Example</title>
<body>
    <div id="stl_cont" style="width:500px;height:500px;margin:0 auto;"></div>

    <script src="stl_viewer.min.js"></script> 
    <script src="parser.min.js"></script>
    <script src="three.min.js"></script>
    <script src="CanvasRenderer.js"></script>
    <script src="OrbitControls.js"></script>
    <script src="Projector.js"></script> 
    <script src="webgl_detector.js"></script>
    <script src="TrackballControls.js"></script>

    <script>
        var stl_viewer=new StlViewer
        (
            document.getElementById("stl_cont"),
        );
        stl_viewer.add_model({id:0, filename:"mystl.stl"});
        
        alert( JSON.stringify(stl_viewer.get_model_info(0)) );
        
    </script>

</body>
@omrips
Copy link
Owner

omrips commented Dec 3, 2023

Hi, sorry for the late response, you have to wait the model to load before calc its volume,
please use "ready_callback" option, like this:

var stl_viewer=new StlViewer
        (
            document.getElementById("stl_cont"),
            all_loaded_callback:loaded_callback
        );
stl_viewer.add_model({id:0, filename:"mystl.stl"});

function loaded_callback()
{
       alert( JSON.stringify(stl_viewer.get_model_info(0)) );
}

BTW. you don't need to load all of the libs above, only stl_viewer.min.js

@tjasa-karas
Copy link
Author

Hello thank you so much! I figured it out after a day so its okej :)

I tried to access the volume setting through another domain called Bubble.io. i uploaded a file on that domain and tried to calculate its volume but when i run the code, i get an error saying that the web worker couldnt be constructed. Do you maybe know how to fix this issue?

@omrips
Copy link
Owner

omrips commented Dec 9, 2023

please post the log here (with Chrome do ctrl+shift+j)

@tjasa-karas
Copy link
Author

@tjasa-karas
Copy link
Author

tjasa-karas commented Dec 9, 2023

THE ERROR:

run_debug.js:662 Element Volumecalculator(testing) A - The plugin STL parser (testing) / element Volume calculator (testing) threw the following error: Error: Failed to construct 'Worker': Script at 'https://9eaebe63011526167540ff8dae4c76e7.cdn.bubble.io/f1701339509235x335094444249260300/load_stl.min.js' cannot be accessed from origin 'https://api-testing-81257.bubbleapps.io'.
    at StlViewer.load_from_stl_file (https://9eaebe63011526167540ff8dae4c76e7.cdn.bubble.io/f1701339509235x335094444249260300/stl_viewer.min.js:2:4288)
    at StlViewer.load_model (https://9eaebe63011526167540ff8dae4c76e7.cdn.bubble.io/f1701339509235x335094444249260300/stl_viewer.min.js:2:3795) (please check your plugin's code)

THE PLUGIN CODE:

  • content in header:

<script src="//meta-q.cdn.bubble.io/---noworker.js"></script>
<script src="//meta-q.cdn.bubble.io/---/stl_viewer.min.js"></script>
<script src="//meta-q.cdn.bubble.io/--/three.min.js"></script> 
<script src="//meta-q.cdn.bubble.io/--/OrbitControls.js"></script>
<div id="stl_cont" style="width:1350px;height:800px;margin:0 auto;background-color:#909090;"></div>
  • content in the initialize function:
function(instance, context) {
	function stl_loaded()
	{
		console.log(stl_viewer.get_model_info(0));
		
		console.log(stl_viewer.get_vsj());
	}
	

	var stl_viewer=new StlViewer
	(
		document.getElementById("stl_cont")
		,
		{
			model_loaded_callback:stl_loaded,

		
			

			models:
			[
				{id:0, filename:"//meta-q.cdn.bubble.io/---/06_elsa_right_hand.stl"},
			] 
			
		}
	);
}

@omrips
Copy link
Owner

omrips commented Dec 10, 2023

It can't load some js files for some reason, try to load them manually:
three.min.js
stl_viewer.min.js
parser.min.js
load_stl.min.js
webgl_detector.js
CanvasRenderer.js
OrbitControls.js
TrackballControls.js
Projector.js

and set "load_three_files:false" at the init options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants