How do I clear the 'scene' in rust's kiss3d? The 2019 Stack Overflow Developer Survey Results Are InWhat is the overhead of Rust's Option type?What are the differences between Rust's `String` and `str`?How to use Rust's Peekable?What are Rust's exact auto-dereferencing rules?What is the motivation of Rust's ToLowercaseHow does Rust's struct hold and use a object?How to use multiple variables in Rust's for loop?Need holistic explanation about Rust's cell and reference counted typesWhy is Rust's assert_eq! implemented using a match?Is there a Rust function or module for iterating over all the removable drives attached to a Windows machine?

ODD NUMBER in Cognitive Linguistics of WILLIAM CROFT and D. ALAN CRUSE

"as much details as you can remember"

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

How did passengers keep warm on sail ships?

Correct punctuation for showing a character's confusion

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?

Why isn't the circumferential light around the M87 black hole's event horizon symmetric?

writing variables above the numbers in tikz picture

Why are there uneven bright areas in this photo of black hole?

Cooking pasta in a water boiler

Flight paths in orbit around Ceres?

Did any laptop computers have a built-in 5 1/4 inch floppy drive?

What do hard-Brexiteers want with respect to the Irish border?

What information about me do stores get via my credit card?

How come people say “Would of”?

Relationship between Gromov-Witten and Taubes' Gromov invariant

Does adding complexity mean a more secure cipher?

Keeping a retro style to sci-fi spaceships?

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

Straighten subgroup lattice

Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?

How can I add encounters in the Lost Mine of Phandelver campaign without giving PCs too much XP?

Slides for 30 min~1 hr Skype tenure track application interview

Why was M87 targeted for the Event Horizon Telescope instead of Sagittarius A*?



How do I clear the 'scene' in rust's kiss3d?



The 2019 Stack Overflow Developer Survey Results Are InWhat is the overhead of Rust's Option type?What are the differences between Rust's `String` and `str`?How to use Rust's Peekable?What are Rust's exact auto-dereferencing rules?What is the motivation of Rust's ToLowercaseHow does Rust's struct hold and use a object?How to use multiple variables in Rust's for loop?Need holistic explanation about Rust's cell and reference counted typesWhy is Rust's assert_eq! implemented using a match?Is there a Rust function or module for iterating over all the removable drives attached to a Windows machine?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















This a specific question about sebcrozet/kiss3d (a graphics package for games written in rust): how do I clear the 'scene'?



I can add objects to the scene by window.add_mesh() and similar methods, and it seems I can remove specific objects by windows.remove_node(), but how do I remove all the objects in a scene (e.g. to start a new scene)?



I suppose I could keep a vector of all the objects in the scene, and then iterate over the vector to remove the objects, but that should not be necessary.



Edit: here is some code that reproduces the error, excerpted from my code.



