How to close / delete a Morph in Squeak? - user-interface

Let's say I have a new Morph:
m := Morph new.
m openInWorld.
How do I close / delete the Morph off?
m removeFromWorld.

To remove a morph from the world, use the delete method.
m := Morph new.
m openInWorld.
...
m delete.
delete removes the morph from its parent morph (which is the world after openInWorld).

Related

threejs, how to remove objects from octree?

In this example: https://threejs.org/examples/games_fps.html
This line adds an object to the octree: worldOctree.fromGraphNode( gltf.scene );
Let's say I spawn a player body, it gets fragged and I want to remove that object from the worldOctree, so that it doesn't participate in collisions anymore. How do I remove an object from the octree?

three.js Geometry.faceVertexUvs setup is confusing

I am working on implementing a custom model importer. The file contains all the necessary info (vertices, vertex normals, vertex uv coordinates, materials, etc.)
It's important to note that the file contains models with multiple materials.
The setup of the vertices is fairly straight forward and is working correctly.
The setup of the faces I'm not 100% sure about. I do the following:
meshDict[name].faces.push(
new THREE.Face3(parseInt(triangles[t]),
parseInt(triangles[t + 1]),
parseInt(triangles[t + 2]),
[normals[parseInt(triangles[t])],
normals[parseInt(triangles[t + 1])],
normals[parseInt(triangles[t + 2])]],
new THREE.Vector3(1, 1, 1), matIndex));
Here: t is the index iterator of the triangles array, normals is an array that holds the normal information of the vertices and matIndex is the material index of the face based on the sub-mesh number from the object file. This also seems to work correctly.
Now for the hard part. I searched all day for a clear explanation and/or good example of how to set-up the faceVertexUvs of a multi material mesh, but every second post I found shows a different method to set this up. After a lot of trial and error I got to this solution that works, but throws a LOT of warnings...
for (var f = 0; f < faces.length; f++)
{
if (currentMesh.faceVertexUvs[faces[f].materialIndex] == undefined)
{
currentMesh.faceVertexUvs[faces[f].materialIndex] = []
faceOffset = (faces[f].materialIndex == 0? 0 : 1) * f;
}
currentMesh.faceVertexUvs[faces[f].materialIndex].push(f);
currentMesh.faceVertexUvs[faces[f].materialIndex][f - faceOffset] = [];
currentMesh.faceVertexUvs[faces[f].materialIndex][f - faceOffset].push(uvs[faces[f].a]);
currentMesh.faceVertexUvs[faces[f].materialIndex][f - faceOffset].push(uvs[faces[f].b]);
currentMesh.faceVertexUvs[faces[f].materialIndex][f - faceOffset].push(uvs[faces[f].c]);
}
Here uvs is an array of Vector2 of the same length as the vertices array.
Basically I am doing:
faceVertexUvs[materialIndex][faceIndex][uvs[a], uvs[b], uvs[c]].
The number of material indexes is equal to the number of sub-meshes that the object has.
So this solution kinda works OK, but some of the textures are not looking correct (I suspect because the UV mapping of that area is not being set correctly), and I am getting a lot of warnings that say:
Important to note that all the models look OK in the exporting program so the issue is not from there.
Any ideas as to what I am doing wrong here?
So I think I finally managed to figure it out and I got it working correctly, and since the documentation is severely lacking in this area, and the examples are not quite clear I'll post my understanding of this topic here for anyone having the same issue.
So it goes like this:
Geometry.faveVertexUvs[UV LAYER][face index][uv[face.a], uv[face.b], uv[face.c]]
As far as I understand unless you have an AO (ambient occlusion) map, you only use UV LAYER 0.
Now, if you define a material index when setting up the faces of the geometry then each face will be rendered with the corresponding material, and there is no need to split the UVs into separate areas like I was doing in my question. So you only have to use:
Geometry.faces.push(new THREE.Face3(v0, v1, v2, [n0, n1, n2], vertexColor, materialIndex));

How to create multiple polygon into single geometry with three js

I have some countries polygon. I want to draw them on top of my sphere with three js, but when I'm trying to draw these polygons, fps drop down, at 3fps....
Someone told me to create juste ONE geometry and include all the polygons into it, did you have an example?
What I'm doing:
foreach countrie in countries
geometry = new THREE.shapeGeometry();
geometry.push(vectorArray);
var mesh = new Mesh(geometry);
globe.Add(mesh);
With over 250 countries, Three js just creates over 38k buffer. Strange behaviour, without any control, we shouldn't be able to create such buffers... so where am I wrong? I need help.
The three.js class THREE.GeometryUtils has a number of helpful methods for situations like these...
In particular, there is a merge method that will combine two Geometry objects into one. Assume that you have three geometry objects, country1, country2, country3. Then you could do something like:
temp = THREE.GeometryUtils.merge( country1, country2 );
allCountries = THREE.GeometryUtils.merge( temp, country3 );
Hope this helps!

