sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [CODE] Camera settings

    Scheduled Pinned Locked Moved Developers' Forum
    28 Posts 5 Posters 4.3k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Chris FullmerC Offline
      Chris Fullmer
      last edited by

      So to further understand now: You have an existing model with scenes in it. Then you iterate otver the scenes and get all the cameras and save the camera settings. Then you want to use your script to re-create the cameras from the scenes. Is that the idea?

      If so, then what your script does should not differ from the cameras in the scenes. so if the camera is zoomed way out in the scene, then that is what your script should make too. IS this not currently what you are achieving?

      If that is the case, then it sounds like somehow you are missing something in the camera settings when you extract them from the scenes. And the field of view might be my guess. Are you checking or setting the Field of View at any point in your script? I think ideall you would check the FOV of the scene camera and then st your camera to match when you create your camera object.

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • chrisglasierC Offline
        chrisglasier
        last edited by

        @chris fullmer said:

        So to further understand now: You have an existing model with scenes in it. Then you iterate otver the scenes and get all the cameras and save the camera settings. Then you want to use your script to re-create the cameras from the scenes. Is that the idea?

        Yes - maybe recreate views of the model is a better term.

        @unknownuser said:

        If so, then what your script does should not differ from the cameras in the scenes. so if the camera is zoomed way out in the scene, then that is what your script should make too. IS this not currently what you are achieving?

        Please see pixs and code.

        @unknownuser said:

        If that is the case, then it sounds like somehow you are missing something in the camera settings when you extract them from the scenes. And the field of view might be my guess. Are you checking or setting the Field of View at any point in your script? I think ideall you would check the FOV of the scene camera and then st your camera to match when you create your camera object.

        Please have a look at the code. From the console and js output it seems the fov does not change. Perhaps I have made the error there.


        No zoom_extents


        original scene

        With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

        1 Reply Last reply Reply Quote 0
        • chrisglasierC Offline
          chrisglasier
          last edited by

          ... and the non perspective views are the same ...

          With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            I can't parse your code very quickly Chris. Especially once it goes out to js, I'm lost. But it looks like you are doing the right thing by getting the fov for the perspective cameras. But somewhere in there, something is getting messed up. If you get the values correctly and apply them back correctly, the cameras will match 100%. There should be no need to do a zoom extents. So it is clear that somewhere the values are not coming through correctly. I would do some solid value testing. Output all the values before they go to js, then output them again as you recreate the camera. See if they differe at all.

            Also, if you could make a model with a scene, then run your script on it and recreate that camera, then create a new scene that uses your camera info it might be easier to compare the settings of the 2 cameras - the original and your recreation.

            Chris

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            1 Reply Last reply Reply Quote 0
            • chrisglasierC Offline
              chrisglasier
              last edited by

              Thanks for all your effort Chris. Just by posting those pix **.mm** came to mind ... errgh ... but somehow oddly satisfying. First go seems to work but still not quite it. You know when the French gave you the Statue of Liberty, it would have been nice if you had taken up their metric system.

              Tally ho!

              With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                Hehe, yeah sorry about that imperial vs. metric thing. I hope you're able to pin down the problems!

                Chris

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  @chrisglasier said:

                  Yes guess what - fov is in mm by default!
                  Here's a kind of victory pic.
                  I amended the previous code in case anyone is thinking of doing something similarly lunatic.

                  Cheers.

                  hi Chris,

                  I can't get the feb016.avi to run on any player, I'm on a Mac but don't normally have problems with .avi
                  can you out-put a quicktime.mov as well? Is it the same video that's up on youtube?
                  I'm very interested in your approach and although I'm only just starting to learn coding, I'd like to integrate namespace conventions into my efforts right from the start.

                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • chrisglasierC Offline
                    chrisglasier
                    last edited by

                    @unknownuser said:

                    Is it the same video that's up on youtube?

                    Yes. You could also look at my old website (button on left).

                    Now I'm off to the real movies for a while.

                    Interested in your interest.

                    With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                    1 Reply Last reply Reply Quote 0
                    • chrisglasierC Offline
                      chrisglasier
                      last edited by

                      Yes guess what - fov is in mm by default!
                      Here's a kind of victory pic.
                      I amended the previous code in case anyone is thinking of doing something similarly lunatic.

                      Cheers.


                      Metric!

                      With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                      1 Reply Last reply Reply Quote 0
                      • chrisglasierC Offline
                        chrisglasier
                        last edited by

                        A couple of odd things I just discovered when doing something else is that whereas the perspectives are spot on the standard views are unstable. The top/plan views for example get some 164% bigger when imported. See pixs:
                        originalrecreated
                        The other is that I .mm 'd the vector3ds for up. I changed them but it didn't make any difference. (Obviously I don't understand this stuff well enough.)

                        With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                        1 Reply Last reply Reply Quote 0
                        • chrisglasierC Offline
                          chrisglasier
                          last edited by

                          Thanks for your help.

                          [flash=600,432:21eq7727]http://www.youtube.com/v/6h6m_xr5IYA&hl=en_US&fs=1&[/flash:21eq7727]

                          For anyone interested here are extracts from the rather clunky code I ended up to support this v quick video hinting at the potential.

                          Ruby extractor:

                          
                          pages	= model.pages
                          		layers	= model.layers
                          		styles	= model.styles
                          		@parray	=[]
                          		pages.each do |page|
                          			model.pages.selected_page = page
                          			cam  = page.camera
                          			name = page.name
                          			pl = []
                          				page.layers.each do |layer|
                          					pl.push(layer.name)
                          				end
                          			pl = pl.join(",")
                          			st = page.style
                          			st = st.name
                          			pts = [cam.eye, cam.target, cam.up]
                          			per = cam.perspective?
                          			if(cam.perspective?)
                          				fov = cam.fov
                          				sub = [pts,per,fov]
                          			else
                          				sub = [pts,per]
                          			end
                          			sub = sub.join("yy")
                          			entry = [name,pl,st,sub]
                          			@parray.push(entry.join("xx"))	
                          
                          

                          JS converter

                          
                          p = ret[3].split(";");
                          	pages = [];
                          	for (a = 0; a < p.length; a += 1){
                          		p[a]	= p[a].split("xx");
                          		lgth	= fLength(nset);
                          		lab		= lgth.toString(); 
                          		o		= {};
                          		o.Type	= "Scene"; 
                          		o.Genus	= "New";
                          		o.Name	= p[a][0];
                          		o.Backlink	= [];
                          		o.Backlink.push(sRoot);
                          		o.Hidden	= [];
                          		nset[lab]	= o;
                          		nset[sRoot].Forelink.push(lab);
                          		pages.push(lab);
                          		nset[lab].Forelink = [];
                          		//mark hidden layers
                          		//alert(p[a])
                          		pp 		= p[a][1].split(",");
                          		
                          		for (c = 0; c < pp.length; c += 1){
                          			for (d = 0; d < combo.length; d += 1){
                          				if(pp[c] === nset[combo[d]].Name){
                          					nset[combo[d]].Filter = 1;
                          				}
                          			}
                          		}
                          		for (d = 0; d < combo.length; d += 1){
                          			nset[combo[d]].Backlink = [];
                          			if(!nset[combo[d]].Filter){
                          				nset[lab].Forelink.push(combo[d].toString());
                          				nset[combo[d]].Backlink.push(lab);
                          			}
                          			else{
                          				delete nset[combo[d]].Filter;
                          			}
                          		}
                          		//name,pl,st,camry
                          	nset[lab].Style = p[a][2];
                          	nset[lab].Camera = p[a][3];
                          	}		
                          
                          

                          JS scene call

                          
                          function fScenes(){
                          	var cell,nt,node,name,kids,dn,cm,genus,cmps;
                          	cell = document.getElementById("ScenesOn")
                          	nt		= config.nametrail;
                          	node	= nt[nt.length-1][0];
                          	type	= nset[node].Type;
                          	if(type === "Scene"){
                          		name	= nset[node].Name;
                          		kids	= nset[node].Forelink;
                          		dn		= [];
                          		cm		= [];
                          		for(a = 0; a <kids.length; a += 1){
                          			genus = nset[kids[a]].Genus
                          			if(genus === "Dimension" || genus === "Notes"){
                          				dn.push(nset[kids[a]].Name);
                          				continue;
                          			}
                          			dn.push(nset[kids[a]].Name);
                          			cmps = nset[kids[a]].Forelink;
                          			for(b = 0; b <cmps.length; b += 1){
                          				cm.push(nset[cmps[b]].Index); 
                          			}		
                          		}
                          		name	= nset[node].Name;
                          		style	= nset[node].Style;
                          		rec		= nset[node].Camera.split("yy");
                          		cam 	= [];		//eye,target,up
                          		for(a=0; a < 3; a += 1){
                          			cam.push(rec[a].slice(1,-1));
                          		}
                          		cam.push(rec[3])
                          		if(rec[3]){
                          			cam.push(rec[4]); 
                          		}
                          		data	= [name,dn.join(","),cm.join(","),style,cam]; 
                          		document.getElementById("trans").value = data.join("|");
                          		window.location = "skp;scene";
                          	}
                          }
                          
                          

                          Ruby callback

                          
                          @dlg.add_action_callback("scene") {|d, p|
                          		a = @dlg.get_element_value("trans")
                          		a = a.split("|")
                          		name	= a[0].split(",")
                          		lyrs	= a[1].split(",")
                          		cmps	= a[2].split(",")
                          		sty		= a[3].to_s
                          		cam		= a[4].split(",")
                          		model	= Sketchup.active_model
                          		entities	= model.entities
                          		entities.each do |entity|
                          			if  entity.class == Sketchup;;ComponentInstance || entity.class == Sketchup;;Group
                          				entity.visible = false
                          			end
                          		end
                          		cmps.each do |c|
                          			a = Integer(c)
                          			#p entities[a].name
                          			entities[a].visible = true
                          		end
                          		layers = model.layers
                          		layers.each do |layer|
                          		layer.visible = false 
                          		end	
                          		lyrs.each do |lyr|
                          			layers[lyr].visible = true;
                          			#p layers[lyr].name
                          		end	
                          		
                          		pages	= model.pages
                          		styles	= model.styles
                          		page	= pages["Nameset"]
                          		styles.selected_style= styles[sty]
                          		page.use_style = styles.selected_style
                          		eye		= Geom;;Point3d.new [Float(cam[0]).mm, Float(cam[1]).mm, Float(cam[2]).mm]
                          		target	= Geom;;Point3d.new [Float(cam[3]).mm, Float(cam[4]).mm, Float(cam[5]).mm]
                          		up	= Geom;;Vector3d.new [Float(cam[6]), Float(cam[7]), Float(cam[8])]
                          		camera = model.active_view.camera
                          		camera.set(eye,target,up)
                          		if cam[9] == "true"
                          			camera.perspective = true
                          		else
                          			camera.perspective = false
                          		end
                          		if camera.perspective?
                          			camera.fov = Float(cam[10])
                          		end
                          	}	
                          
                          
                          

                          It seems to work OK but I don't like the zoom extents (I'm working on that).

                          As they say in the gallery ... C&C welcome.

                          Edit 15 Feb: Changed code in callback to match post post revelations


                          Scene extraction and view generation

                          With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                          1 Reply Last reply Reply Quote 0
                          • chrisglasierC Offline
                            chrisglasier
                            last edited by

                            And here's the matrix returns for one component in the original and recreated view.
                            camera011.png

                            With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                            1 Reply Last reply Reply Quote 0
                            • 1
                            • 2
                            • 2 / 2
                            • First post
                              Last post
                            Buy SketchPlus
                            Buy SUbD
                            Buy WrapR
                            Buy eBook
                            Buy Modelur
                            Buy Vertex Tools
                            Buy SketchCuisine
                            Buy FormFonts

                            Advertisement