use kiss3d::resource::Mesh;
use kiss3d::window::Window;
use na::Point3;
use na::Vector3;
use rand::Rng;
use std::cell::RefCell;
use std::rc::Rc;
extern crate kiss3d;
extern crate nalgebra as na;
extern crate rand;
fn main()
let mut window = Window::new("Test");
const FRAMES_PER: u16 = 100;
let mut frame_count = FRAMES_PER;
let mut rng = rand::thread_rng();
window.set_point_size(5.0);
while window.render()
frame_count += 1;
if frame_count > FRAMES_PER
window
.scene_mut()
.apply_to_scene_nodes_mut(&mut











share|improve this question
























  • Can't you just do window.remove (window.scene())?

    – Jmb
    Mar 22 at 7:27











  • No, as I said in my reply to Akiner Alkan, I get cannot borrow 'window' as mutable more than once at a time.

    – Martin Ellison
    Mar 22 at 7:36


















1















This a specific question about sebcrozet/kiss3d (a graphics package for games written in rust): how do I clear the 'scene'?



I can add objects to the scene by window.add_mesh() and similar methods, and it seems I can remove specific objects by windows.remove_node(), but how do I remove all the objects in a scene (e.g. to start a new scene)?



I suppose I could keep a vector of all the objects in the scene, and then iterate over the vector to remove the objects, but that should not be necessary.



Edit: here is some code that reproduces the error, excerpted from my code.



use kiss3d::resource::Mesh;
use kiss3d::window::Window;
use na::Point3;
use na::Vector3;
use rand::Rng;
use std::cell::RefCell;
use std::rc::Rc;
extern crate kiss3d;
extern crate nalgebra as na;
extern crate rand;
fn main()
let mut window = Window::new("Test");
const FRAMES_PER: u16 = 100;
let mut frame_count = FRAMES_PER;
let mut rng = rand::thread_rng();
window.set_point_size(5.0);
while window.render()
frame_count += 1;
if frame_count > FRAMES_PER
window
.scene_mut()
.apply_to_scene_nodes_mut(&mut











share|improve this question
























  • Can't you just do window.remove (window.scene())?

    – Jmb
    Mar 22 at 7:27











  • No, as I said in my reply to Akiner Alkan, I get cannot borrow 'window' as mutable more than once at a time.

    – Martin Ellison
    Mar 22 at 7:36














1












1








1








This a specific question about sebcrozet/kiss3d (a graphics package for games written in rust): how do I clear the 'scene'?



I can add objects to the scene by window.add_mesh() and similar methods, and it seems I can remove specific objects by windows.remove_node(), but how do I remove all the objects in a scene (e.g. to start a new scene)?



I suppose I could keep a vector of all the objects in the scene, and then iterate over the vector to remove the objects, but that should not be necessary.



Edit: here is some code that reproduces the error, excerpted from my code.



use kiss3d::resource::Mesh;
use kiss3d::window::Window;
use na::Point3;
use na::Vector3;
use rand::Rng;
use std::cell::RefCell;
use std::rc::Rc;
extern crate kiss3d;
extern crate nalgebra as na;
extern crate rand;
fn main()
let mut window = Window::new("Test");
const FRAMES_PER: u16 = 100;
let mut frame_count = FRAMES_PER;
let mut rng = rand::thread_rng();
window.set_point_size(5.0);
while window.render()
frame_count += 1;
if frame_count > FRAMES_PER
window
.scene_mut()
.apply_to_scene_nodes_mut(&mut











share|improve this question
















This a specific question about sebcrozet/kiss3d (a graphics package for games written in rust): how do I clear the 'scene'?



I can add objects to the scene by window.add_mesh() and similar methods, and it seems I can remove specific objects by windows.remove_node(), but how do I remove all the objects in a scene (e.g. to start a new scene)?



I suppose I could keep a vector of all the objects in the scene, and then iterate over the vector to remove the objects, but that should not be necessary.



Edit: here is some code that reproduces the error, excerpted from my code.



use kiss3d::resource::Mesh;
use kiss3d::window::Window;
use na::Point3;
use na::Vector3;
use rand::Rng;
use std::cell::RefCell;
use std::rc::Rc;
extern crate kiss3d;
extern crate nalgebra as na;
extern crate rand;
fn main()
let mut window = Window::new("Test");
const FRAMES_PER: u16 = 100;
let mut frame_count = FRAMES_PER;
let mut rng = rand::thread_rng();
window.set_point_size(5.0);
while window.render()
frame_count += 1;
if frame_count > FRAMES_PER
window
.scene_mut()
.apply_to_scene_nodes_mut(&mut








rust






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 7:32







Martin Ellison

















asked Mar 22 at 4:44









Martin EllisonMartin Ellison

127213




127213












  • Can't you just do window.remove (window.scene())?

    – Jmb
    Mar 22 at 7:27











  • No, as I said in my reply to Akiner Alkan, I get cannot borrow 'window' as mutable more than once at a time.

    – Martin Ellison
    Mar 22 at 7:36


















  • Can't you just do window.remove (window.scene())?

    – Jmb
    Mar 22 at 7:27











  • No, as I said in my reply to Akiner Alkan, I get cannot borrow 'window' as mutable more than once at a time.

    – Martin Ellison
    Mar 22 at 7:36

















Can't you just do window.remove (window.scene())?

– Jmb
Mar 22 at 7:27





Can't you just do window.remove (window.scene())?

– Jmb
Mar 22 at 7:27













No, as I said in my reply to Akiner Alkan, I get cannot borrow 'window' as mutable more than once at a time.

– Martin Ellison
Mar 22 at 7:36






No, as I said in my reply to Akiner Alkan, I get cannot borrow 'window' as mutable more than once at a time.

– Martin Ellison
Mar 22 at 7:36













1 Answer
1






active

oldest

votes


















2














You can get a scene from a window with the Window::scene_mut function, which will return a SceneNode.



After you get your mutable scene node you can delete all the objects inside of the scene with the SceneNode::apply_to_scene_nodes function.



As documented in kiss3d docs page:




fn apply_to_scene_nodes_mut<F: FnMut(&mut SceneNode)>(&mut self, f: &mut F)



Applies a closure to each object contained by this node and its children.




This is the method that takes closure in it and applies it to the all nodes inside to scene. So you don't need to add all the objects to a Vec.



Note that this method is working recursively to apply the function you provided to all the childrens of the parent and itself.



In your case it is only needed to unlink the parent scene like following:



window.scene_mut().unlink();


Whenever you unlink the parent scene node, then the children will be unlinked with the parent of course. So in your needs you may not need to
SceneNode::apply_to_scene_nodes even.



Playground






share|improve this answer

























  • Thanks for the reply, but I have coded window.scene_mut().apply_to_scene_nodes_mut(&mut |n| n.unlink()); but that crashes with 'already borrowed: BorrowMutError'. If I use window.remove_node(n) the compiler says cannot borrow 'window' as mutable more than once at a time.

    – Martin Ellison
    Mar 22 at 5:38







  • 1





    Could you please share the work that you have tried so maybe we can identify that problem.

    – Akiner Alkan
    Mar 22 at 6:07











  • I've added some code to the question that shows the behaviour.

    – Martin Ellison
    Mar 22 at 7:33






  • 1





    @MartinEllison Updated your code and my answer. This way, the problem seems solved :) Good luck

    – Akiner Alkan
    Mar 22 at 11:03











  • Sorry, I've run the code in your playground link, and it does not delete anything. It should be displaying only one triangle at any time, but just keeps adding new triangles and not deleting any. I am at kiss3d = "0.18.0", if that is relevant.

    – Martin Ellison
    Mar 24 at 9:44











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293051%2fhow-do-i-clear-the-scene-in-rusts-kiss3d%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can get a scene from a window with the Window::scene_mut function, which will return a SceneNode.



After you get your mutable scene node you can delete all the objects inside of the scene with the SceneNode::apply_to_scene_nodes function.



As documented in kiss3d docs page:




fn apply_to_scene_nodes_mut<F: FnMut(&mut SceneNode)>(&mut self, f: &mut F)



Applies a closure to each object contained by this node and its children.




This is the method that takes closure in it and applies it to the all nodes inside to scene. So you don't need to add all the objects to a Vec.



Note that this method is working recursively to apply the function you provided to all the childrens of the parent and itself.



In your case it is only needed to unlink the parent scene like following:



window.scene_mut().unlink();


Whenever you unlink the parent scene node, then the children will be unlinked with the parent of course. So in your needs you may not need to
SceneNode::apply_to_scene_nodes even.



Playground






share|improve this answer

























  • Thanks for the reply, but I have coded window.scene_mut().apply_to_scene_nodes_mut(&mut |n| n.unlink()); but that crashes with 'already borrowed: BorrowMutError'. If I use window.remove_node(n) the compiler says cannot borrow 'window' as mutable more than once at a time.

    – Martin Ellison
    Mar 22 at 5:38







  • 1





    Could you please share the work that you have tried so maybe we can identify that problem.

    – Akiner Alkan
    Mar 22 at 6:07











  • I've added some code to the question that shows the behaviour.

    – Martin Ellison
    Mar 22 at 7:33






  • 1





    @MartinEllison Updated your code and my answer. This way, the problem seems solved :) Good luck

    – Akiner Alkan
    Mar 22 at 11:03











  • Sorry, I've run the code in your playground link, and it does not delete anything. It should be displaying only one triangle at any time, but just keeps adding new triangles and not deleting any. I am at kiss3d = "0.18.0", if that is relevant.

    – Martin Ellison
    Mar 24 at 9:44















2














You can get a scene from a window with the Window::scene_mut function, which will return a SceneNode.



After you get your mutable scene node you can delete all the objects inside of the scene with the SceneNode::apply_to_scene_nodes function.



As documented in kiss3d docs page:




fn apply_to_scene_nodes_mut<F: FnMut(&mut SceneNode)>(&mut self, f: &mut F)



Applies a closure to each object contained by this node and its children.




This is the method that takes closure in it and applies it to the all nodes inside to scene. So you don't need to add all the objects to a Vec.



Note that this method is working recursively to apply the function you provided to all the childrens of the parent and itself.



In your case it is only needed to unlink the parent scene like following:



window.scene_mut().unlink();


Whenever you unlink the parent scene node, then the children will be unlinked with the parent of course. So in your needs you may not need to
SceneNode::apply_to_scene_nodes even.



Playground






share|improve this answer

























  • Thanks for the reply, but I have coded window.scene_mut().apply_to_scene_nodes_mut(&mut |n| n.unlink()); but that crashes with 'already borrowed: BorrowMutError'. If I use window.remove_node(n) the compiler says cannot borrow 'window' as mutable more than once at a time.

    – Martin Ellison
    Mar 22 at 5:38







  • 1





    Could you please share the work that you have tried so maybe we can identify that problem.

    – Akiner Alkan
    Mar 22 at 6:07











  • I've added some code to the question that shows the behaviour.

    – Martin Ellison
    Mar 22 at 7:33






  • 1





    @MartinEllison Updated your code and my answer. This way, the problem seems solved :) Good luck

    – Akiner Alkan
    Mar 22 at 11:03











  • Sorry, I've run the code in your playground link, and it does not delete anything. It should be displaying only one triangle at any time, but just keeps adding new triangles and not deleting any. I am at kiss3d = "0.18.0", if that is relevant.

    – Martin Ellison
    Mar 24 at 9:44













2












2








2







You can get a scene from a window with the Window::scene_mut function, which will return a SceneNode.



After you get your mutable scene node you can delete all the objects inside of the scene with the SceneNode::apply_to_scene_nodes function.



As documented in kiss3d docs page:




fn apply_to_scene_nodes_mut<F: FnMut(&mut SceneNode)>(&mut self, f: &mut F)



Applies a closure to each object contained by this node and its children.




This is the method that takes closure in it and applies it to the all nodes inside to scene. So you don't need to add all the objects to a Vec.



Note that this method is working recursively to apply the function you provided to all the childrens of the parent and itself.



In your case it is only needed to unlink the parent scene like following:



window.scene_mut().unlink();


Whenever you unlink the parent scene node, then the children will be unlinked with the parent of course. So in your needs you may not need to
SceneNode::apply_to_scene_nodes even.



Playground






share|improve this answer















You can get a scene from a window with the Window::scene_mut function, which will return a SceneNode.



After you get your mutable scene node you can delete all the objects inside of the scene with the SceneNode::apply_to_scene_nodes function.



As documented in kiss3d docs page:




fn apply_to_scene_nodes_mut<F: FnMut(&mut SceneNode)>(&mut self, f: &mut F)



Applies a closure to each object contained by this node and its children.




This is the method that takes closure in it and applies it to the all nodes inside to scene. So you don't need to add all the objects to a Vec.



Note that this method is working recursively to apply the function you provided to all the childrens of the parent and itself.



In your case it is only needed to unlink the parent scene like following:



window.scene_mut().unlink();


Whenever you unlink the parent scene node, then the children will be unlinked with the parent of course. So in your needs you may not need to
SceneNode::apply_to_scene_nodes even.



Playground







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 22 at 11:02

























answered Mar 22 at 5:00









Akiner AlkanAkiner Alkan

1,707426




1,707426












  • Thanks for the reply, but I have coded window.scene_mut().apply_to_scene_nodes_mut(&mut |n| n.unlink()); but that crashes with 'already borrowed: BorrowMutError'. If I use window.remove_node(n) the compiler says cannot borrow 'window' as mutable more than once at a time.

    – Martin Ellison
    Mar 22 at 5:38







  • 1





    Could you please share the work that you have tried so maybe we can identify that problem.

    – Akiner Alkan
    Mar 22 at 6:07











  • I've added some code to the question that shows the behaviour.

    – Martin Ellison
    Mar 22 at 7:33






  • 1





    @MartinEllison Updated your code and my answer. This way, the problem seems solved :) Good luck

    – Akiner Alkan
    Mar 22 at 11:03











  • Sorry, I've run the code in your playground link, and it does not delete anything. It should be displaying only one triangle at any time, but just keeps adding new triangles and not deleting any. I am at kiss3d = "0.18.0", if that is relevant.

    – Martin Ellison
    Mar 24 at 9:44

















  • Thanks for the reply, but I have coded window.scene_mut().apply_to_scene_nodes_mut(&mut |n| n.unlink()); but that crashes with 'already borrowed: BorrowMutError'. If I use window.remove_node(n) the compiler says cannot borrow 'window' as mutable more than once at a time.

    – Martin Ellison
    Mar 22 at 5:38







  • 1





    Could you please share the work that you have tried so maybe we can identify that problem.

    – Akiner Alkan
    Mar 22 at 6:07











  • I've added some code to the question that shows the behaviour.

    – Martin Ellison
    Mar 22 at 7:33






  • 1





    @MartinEllison Updated your code and my answer. This way, the problem seems solved :) Good luck

    – Akiner Alkan
    Mar 22 at 11:03











  • Sorry, I've run the code in your playground link, and it does not delete anything. It should be displaying only one triangle at any time, but just keeps adding new triangles and not deleting any. I am at kiss3d = "0.18.0", if that is relevant.

    – Martin Ellison
    Mar 24 at 9:44
