XNA: Identifying identical sprites created with for loop

G'day all,
In short, I'm using a for loop to create a bunch of identical sprites that I want to bounce around the screen. The problem is how do I write a collision detection process for the sprites. I have used the process of placing rectangles around sprites and using the .intersects method for rectangles but in that case I created each sprite separately and could identify each one uniquely. Now I have a bunch of sprites but no apparent way to pick one from another.
In detail, if I create an object called Bouncer.cs and give it the movement instructions in it's update() method then create a bunch of sprites using this in Game.cs:
for (int i = 1; i < 5; ++i)
{
Vector2 position = new Vector2(i * 50, i * 50);
Vector2 direction = new Vector2(i * 10, i * 10);
Vector2 velocity = new Vector2(10);
Components.Add(new Bouncer(this, position, direction, velocity, i));
}
base.Initialize();
I can draw a rectangle around each one using:
foreach (Bouncer component1 in Components)
{
Bouncer thing = (Bouncer)component1;
Rectangle thingRectangle;
thingRectangle = new Rectangle((int)thing.position.X, (int)thing.position.Y, thing.sprite.Width, thing.sprite.Height);
But now, how do I check for a collision? I can hardly use:
if (thingRectangle.Intersects(thingRectangle))
I should point out I'm a teacher by trade and play with coding to keep my brain from turning to mush. Recently I have been working with Python and with Python I could just put all the sprites into a list:
sprites[];
Then I could simply refer to each as sprite[1] or sprite[2] or whatever its index in the list is. Does XNA have something like this?
Please let me know if any more code needs to be posted.
Thanks,
Andrew.
One solution, which I use in my game engine, is to have a Logic code run inside the objects for every game Update, ie. every frame. It seems you already do this, according to the variable names, which indicate you run some physics code in the objects to update their positions.
You might also want to create the collision rectangle inside the Bouncer's constructor so it's more accessible and you make good use of object oriented programming, maybe even make it an accessor, so you can make it update every time you call it instead of manually updating the bounding/collision box. For example:
public Rectangle #BoundingBox {
get { return new Rectangle(_Position.X, _Position.Y, width, height); }
}
Whichever way works, but the collision checks can be run inside the Bouncer object. You can either make the reference list of the Bouncer objects static or pass it to the objects itself. The code for collisions is very simply:
foreach(Bouncer bouncer in Components) //Components can be a static List or you can pass it on in the constructor of the Bouncer object
{
if (bouncer.BoundingBox.Intersects(this.BoundingBox))
{
//they collided
}
}

Sum up Area for material in Components, Google Sketchup

I am making a plugin to sum up the area of all the material in a Sketch.
I have succeeded in getting all the faces and such, but now the Components come into the picture.
Im using the term single or multi leveled component as i dont know any better way to explain the occurence of having a component inside an component and so on.
I have noticed that some components also have more to i than just 1 level. So if you go inside one component there may be components embedded inside this component that also have materials. So what i want is to sum up all of the material of a specific component and get all the "recursive" materials, if any, inside the component.
So, how do I count the area of all the material inside an component(single or multileveled)?
Here is what I would do, let's suppose that you loop through all entities and check for type of entity.
if entity.is_a? Sketchup::ComponentInstance
entity.definition.entities.each {|ent|
if ent.is_a? Sketchup::Face
#here do what you have to do to add area to your total
end
}
end
You can do the same with a Group with:
if entity.is_a? Sketchup::Group
entity.entities.each {|ent|
if ent.is_a? Sketchup::Face
#here do what you have to do to add area to your total
end
}
end
Hope it helps
Ladislav
Ladislav's example doesn't dig into all the levels.
For that you need a recursive method:
def sum_area( material, entities, tr = Geom::Transformation.new )
area = 0.0
for entity in entities
if entity.is_a?( Sketchup::Group )
area += sum_area( material, entity.entities, tr * entity.transformation )
elsif entity.is_a?( Sketchup::ComponentInstance )
area += sum_area( material, entity.definition.entities, tr * entity.transformation )
elsif entity.is_a?( Sketchup::Face ) && entity.material == material
# (!) The area returned is the unscaled area of the definition.
# Use the combined transformation to calculate the correct area.
# (Sorry, I don't remember from the top of my head how one does that.)
#
# (!) Also not that this only takes into account materials on the front
# of faces. You must decide if you want to take into account the back
# size as well.
area += entity.area
end
end
area
end

Resources