There exists legacy application having 3 canvas. First canvas to display objects which is stored in container, second canvas when object is selected and third one when object is moved or added for editing. I want to use the text and image feature of fabricJS into my existing application. While creating fabricJS canvas, i provided editing canvas object then all the mouse events bind to the editing canvas stopped working. So does there exists way to use fabricJS into existing application only for using the text and image feature of fabricJS.
You should be able to dynamically assign a z-index value to a canvas layer to expose or hide the layer to mouse events.
For the layers that you want to hide mouse events from, set z-index value to -1. For the layer that you want to expose to mouse events, set z-index value to 1.
var textLayer = document.getElementById("text-layer");
textLayer.style["z-index"] = 1;
I have .obj file of truck where I want to assign a texture to tyres.
I am doing this in blender:
select the vertices/faces of tyres
split it into different object (using P)
assign a texture file to the new object
combine the new object back to the main object using Ctrl+J
The problem is the texture file is not preserved and the whole model is assigned one of the texture files.
How can I assign the texture to just tyres?
Make a new separate material and select the vertices of the tire,
then click 'Assign' to assign that new material to the selected vertices.
See image here
I'm currently creating a map in Openlayers for a customer that requires validation for drawing polygons inside another polygon (base-area). By using JSTS and Openlayers native methods, i'm able to validate that all shapes are drawn inside the polygon, and do not intersect with other shapes inside the polygon. This includes markers and polygons.
Another requirement is to check if the base-area is completely filled by other polygons, with pre-defined margins. I've not been able to think of any way to do this yet. What would be a good way to accomplish this?
EDIT:
Methods i used to check if polygon contains other polygon:
const geoJSONFormat = new GeoJSON();
const jstsGeoJSONReader = new jsts.io.GeoJSONReader();`
polygon1 = jstsGeoJSONReader.read(geoJSONFormat.writeFeatureObject(feature1)).geometry;
polygon2 = jstsGeoJSONReader.read(geoJSONFormat.writeFeatureObject(feature2)).geometry;
polygon1ContainsPolygon2= polygon1.contains(polygon2); `
First i pass the given feature the geoJSONFormat.writeFeatureObject which is imported from OL. And then assign this to a variable using the JSTS GeoJSON-reader.
contains-method from JSTS will return a boolean indicating if polygon2 is contained inside polygon1
Since you've already validated the polygons are inside the base-area and that they aren't overlapping. To check the base-area is completely filled, just check the sum of the area of the polygons is equal to the base-area.
I'm not entirely sure what you mean by margin but you could check the sum of the area of the polygons is at least some x% of the area of the base-area to give some "wiggle" room.
I just started out with Phaser.
I have a simple sprite in the middle of the screen, and whenever I click the sprite, I emit a particle at the clicked x,y coordinates.
My problem is that the particles are generated behind the sprite. I have tried setting z on the sprite to 1 and the emitter to 1000 without luck.
What am I missing?
var emitter = game.add.emitter(game.world.centerX, game.world.centeryY);
emitter.makeParticles('phaser');
var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser');
sprite.scale.setTo(2, 2);
sprite.inputEnabled = true;
sprite.events.onInputDown.add(function(sender, pointer){
emitter.emitX = pointer.x;
emitter.emitY = pointer.y;
emitter.emitParticle();
}, this);
http://phaser.io/sandbox/cxBVeHrx
EDIT
My actual code is based on the Phaser-ES6-Boilerplate. Even though BdRs answer solves the issue in the sandbox code, I'm not able to utilize this in my real code.
I have uploaded both the code and a running example. Hopefully someone can tell me where I have screwed things up...
Separate Phaser items don't have a z-order, instead it just depends on the order you create and add them to game. Each new sprite or emitter or group etc. will be displayed on top of all previously added items.
So, simply changing your code to something like this should work.
// first the sprite
var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser');
sprite.scale.setTo(2, 2);
// then the particles in front of sprite
var emitter = game.add.emitter(game.world.centerX, game.world.centeryY);
emitter.makeParticles('phaser');
// then maybe text in front of particles and sprite
var mytest = game.add.bitmapText(10, 20, 'myfont', 'Level 1', 16);
// etc.
Btw sprites do have a .z value but that only used when it's part of a Phaser.Group, it will then be used as the display z-order but only within that group of sprites.
By default, phaser will not sort objects that get added to any group, it will just render them in the order that they get added. In your case, you can just add the emitter to the group after you add the sprite (the group in this case is the 'game' object).
Of course, having to add objects in the drawing order is not ideal, and if you need to have them sorted dynamically, not possible.
Another way is you can sort objects within a group using the 'sort' function, in which you give it the name of a parameter to sort by, and you sort whenever you need to (in some cases, in the Update callback).
Sorting every frame can be a performance hit though, especially if you have a lot of objects. Another way you could go about this is by adding groups, sorting those groups in draw order (think of them like layers), and then adding objects to those groups in any order. Any group that needs sorting within itself you can sort as well. This way, you can choose to have (for example) a background layer not needing to be sorted but everything added to that layer will be behind every other layer.
Good answers from everybody, but you are missing that every GameObject has a depth property which serves exactly the z-index purpose. This way you do not need to rely on the order of objects creation.
There is also an official
example.
Hope this helps.
Anyone know how Apple does the transition to the store in the iBooks app? I know they are using a Modal View Controller with the UIModalTransitionStyleFlipHorizontal transition style set but I don't see how they are showing the "depth" of the "bookcase" when they do the transition.
I'm supposing that the animation works something like this:
A 'snapshot' image is taken of the
bookshelf and set to the contents of
a CALayer.
The bookshelf view is
removed from its superview.
The newly created CALayer (the bookshelf
layer) with the image of the
bookshelf is added to the layer of
some existing (or newly created)
UIView
Another layer (the side
layer) is created and an image of
the side of the bookshelf is used as
its contents. This layer is added
to the UIView The side layer is
positioned at the right edge of the
bookshelf layer.
The side layer's
transform is set to rotate it M_PI_2
rads about the y-axis. This
essentially makes it invisible as it
is perpendicular to the device
screen
The bookshelf and side layers
have an animation added to them that
transforms each with an M_PI_2
rotation about the y axis. At the
conclusion of this animation, the
bookshelf will be perpendicular to
the device screen and the side layer
will be fully in view.
A new layer (the store layer) is created and a snapshot image of the store is added as the contents of the new layer, it is transformed and positioned so that it will appear correctly when . . .
The side layer and store layer have an animation added that transforms each with an M_PI_2 rotation about the y axis.
All of the layers are removed and the store UIView is displayed.
I don't have any inside knowledge of the iBooks app, but if I were trying to duplicate this effect, this is how I'd go about it. FWIW, once you get the hang of positioning and transforming the CALayers, its kinda fun to mess around with animations like this.