Thanks for the reply, but I have coded window.scene_mut().apply_to_scene_nodes_mut(&mut |n| n.unlink()); but that crashes with 'already borrowed: BorrowMutError'. If I use window.remove_node(n) the compiler says cannot borrow 'window' as mutable more than once at a time.

– Martin Ellison
Mar 22 at 5:38






Thanks for the reply, but I have coded window.scene_mut().apply_to_scene_nodes_mut(&mut |n| n.unlink()); but that crashes with 'already borrowed: BorrowMutError'. If I use window.remove_node(n) the compiler says cannot borrow 'window' as mutable more than once at a time.

– Martin Ellison
Mar 22 at 5:38





1




1





Could you please share the work that you have tried so maybe we can identify that problem.

– Akiner Alkan
Mar 22 at 6:07





Could you please share the work that you have tried so maybe we can identify that problem.

– Akiner Alkan
Mar 22 at 6:07













I've added some code to the question that shows the behaviour.

– Martin Ellison
Mar 22 at 7:33





I've added some code to the question that shows the behaviour.

– Martin Ellison
Mar 22 at 7:33




1




1





@MartinEllison Updated your code and my answer. This way, the problem seems solved :) Good luck

– Akiner Alkan
Mar 22 at 11:03





@MartinEllison Updated your code and my answer. This way, the problem seems solved :) Good luck

– Akiner Alkan
Mar 22 at 11:03













Sorry, I've run the code in your playground link, and it does not delete anything. It should be displaying only one triangle at any time, but just keeps adding new triangles and not deleting any. I am at kiss3d = "0.18.0", if that is relevant.

– Martin Ellison
Mar 24 at 9:44





Sorry, I've run the code in your playground link, and it does not delete anything. It should be displaying only one triangle at any time, but just keeps adding new triangles and not deleting any. I am at kiss3d = "0.18.0", if that is relevant.

– Martin Ellison
Mar 24 at 9:44



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293051%2fhow-do-i-clear-the-scene-in-rusts-kiss3d%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현