Brunex92 Posted December 8, 2016 Share Posted December 8, 2016 Hey! So, I've programming on javascript for not so long, and I'm trying to do this simple project where I get data from a matrix and draw in canvas, just like this playground: http://playground.babylonjs.com/#191SVM#0 Problem is... Everytime I call the function, it will always draw the center sphere, multiple times, which obviously is not what is intendend... Anyone can help me with that? Like using an exception everytime it tries to draw an object where it alredy is This looks really simple to do, but I have not idea how do I get the data from the object before I draw it Thanks Quote Link to comment Share on other sites More sharing options...
Nabroski Posted December 8, 2016 Share Posted December 8, 2016 http://playground.babylonjs.com/#1XHNOR#0 b=a is your friend http://playground.babylonjs.com/#YCVDD#23 http://playground.babylonjs.com/#DMLWQ#2 http://geniuscarrier.com/copy-object-in-javascript/http://blog.soulserv.net/understanding-object-cloning-in-javascript-part-ii/ Quote Link to comment Share on other sites More sharing options...
JohnK Posted December 8, 2016 Share Posted December 8, 2016 Not entirely sure what you are trying to achieve. Have given each row of the matrix a different colour and where y variables for matrix[\i][4] gave same positions changed them by radius of sphere. Hope that this might help. http://playground.babylonjs.com/#191SVM#1 Quote Link to comment Share on other sites More sharing options...
Brunex92 Posted December 8, 2016 Author Share Posted December 8, 2016 On 12/8/2016 at 12:41 PM, JohnK said: Not entirely sure what you are trying to achieve. Have given each row of the matrix a different colour and where y variables for matrix[4] gave same positions changed them by radius of sphere. Hope that this might help. http://playground.babylonjs.com/#191SVM#1 I actually need that these objects are linked through a center object, so changing its position won't work for me, the point is everytime I call the function to draw it, the center object will be rendered over and over again, until the loop is over, because that's how my code works. First I set its color, using the matrix[6], matrix[7], matrix[8], then I draw the the external sphere using the matrix[0],[1],[2], then the center one with the rest of it, linking both of the spheres. So what I want is once I draw the center one time, it won't be rendered again when the loop finds it again, only the external sphere Quote Link to comment Share on other sites More sharing options...
Nabroski Posted December 9, 2016 Share Posted December 9, 2016 @Brunex92 Can't see any sphere in the middle can you comment the problematic code out, so i can comment it in again and debug Quote Link to comment Share on other sites More sharing options...
Brunex92 Posted December 9, 2016 Author Share Posted December 9, 2016 On 12/9/2016 at 12:27 AM, Nabroski said: @Brunex92 Can't see any sphere in the middle can you comment the problematic code out, so i can comment it in again and debug Sure!http://playground.babylonjs.com/#191SVM#3 Lines 69-80 There you go, the center spheres in this playground are [10, 0, 10,] and [0, 0, 0] they are linked to external spheres. Imagine it as a cluster or a network, every PC is connected to a router, the router is the center sphere, the PCs are the external ones. Quote Link to comment Share on other sites More sharing options...
JohnK Posted December 9, 2016 Share Posted December 9, 2016 Ahhh now I understand in your scene there are two center sphere, one for the grey network and one for the black network, whereas I and, perhaps, Nabroski were wondering where this group of overlapping sphere were in your scene. An example like this may have helped http://playground.babylonjs.com/#191SVM#5 Unless you are firmly wedded to the data structure you have currently then maybe a different data structure would be better. Quote Link to comment Share on other sites More sharing options...
Brunex92 Posted December 9, 2016 Author Share Posted December 9, 2016 On 12/9/2016 at 12:34 PM, JohnK said: Ahhh now I understand in your scene there are two center sphere, one for the grey network and one for the black network, whereas I and, perhaps, Nabroski were wondering where this group of overlapping sphere were in your scene. An example like this may have helped http://playground.babylonjs.com/#191SVM#5 Unless you are firmly wedded to the data structure you have currently then maybe a different data structure would be better. Hmm, they're still there, on this PG you provided, there are 6 center spheres at the [0, 0, 0], and that is exactly what I dont want, there are 5 unnecessary objects Also, which data structure you think it would be better to use? Quote Link to comment Share on other sites More sharing options...
JohnK Posted December 9, 2016 Share Posted December 9, 2016 Sorry perhaps I wasn't clear, I did not say the playground solved your problem only that it was much clearer in showing what the problem is. Each cylinder has a central red mesh which is drawn for each cylinder. What is required is that the central red mesh is only drawn once. Cannot help with a new data structure now as my dinner is about to be served. I will have a look after dinner. In the meantiime perhaps someone else will have a look at the thread. Brunex92 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted December 9, 2016 Share Posted December 9, 2016 A change of data structure - centre only drawn once http://playground.babylonjs.com/#191SVM#6 Quote Link to comment Share on other sites More sharing options...
Nabroski Posted December 9, 2016 Share Posted December 9, 2016 if its possible to redefine your matrix you can stop in a for loop like thishttp://playground.babylonjs.com/#191SVM#7 http://www.w3schools.com/js/js_break.asp Quote Link to comment Share on other sites More sharing options...
Brunex92 Posted December 9, 2016 Author Share Posted December 9, 2016 On 12/9/2016 at 2:22 PM, JohnK said: A change of data structure - centre only drawn once http://playground.babylonjs.com/#191SVM#6 Hmmm, that will only work if I know the centers, my project is a little bit different, I load a text file with the matrix, read it and the draw it, so I don't know what are the centers. On 12/9/2016 at 3:55 PM, Nabroski said: if its possible to redefine your matrix you can stop in a for loop like thishttp://playground.babylonjs.com/#191SVM#7 http://www.w3schools.com/js/js_break.asp I can't as said above. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 10, 2016 Share Posted December 10, 2016 You can always find the center of a mesh with: mesh.getBoundingInfo().boundingSphere.centerWorld Quote Link to comment Share on other sites More sharing options...
Nabroski Posted December 10, 2016 Share Posted December 10, 2016 http://playground.babylonjs.com/#191SVM#9 Quote Link to comment Share on other sites More sharing options...
JohnK Posted December 10, 2016 Share Posted December 10, 2016 On 12/9/2016 at 5:30 PM, Brunex92 said: Hmmm, that will only work if I know the centers, my project is a little bit different, I load a text file with the matrix, read it and the draw it, so I don't know what are the centers. So keep the same incoming data structure, do a conversion into a data structure where the centres and colours are only stored once and then draw networks. http://playground.babylonjs.com/#191SVM#10 This time with a more random selection of nodes and centres. http://playground.babylonjs.com/#191SVM#11 Quote Link to comment Share on other sites More sharing options...
Brunex92 Posted December 12, 2016 Author Share Posted December 12, 2016 On 12/10/2016 at 3:54 AM, JohnK said: So keep the same incoming data structure, do a conversion into a data structure where the centres and colours are only stored once and then draw networks. http://playground.babylonjs.com/#191SVM#10 This time with a more random selection of nodes and centres. http://playground.babylonjs.com/#191SVM#11 http://playground.babylonjs.com/#191SVM#11 - That works perfectly! Thanks a lot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.