Search the Community

Showing results for tags 'canvas2d'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda.js
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 42 results

  1. Character width calculation is wrong for not mono-spaced fonts. Error is here (BMFontLoaderTxt._buildCharInfo): if (xadv) { width = xadv; } Character width is not always equal to xadv. Try to export Arial from BMFont and look to number characters (48-57) When rendering, wrong part of texture is taken for character. @Nockawa
  2. There are two questions about sprite2d behaviour, again I don't know whether it's bug or intended properties (fun club of @Nockawa keeps working) 1. Origin property of primitive. (That can be a bug) From documentation: Origin: define the origin of the primitive, default being 0.5,0.5, which is the center of the primitive, 0.0,0.0 would be the bottom/left corner of the primitive. The origin play a role in the rotation/scaling of the primitive but not in its positioning. Here is PG with exploration of that "not in its positioning" thing in the context of Sprite2D: http://babylonjs-playground.com/#1RJPAB As we can see, the right origin formula has to be written as "...but not in its positioning, if the primitive is not Sprite2d. In later case, you wouldn't guess the algorithm that derives actual sprite position from it's position and origin properties. 2. Size and width + height (That is a question of usability). Simple - you can set size property, but you can't set height and width properties on sprite2d. I belive that is the intended behaviour, because there are no height and width in sprite2d constructor settings, nor in renderablePrim2d or prim2dBase. But, 1. using all shape2d-based primitives and group2d you can set size or height/width, 2. on all primitives (including sprited2d) you can set position or x/y so, that is one of those nasty little things that you have to just remember.
  3. Sprite2D expects that underlying texture may not be loaded on sprite2d creation. It waits for texture to load, and everything is working fine. But the same problem can arise with Text2D, when using custom font, embedded into css/html. When Text2D object is created, it tries to create font texture, using supplied font parameter. But that font has to be loaded, and that is the process that takes time. So there is no font to use. In Firefox it leads to rendering Text2D objects without any text at all, soft page refresh fixes it. In Chrome one of the system fonts is used instead of required font. Soft page refresh doesn't not fix it, you have to recreate Text2D object. @Nockawa, is there any work around for this? UPD: One can use Bitmap font, that do know about loading time, and waits for underlying texture to load. But is that the only way to deal with the problem?
  4. Here is PG. http://babylonjs-playground.com/#QTNKM#1 When using designSize on canvas alignment properties are unusable. There are two different use cases: 1. I manually position primitive on some point. I expect it's position to be uniformly scaled from design size to real rendering size. That one is working. 2. I do not position primitive, but I set primitive alignment. Let it be marginHAlignment = BABYLON.PrimitiveAlignment.AlignRight. In that case I expect this primitive to be stuck on the right side of the rendered canvas. That case is not working. So, building real UI I have a problem. I can build UI panels using absolute positioning, and it will be OK, but how can I position those panels? Suppose I want one panel to be on left side of the canvas, and one on the right side - not so complex high level layout. Left one will be positioned fine, but with positioning right one I will have a problem. Big one. @Nockawa, is there any work around for this?
  5. There is a question on using Sprite2D primitive when sprite size is larger then texture size. The common usage scenario is filling some area with "pattern" texture. Logically, that behaviour can be achieved by setting wrapU and wrapV properties of underlying texture to Texture.WRAP_ADDRESSMODE. But Sprite2D doesn't support that usage scenario. In Sprite2D constructor: super(settings); this.texture = texture; this.texture.wrapU = Texture.CLAMP_ADDRESSMODE; this.texture.wrapV = Texture.CLAMP_ADDRESSMODE; so, Sprite2D overrides texture settings. That snippet will use CLAMP_ADDRESSMODE, ignoring texture settings. tx.wrapU = Texture.WRAP_ADDRESSMODE; tx.wrapV = Texture.WRAP_ADDRESSMODE; let sprite = new Sprite2D(tx, ...); But if you really want to have WRAP_ADDRESSMODE, you can do as following: let sprite = new Sprite2D(tx, ...); sprite.texture.wrapU = Texture.WRAP_ADDRESSMODE; sprite.texture.wrapV = Texture.WRAP_ADDRESSMODE; And the sprite will be filled with texture. The workaround is fairy simple, but I want to know the logic behind that solution - texture settings override in constructor. @Nockawa
  6. Hello good people of the babylon.js community! Update #14 from January 29th, 2017 Primitive Collision Manager (PCM, @ller request) The PCM is finally done! Well, first release, I've already spotted some not supported cases... Anyway, you can check a PG demonstrating the feature here: http://babylonjs-playground.com/#1PXWLR#2 (I've commented the PG for you to see how it works) Turned out that I didn't do what I wrote in the previous message, I didn't check for OOB and I've implemented a generic triangle set versus triangle set intersection algorithm right away. Basically all primitive types now create/update a Tri2DArray which contains a list of triangles describing the primitives surface. It needed to be that way because an Ellipse with a intersection of 8 is graphically not shaped like a perfect ellipse: there's not enough polygons, so I couldn't use a intersection algorithm involving a true/perfect ellipse, same goes for the Rectangle2D with round corners. So I decided to go for the most generic and accurate way. All primitive types are supported except the new WireFrame2D one. Through the PCM object you have a list of all primitives intersecting with the Canvas' border (if you activate the feature), it's useful. You also have a list of all the pair of two colliding primitives. From a given prim you have the intersectWithObservable and intersectWith properties to get notified of new/removed intersections and to access the full list of them. New Text Alignment (vertical and horizontal) and word wrapping features for Text2D (coded by @adam, I'm very thankful to him! It's good to feel less alone on this whole coding...) Basically now you can set a left/center/right text horizontal alignment and a top/center/bottom for the vertical one. If you specify a size for your Text2D primitive you can now have auto word-wrapping if the line exceed the horizontal limit. Maybe @adam could share a PG demonstrating the feature! New Primitive Type: WireFrame2D Well, I needed it to draw the debug World AABB and Cluster of the PCM, so I wrote it. The Primitive accept many WireFrameGroup2D, each one having a default color and contain a list of lines. Each stored vertex has its own color. Basically you create a WireFrameGroup2D instance then use its method to fill it with vertices. Note: it's Line List, not line strip: each line is defined by two own vertices. You can use an API to start, fill, end a LineStrip but internally it will double the vertices for everything between the first and last vertex. Right now this Primitive doesn't support any kind of intersection (point or prim-prim), I'll add an intersectionThreshold and implement the algo any time soon...It's not a priority right now... Misc things The BoundingInfo2D now support a WorldAABB with an efficient dirty/update, I obviously needed it for PCM Each Prim Instance has now a uid property which is a unique id (a GUID), I use it as a key to store the prim or prim related data into a StringDictionary, it's an efficient way to retrieve a given prim without going O(n). There's a Triangle versus Triangle intersection method in the Math2D.ts file, its implem is slow. If someone has the code for a Tri-Tri in 2D implemented using the Separating Axis Theorem (SAT) algo: I'm in ! Update #13 from January 24th, 2017 WorldSpaceCanvas TrackNode feature So I've developed the feature requested by @royibernthal to create WorldSpaceCanvas that track a 3D Scene Node with the optional feature for the WSC to always face the camera (billboard mode). You can find a demo in this playground. It was truly missing to the whole "WorlSpace Canvas interacting with 3D Scene" scenario. Other users requested more about this specific scenario and it perfectly makes sense: C2D was develop to provide 2D support for the 3D Scene, I've been focus on the "2D stuff" by itself a lot, because, well, it's already a big task, but yes there should be more things to come on this area, I'll try to dev feature requests on this matter with a higher priority. Update #12 from January 11th, 2017 Few announcements: We can now use BMFont to render text with Text2D PG here the documentation of the Text2D was update to explain the different techniques you can use to render text (normal, Super Sample, Signed Distance Field, BMFont) and which one you should use. (Thanks @MasterK for the idea and help) There's a new page about how the Rendering is working, it will help people to understand how to get transparent sprites, for instance. (this page is currently only accessible by the link I gave before, because I've messed up the link in the Canvas2D Homepage, yeah, that's my special ability, DK loves it) Some new Playgrounds are available at the bottom of the Home Page I was ill during the release of the 2.5, so I couldn't update the doc and the what's new, so I've updated the what's new of the documentation web site, go take a look if you want. As a separate module, Canvas2D has its own section in the What's New. Update #11 from January 5th, 2017 Long time that I didn't develop new features but here we go: AtlasPicture is now supported, see the documentation about it. Scale9Sprite is a new feature of Sprite2D class.The Sprite2D documentation was also updated. You can play with the following PG: Scale9Sprite AtlasPicture Of course you can use Scale9Sprite for a Sprite generated from an AtlasPicture. Update #10 from October 21th, 2016 allow3DEventsBelowCanvas Until now, pointerEvent occurring above a ScreenSpaceCanvas were also sent to the 3D Scene, many people (rightfully) complained about this so I decided to add the feature, which is called "allow3DEventsBelowCanvas" (which is false by default). The PR is here for more info https://github.com/BabylonJS/Babylon.js/pull/1448 (preview files updated and PG not updated so far). You have to realize that this is a change in behavior, now by default events won't be sent to the 3D Scene if they occurred above the Canvas, but I figured it made more sens this way. If you want them to be sent anyway, just set the setting to true! Update #9 from October 19th, 2016 Stabilization The latest weeks were spent on keeping stabilizing the Canvas2D feature, fixing bugs and adding feature only when necessary. Overall bug fixes were concerning Positioning Engine (alignment), StackPanel Layout Enigne, pointerEvent observable (leave/out now works better), some dispose issues solved, you're supposed to have no more opacity/transparency issues (well, let's say, "less"). One new feature One new feature was developed recently, during the creation of a ScreenSpaceCanvas you can now specify the renderingPhase setting, allowing you specify for which camera and which renderingGroup the Canvas is supposed to be rendered to. Simpler version: you can now interleaved 3D layers (which are renderingGroup) with 2D layers (which are ScreenSpaceCanvas). Many people requested it ( @MasterK, @HenryPeng, @stormwarestudios) to render 3D content above UI for FX (particles) or simply some 3D preview (like a 3D character preview in a UI). This playground is a very raw demonstration of the feature. Modularization Oh, by the way, I nearly forgot to tell something pretty important: we have recently extracted the Canvas2D feature (and the forthcoming GUI Lib first code lines) from the main babylon.js file. This is the first step of what is going to be a modularization of babylon.js, Canvas2D/GUI being obvious (and easy) candidates. What is changes for you? Well, not that much, if you use C2D/GUI you now have to use the "babylon.canvas2d.d.ts", "babylon.canvas2d.max.js", "babylon.canvas2d.js" that are sitting next to the "babylon.js/d.ts/max.js" files in the "dist" directory of your choice (right now only the "preview release" directory contains the Canvas2D related files, for obvious reason. The module's name is still "BABYLON", which will ensure you'll compile without changing anything. On a repository point of view, the source code was moved from /src/Canvas2D to /canvas2d/src/. Our lovely boss made the move and the Gulp config to compile everything the same way babylon.js does so you don't be lost. La surprise du chef! And the "chef" is not me, but another core member @Temechon spent some very valuable time (and I can't thank him enough for that!) to work on a feature I desperately need for so long but that I'm unable to code (well, in the time frame it will took me) which is called: c2dinspector.js. Basically the c2dInspector is a HTML Pane that is added on the right side of your HTML pane and that displays all the Canvas2D instances in your Scene (well, Engine to be more accurate) and their content as a tree of Primitives. You can select a given Primitive to see its details on the Detail Plane below, you can even change some values (still work in progress). In the tree, for each item there're two icons at the very left, an "eye" to show/hide the prim, and a "double frame" which is used to show/hide the debugDisplayArea (more on this below). This feature will help you (and me!) debug and understand better what's going on and why! It's not released yet, but a beta will be very soon (tonight or tomorrow), it's still Work in Progress, but hey, it's better than nothing and it won't harm you. The debugDisplayArea (the only thing I coded, bugs are to expect!): as you may know a primitive has four area: layout, margin, padding and content, this feature will display them with a given color code (layout being light red, margin is yellow, padding is magenta, content is cyan). This screenshot below is the same UI as above but with the debugDisplayArea on the "GUI Visual Placeholder of MainWindow", which has a margin of 50, 50, 50, 50 (the yellow area shows it) and padding of 100, 100, 100, 100 (the magenta area show it). The content in blue is the Windows' background, in light grey, which is here covered by the blue area. GUI Library I've started the GUI Library, it's going on very well, but I just can't work as much as I wanted on it the last couple of weeks, so there's delay: that's life. There's a separated thread about the GUI here so don't expect me to say more in this post, got watch the other thread if you care about it. That's all folk, enjoy, as usual: feedback are welcomed, you can do it in this thread of course! I just don't want this thread to be a "bug tracker" one, if you have issue, keep creating a new post and don't forget to mention me as I don't look at the forum everyday to see if someone needs help (but DK does, happy him...) Update #8 from August 31, 2016 I pushed a new commit today that address many things around using Scale on the Canvas object directly. I'm lazy so I copy/paste the PR description: You can now set a Scale (or ScaleX/Y) to a Canvas2D object, it will render as expected, for every caching strategies. At creation time of a ScreenSpaceCanvas you can set a designSize which will be used to compute the Canvas' scale automatically in order for you to specify absolute coordinate in the frame of the designSize (MasterK request) Any Cached Renderable Group can have a new GroupCache Behavior: GROUPCACHEBEHAVIOR_NORESIZEONSCALE. When set the cached bitmap for the Group won't be resized when the scale of the group will change, improving performances over rendering quality Ellipse, Rectangle are now drawn with a prescale computation to ensure the best result when using high/low scaling Prim2DBase has not the actualScale and actualScaleX/Y property that return the accumulated scale of the primitive. At their creation, primitives can specify if they should not inherit from the scale of their parent through the dontInheritParentScale setting. I don't know if many of you will get the GROUPCACHEBEHAVIOR_NORESIZEONSCALE and find a usage, but I thought it was the time or never to do it, so I did. And it works pretty well. I think for mobile gaming it may help to improve the perf by setting/keeping a fixed resolution of what's being rendered into a Cached Renderable Group2D. The designSize mode was made upon a request from @MasterK and it's really a good idea, I can see the use case from a game UI point of view and I hope it will work the way it should be, otherwise I'll do bug fixing! If there's no more urgent thing I'll go back on my working list and the next thing (that was already started but paused) is supporting the Device Pixel Ratio, which is another big thing for mobile gaming I think. I will be a breaking change for people who are right now "compensating the lack of this feature", but well, I'm sorry, there's nothing I can do about it except I wished I knew more about HTML few months ago! I know most of you are still trying to understand how things work with the Canvas2D and don't have time to try and use different Caching Strategies (and then rely on the DONTCACHE mode). Truth is the other modes were pretty bugged, they are less bugged now, but I'm not sure it's working the same. To solve this matter I'm revamping my whole "Unit Test" project, which was a local thing and not as powerful as it should be. There are so many different combination to test a given Use Case against: the different Caching Strategies, the support of the Instanced Array and with different Device Pixel Ratio values. I have to find time to put a good Unit Test framework and publish the whole stuff once it's done, because I think it will help all of you to discover the many things you can do and how. When this will be done then I think I'll start the true "why I did this": a GUI Library based on Canvas2D, with the UI Controls you all are waiting for. The foundation of Canvas2D is getting more and more stable so I think it will be soon the right time to start it and it will be the perfect chance to fix dozen of bugs, I'm sure of it! Update #7 from August 13th, 2016 @ Legoland, Billund, Denmark The latest fix is a long ongoing one noticed by @FlashyGoblin concerning transparency of Sprite2d. To make a long story short: I mixed up the implementation of AlphaTest and AlphaBlend (aka Transparency), the result were...well ugly...and you couldn't do things like the one FlashyGloblin ran against. So here are the new ground rules about this: I try to behave the same way the 3D Engine StandartMaterial does, so people familiar with it will catch things up pretty quickly. One noticeable difference is that useAlphaFromTexture is true by default. There are three render modes: Opaque, Alpha Test and Transparency (Alpha Blend). If you don't use Alpha in a Brush or a Texture and the Opacity is 1, the primitive is rendered in Opaque mode If you use Alpha in a Brush, if you set BaseTexture.hasAlpha to true in a Texture your primitive uses or if the Opacity is not 1, then it will be either Alpha Test if useAlphaFromTexture is false or Transparency if it's true. Beware: until now you didn't have to set hasAlpha for a Sprite2d to deal automatically with transparency, this is no longer the case! With the latest version your Sprite2d will be rendered as Opaque if BaseTexture.hasAlpha is set to false (which is the default value no matter what your bitmap stores). To sum up Text2d is set as a Transparent primitive to ensure a proper blending. Shape2d based primitives will be either opaque or transparent based on Opacity and Alpha in their Brushes. Sprite2d can use the three modes, the default behavior being Opaque if the texture has hasAlpha to false or Transparent if it's set to true and you can use useAlphaFromTexture to switch to Alpha Test. Update #6 from 15 June 2016: babylon.js 2.4 is out! I took the time to finish the overview/tutorial documentation. I also updated the playground and use the BABYLON. prefix everywhere it was needed (which mean I removed the alias like "var Scene = BABYLON.Scene") in order for you the user to copy/paste more easily. The documentation entry point is: http://doc.babylonjs.com/overviews/Canvas2D_Home (with all the playgrounds at the bottom of the page). The architecture/design doc is: http://doc.babylonjs.com/overviews/Canvas2D_Overview_Architecture Please, I've also created a PRO for the Canvas2D feature in Slant, for those who think it's a great addition to babylon.js, please follow this link and upvote, this work is on my spare time so fame is my only reward! thanks! http://www.slant.co/topics/3777/viewpoints/4/~open-source-javascript-3d-engines~babylon-js#15 Update #5 from 13 June 2016: new features added and also a lot of little bug fixes This version is supposed to be the "first official release", there were breaking changes with the previous ones, most notably: You don't use the public static CreateXXX method to create a primitive, you can now use the constructor, the parent is an optional parameter in the settings object (see sample below). At construction you can use a settings object that contains many many properties that you can set as you wish, some are somewhat overlapping (e.g. there's size, width and height, you set either the first or the two latest). This was designed to bring you some flexibility. You won't certainly notice, but the location of a primitive will always be relative to its bottom/left corner, regardless of the origin you set. This change was necessary to bring something coherent and understandable when alignment/layout comes into play. You have to use the actualPosition and actualSize properties to get the "real" values. position/size properties are the value before layout/positioning takes place. New features: This new creation mode allows you to cascade the creation of objects (see below). You'll see that Brushes can now be initialized with a string to make the code more simple. The same is true for margin/padding/alignment. You will find example in some playgrounds, doc will come asap. Lines2D now fully support intersection/picking, as well as roundedRectangle. The size of a primitive is now optional, if omitted it will be sized to its content bounding box. (the same behavior as Group2D) Margin, Padding, Alignment is introduced, you can play here. Margin/Padding support units in pixels or percentage, the value can be inherited from its parent or simply be automatic (0) A LayoutEngine feature now allows to position/size the primitive, by default it's the CanvasLayoutEngine that is assigned to all primitives, unchanging the behavior you already know. But I've made in few minutes a StackPanel Layout that you can test here (don't forget to CTRL-F5 your web browser to fetch the latest .js file) By the way, there's a new playground for Transparency testing. Update #4 from 03 June 2016: new features added and also a lot of little bug fixes intersection works better on Lines2D, I now support every Cap types, it's also accurate on rounded Rectangle (if you click on the empty zone create by the rounding corner it won't generated a hit). interaction mode can now be enable in WorldSpace Canvas, you can take a look at this PG for an example: http://babylonjs-playground.com/#1BKDEO#9 I've also added a alignToPixel property in Sprite2d to make sure the rendering of the sprite will be aligned to the render target device pixel, is ensure the best rendering quality, but in rare case of slow animation you would probably want to turn it off to ensure smooth animation. by default it's on. I won't detail it too much here because it need proper doc to be fully understood, but now you can give your own WorldSpaceNode to render a WorldSpace Canvas on something else that a simple Plane mesh. This mode is easy if you don't use Interaction, but if you do, you have to give a method that compute the world space intersection with your mesh and then compute the local position in the Canvas of the resulted intersection. This is not the simplest method to code but you have an example with the current implem for Plane World intersection to Canvas. Update #3 from 25 May 2016: new features added Breaking changes in the API: concerning the way to create Canvas and Primitives, now it's using the same signature than other object in babylons.js, with an options{} json object for optional parameters. There are default value each time it's possible. Including many bug fixes and little features improvements. We have two new primitives: Ellipse2D and Lines2D. I worked hard to dev a nice Lines2D primitive and I hope you will like it! A full Overview Documentation is now online, the main entry page is here: http://doc.babylonjs.com/overviews/Canvas2D_Home, from this page you'll be able to access to every others pages of the overview doc and also all the playgrounds I've made so far. The reference documentation is now online for the 2.4 you will find documentation for about 80% of the Classes/public methods. Update #2 from 19 May 2016: new features added Lots of little bug fixes, I hope everything will be ok with the origin property, nesting primitives, the text render is way much better now than before. Interaction is supported! There's an pointerEventObservable property in Prim2DBase for you to be notified about many things concerning interaction with a pointer (mouse, touch, pen). I've also added the support of the ActionManager, it's the same as Mesh and Sprite. I support all triggers exception Intersection and KeyUp/Down. Animation is supported too! You have the animations property in the base class of a Primitive for you to add animation the exact same way you would do for the scene objects. Update #1 from 16 May 2016: added link in the Documentation section to a new tutorial that explains how to write your own primitive types Original post I am very pleased to announce you a new feature I've been working on for weeks now! Well, to put things simply, Canvas2D is...a 100% WebGL 2D Engine! It may sound strange at first but I really thought it was missing to this lib, all started from the time I realized I couldn't efficiently display text in babylon.js. So I started to work on a new feature to do so and one thing led to another and I realized we could use of a real 2D Engine for many things! It's not related to the HTML Canvas Element at all, Canvas being a generic term (like Rectangle, for instance). I've called it Canvas2D because the main class controlling the feature is called Canvas2D and acts as its name suggest: you can draw 2D content inside. For performance reason the rendering is 100% WebGL your graphic card loves to do these kinds of things if you spend the right amount of time to create a good rendering engine. Developing such 2D Engine wasn't an easy task because I wanted to lay strong foundations to allow it grows decently through time. Future will tell if I did well or not! At last, for a better understanding this features serves the same purpose than Pixi.js, but the intent were slightly different: Pixi.js relies on two rendering engines (HTML Canvas or WebGL Canvas), but the Canvas2D relies only on WebGL, because it's made to be used along with a 3D Scene, which requires WebGL anyway. Primary focuses while designing the feature: fast, flexible and hopefully easy to contribute. Concerning the "fast" if your device support the WebGL Instanced Array extension, you should be really pleased with the result, the engine was designed to work with this extension (even though if it also works without). I think I overall did well although if there's still room for improvement. Basically, how does it work? You can create many Canvas2D instance on a given Scene, you have two kinds of Canvas: ScreenSpace: the canvas is displayed above the 3D Scene, in 2D space, like you would expect See this example. But there's another interesting mode: WorldSpace:the canvas is displayed in a 2D Rectangle as a part of the 3D Scene, you setup its position, rotation and scale, like a Mesh (well, it's in fact a Mesh of a Plane). See this example. When you want both Performance and Flexibility Things get a little technical! When you create a Canvas you have to choose a Caching Strategy. Why? Because depending on what you will do with it you may use different rendering strategies. CACHESTRATEGY_DONTCACHE: easy, nothing will be cached, all Group2D are called "logical" and the whole content is redrawn every render. If you have few things or if it always change, you may use this mode. It's also the most stable right now. CACHESTRATEGY_TOPLEVELGROUPS: my favorite! Only Group2D that are direct childs of the Canvas will be cached and considered as RenderableGroup, their children Group will be logical only. If you have some On Screen GUI to display at the different corners of your Viewport, this mode may be the best for you. CACHESTRATEGY_CANVAS: Well, the whole Canvas is put into a cache, you better avoid this if you create a Canvas with the size of the Viewport because a texture/depth buffer will be allocated with the size of the viewport. Note: this is actually the only mode that can be used with World Space Canvas. (the other at the exception of DONTCACHE will follow later). CACHESTRATEGY_ALLGROUPS: this is the most technical one, sound brute force at first, but its the opposite: the most complex one. Potentially every groups are Cached, but in reality for each Group you create you can set a CacheBehavior which states if: The Group follows the cache strategy (then be cached), It won't be cached (then rendered every time) or If it's cached in the nearest Cached group parent. This mode has been elaborate to allow the creation of GUI controls being part of a complex canvas with a lots of Depth and diversity. As for today, this is the least tested one, be indulgent. A canvas is made of Primitive: this is the base type, has many property like position, rotation (along the Z axis), scale (uniform), visibility, an origin, zBias (if you're not happy with the default behavior), and a list of children primitives. Group2D: to create a new reference of frame, but also if you wish to cache its content, to avoid redraw at every render. If you have primitives that are most of the time static (or changing sporadically, in response of an event for instance) it'll be well advised to cache them to speed up the canvas rendering. Renderable Primitive: as its name suggest, it's a base class for primitive that render to the canvas, so far: Text2D: to display text. Sprite2D: to display a sprite (a part of a texture if you will). Shape2D: another based class for a 2D Shape made of an optional Border and or Fill content. The Border and Fill Content are drawn using a specific type of Brush, for now SolidColorBrush2D and GradientBrush2D are supported. TileBrush2D (so based on a bitmap pattern) should make its way in the 2.5. So far only the Rectangle is implemented, but it does support roundRadius, which is nice. I think I can implement Ellipsis and Circle in no time, but well, I wanted to focus on the engine first. nPolygon, WireFrame should come later. Vectored based graphics (SVG support) should be a nice addition too. Documentation The tutorial can be found here. An overview of the feature architecture and capabilities can be found here. That's where you'll understand everything you can do and what you can expect in term of performance. A long tutorial to explain how to write your own primitive type can be found here. Few last things My mantra for this feature: by indulgent with the current state of the Canvas2D, but be fearless on the feedback side! I will try my best to fix things as much as possible, I've made already some testing, but nothing will replace the impartiality of the user! I also have some bugs already logged (like don't try to change the origin of a Text2D, the result will be rather funny...and unpleasant) and will fix them asap. Critical features are missing: Group2D and Text2d horiz/vert alignment, more shapes. As well as interaction support through an event system and a better support for animation. I will work on them right away. I don't make promise of what will be there for the 2.4 RTM but I expect everything except animation improvement, really hoping that interaction will make it (edit: also done). A big thanks to the core contributors of the lib for their help: @Deltakosh @RaananW @Temechon @jerome and @Sebavan! I'm waiting for your feedback!
  7. Hello. I am using babylonjs with npm for build my application. But npm distribution does not contains packages for canvas2d extension. It there some way to use canvas2d extension with npm? Thanks.
  8. I'm trying to understand how to work with group caching. Here is PG http://babylonjs-playground.com/#1VRAA#1 And I can't figure out the following - why setting canvas cachingStrategy to CACHESTRATEGY_ALLGROUPS leads to rendering of its' direct children only? So, every cached group have to be the direct child of canvas, or I'm missing something?
  9. If I look at https://www.npmjs.com/~babylonjs and inside the provided babylonjs-2.5.0 npm package, I observe that I have no way to access the Canvas2D project’s API. I think the babylonjs npm user should publish a Canvas2D package so that we can use it in webpack projects and I think this should be published by the official babylonjs npm user. Thanks!
  10. Here is PG: http://babylonjs-playground.com/#Y5PEE#3 case 1. I have primitive with default fill that is not null. When I try to change that fill (on click), everything is OK. case2. I have primitive with default fill that is null. When I try to change that fill (on click): case 2.1 if I use "BABYLON.Canvas2D.GetBrushFromString" to produce IBrush object nothing happens case 2.2 if I use "new BABYLON.SolidColorBrush2D" to produce IBrush object nothing happens, but second click will change the color. Is it a bug or designed feature? (@Nockawa)
  11. Th following code was working in previous release (preview), rendering text on two lines: new Text2D("AAA\nBBB", settings) In current release (announced at 29 Jan) it doesn't work. It produces following exception: Uncaught TypeError: Cannot read property 'offset' of undefined at Text2DInstanceData.descriptor.set [as transformX] (http://localhost:63342/FirstSample/lib/babylon.canvas2d.js:8687:66) at Text2D.RenderablePrim2D.updateInstanceDataPart (http://localhost:63342/FirstSample/lib/babylon.canvas2d.js:9337:29) Without new line symbol: new Text2D("AAABBB", settings) it still works
  12. @Nockawa Is there a way to create a mask in Canvas2D? Something like that: https://phaser.io/examples/v2/sprites/mask
  13. Hi guys. Pinging @Nockawa for this one. I've been working him hard, lately, and I want to thank him for all the recent help. Today I am thinking about borders. Well, I HAVE been thinking about borders for quite some time, but those borders were international borders. Now, about Canvas2D primitives borders. Currently, I think there are only a few ways to make a Canvas2D based border. 1. Rectangle2D 2. Shape2D 3. Sprite2D. Each CAN be used to place a border around a Text2D, or just about anything else. But none of these bordering methods... automatically size-to-fit their contents, right? Perhaps that is reserved for a layer above the currently-completed "base" of Canvas2D. At what point do we "assemble" the FitBorderedText2D and FitBorderedGroup2D? In fact, for maximum-easy bordered tracked-node labeling, I could use a FitBorderedTrackingText2d. It seems strange and clumsy to need Group2D for node tracking, Rectangle2D for text border, and then Text2D... just for a single label. Anyway, I saw mention-of allowing trackNode for WorldSpaceCanvas itself (future feature). That is allowing trackNode on a "higher level" than Group2D. (WSC2D is higher level than a Group2D child of it.) What are the chances of allowing trackNode on LOWER level things... such as Text2D or Rectangle2D? What are the chances of allowing border on Text2D and Group2D? You see, a FitBorderedTrackingText2d... would have a border and trackNode... without needing any help from Rectangle2D or Groupd2D. Potential lines-of-code savings across 10 years of Canvas2D usage - 2 million metric tonnes. Am I de-primitiving the primitives? (i.e. FitBorderedTrackingText2d is a "combo" of primitives, and therefore would be offered on the next layer - the GUI Lib currently under dev?) Perhaps part of a Canvas2D Tools thing... programmer assistance? Of course, programmers can do this "combining" themselves in a little makeLabel() function. But still, I'm curious if Noxxy has any plans for "SuperText2D" features like this. Thoughts, anyone? Thx.
  14. Hi, I have 4 sprite2D buttons in an array. They are the only visible sprites on a canvas, but not the only one (several with opacity 0). If I dispose of 3 among the 4 everything is fine. elements2D.levelButtons[0].dispose(); elements2D.levelButtons[1].dispose(); // elements2D.levelButtons[2].dispose(); elements2D.levelButtons[3].dispose(); But if I dispose of all of them webGL throws a warning on a couple of render() - i'd say around 100 engine.render(). During those render any call to add primitives is not taken into account, resulting in a slight delay. Then, without any reason the warnings stop and calls to render and modify sprite are taking into account and rendered. babylon.2.5.max.js:7685 WebGL: INVALID_OPERATION: drawElements: no buffer is bound to enabled attribute Engine.draw @ babylon.2.5.max.js:7685 Rectangle2DRenderCache.render @ babylon.2.5.canvas2d.max.js:8864 Group2D._renderTransparentData @ babylon.2.5.canvas2d.max.js:8415 Group2D._groupRender @ babylon.2.5.canvas2d.max.js:8287 Canvas2D._render @ babylon.2.5.canvas2d.max.js:13009 (anonymous) @ babylon.2.5.canvas2d.max.js:11954 Observable.notifyObservers @ babylon.2.5.max.js:3605 Scene.render @ babylon.2.5.max.js:18697 (anonymous) @ catch-the-wolf-mri.js:653 Engine._renderLoop @ babylon.2.5.max.js:7166 requestAnimationFrame (async) Tools.QueueNewFrame @ babylon.2.5.max.js:4878 Engine._renderLoop @ babylon.2.5.max.js:7173 requestAnimationFrame (async) Tools.QueueNewFrame @ babylon.2.5.max.js:4878 Engine._renderLoop @ babylon.2.5.max.js:7173 requestAnimationFrame (async) Tools.QueueNewFrame @ babylon.2.5.max.js:4878 Engine._renderLoop @ babylon.2.5.max.js:7173 requestAnimationFrame (async) Tools.QueueNewFrame @ babylon.2.5.max.js:4878 Engine._renderLoop @ babylon.2.5.max.js:7173 I have no idea where it is coming from. It is not due to the fact that they are in an array, if I add another unrelated button to the scene I can dispose of the four rect without warning. This is my function creating the button, but I am not sure it is coming from that, I sometime had the same behavior when using dispose() in other contexts. var addButton = function (stateManager = mandatory(), options = null) { return new Promise(function (resolve, reject) { if (typeof stateManager._parent.parentTaskObject === "undefined") { throw new Error("stateManager.addButton: stateManager._parent.parentTaskObject is undefined"); } var baseOptions = { id: "button" + stateManager.timeInMs, text: "text", x: 50, y: 50, width: 100, height: 50, fill: BABYLON.Canvas2D.GetSolidColorBrush(new BABYLON.Color4(0.8, 0.8, 0.8, 1)), clickEventData: null, fontName: "30pt Arial", baseOpacity: 0.8, hoverOpacity: 1 }; options = _.extend(baseOptions, options); var elements2D = stateManager.getGlobal("elements2D"); var canvas = elements2D.canvas; // create button and add to canvas var buttonRect = new BABYLON.Rectangle2D({ parent: canvas, id: options.id, x: options.x, y: options.y, width: options.width, height: options.height, fill: options.fill, roundRadius: 0, children: [ new BABYLON.Text2D(options.text, { fontName: options.fontName, marginVAlignment: "v: center", marginHAlignment: 3 }) ] }); buttonRect.opacity = options.baseOpacity; // Add an observable for hovering buttonRect.pointerEventObservable.add(function (d, s) { buttonRect.opacity = options.hoverOpacity; }, BABYLON.PrimitivePointerInfo.PointerOver); buttonRect.pointerEventObservable.add(function (d, s) { buttonRect.opacity = options.baseOpacity; }, BABYLON.PrimitivePointerInfo.PointerOut); // Add an observable for clicking if ((options.clickEventData !== null) && (options.clickEventData.constructor === EventData)) { buttonRect.pointerEventObservable.add(function (d, s) { options.clickEventData.happenedAt = stateManager.timeInMs; options.clickEventData.data.button = buttonRect; stateManager.addEvent(options.clickEventData); }, BABYLON.PrimitivePointerInfo.PointerUp); } resolve(buttonRect); }); }; Did that happen to someone else ? Any clue ? To circumvent the problem I create a 1*1 pixel button with opacity 0 at position 0,0 and that allows me to dispose() all the real buttons without error. Thanks !
  15. Hi everyone I'm wondering why font size and font rendering is so different when comparing `DynamicTexture` and `Canvas2D` side by side. http://www.babylonjs-playground.com/#TFFCW Note: The huge but blurred text is `8px` while the small and crisp text is `32px` Dynamic texture returns the expected result while text rendered in canvas 2d seems to be way too big and blurry. Of course I could use a bigger font size (ie. 8 times the size needed) and then scale it down (`scale: 0.125`). But I'd like to understand what's going on… Any hint much appreciated! Anyone?
  16. Edit: The solution to get Sprite2D with transparent areas working is to set "hasAlpha" on the Texture to "true". --- Hi, I want to use sprites2d (in canvas2d) made from png files that have transparent areas. expected behavior: Transparent areas are rendered transparent actual behavior: transparent areas are rendered not transparent It gets super weird, if I set opacity on the sprite to 0.999 everything works fine. Working, with opacity 0.999 http://www.babylonjs-playground.com/#DSJDT#11 no longer working with opacity 1.0 (or opacity removed): http://www.babylonjs-playground.com/#DSJDT#12 I will use the 0.99 opacity workaround for now., but this seems buggy - I would like my sprite to be rendered according to the alpha channel, and it's weird that this only seems to happen if I set opacity to 0.99. Maybe I missed another property?
  17. Hello, this is my first post here. Firstly I want to say thanks to this community, because almost everything I was trying to work with in babylon, was already really well explained here. I would like to ask a question about making a 2D UI on babylon. At first I saw the bGUI, which was deprecated in favor of Canvas2D... but I cannot make it work. Here is a link to a playground actually working http://babylonjs-playground.com/#FFTQL#5 I tried to get the zip and run the same code on my browser and unfortunately it doesn't work. As I tried to figure out what was wrong, I found this in browser console TypeError: BABYLON.ScreenSpaceCanvas2D is not a constructor I think that maybe there is something wrong with the babylon.js version I'm using, but I can't figure it out. Looked as well in the Canvas2D documentation and I (hopefully) didn't miss anything. Thanks for any help
  18. Hi everyone, When I let a Canvas2D primitive to scaling and rotating at the same time, the result of primitive performing is unexpected for me. Like the below code (http://babylonjs-playground.com/#OWCCR#27): let rectGreen = new BABYLON.Rectangle2D({ parent: canvas2d, id: "rectGreen", width: 100, height: 100, rotation: Math.PI * 1 / 4, marginAlignment: "h: center, v: center", fill: BABYLON.Canvas2D.GetSolidColorBrush(new BABYLON.Color4(0, 1, 0, 1)) }); let rectRed = new BABYLON.Rectangle2D({ parent: canvas2d, id: "rectRed", width: 200, height: 200, scale: 0.5, rotation: Math.PI * 1 / 4, marginAlignment: "h: center, v: center", fill: BABYLON.Canvas2D.GetSolidColorBrush(new BABYLON.Color4(1, 0, 0, 1)) }); I want rectRed to perform like rectGreen. What concept of computer graphics I am miss? Thanks.
  19. I have question regarding the tracking of nodes in a scene with canvas2d elements (using ScreenSpaceCanvas2D). It seems that when a node goes behind the camera, the 2d element will initially go out of view, but will eventually re-enter if you keep moving away from the node that it is attached to. An example playground below, which is a very slight modification of a playground from the documentation, demonstrates this. Just pan forward through the cubes (with ctrl + click), and the rectangle2ds initially go out a view, but then come back onto the screen. http://babylonjs-playground.com/#1N9RJY#61 Is this the desired behaviour?
  20. Hi all, I want to create a Sprite2D and it's image can make some effect like grayscale. So I consider using CustomProceduralTexture to implement it. My pseudo code is like below (the shader is just basic one not grayscale): let sampleTexture = new BABYLON.Texture("img/sample.png", scene, true, false, BABYLON.Texture.NEAREST_SAMPLINGMODE); BABYLON.Effect.ShadersStore["TestPixelShader"] = "precision highp float;\n" + "varying vec2 vUV;\n" + "uniform sampler2D sampleTexture;\n" + "void main(void) {\n" + "gl_FragColor = texture2D(sampleTexture, vUV);\n" + "}\n"; let procedualTexture = new BABYLON.CustomProceduralTexture("custom", "Test", 1024, scene); procedualTexture.setTexture("sampleTexture", sampleTexture); let sprite2d = new BABYLON.Sprite2D(procedualTexture, { options... }); Is my idea workable? Or do I need using another ways to implement it? Thanks!
  21. Hi folks, @Nockawa As well as making use of the fine Castor.js extension for html based UI, I am wanting to add some webgl UI elements using Canvas2d, specifically mesh labels. I have pretty much got to grips with the basics. However one thing I cannot get to work is changing the visibility of elements at run time. For example allowing the user to toggle labels on and off. I have created a silly demo based on the "labels" playground demo. The red sphere has a label. Hitting the 'Z' and 'X' keys moves the label along the viewport x-axis and this works fine. The ''L' key toggles the .isVisible property of the label but has no effect. Note that this property does work at 'create' time. If you change line 5 to default to 'false' then the label will not be displayed. However then hitting 'L' key does not display it. The key events write to the console log so it looks as though the events are triggering. http://www.babylonjs-playground.com/#1RB7WB#20 Am I doing something wrong or is the isVisible not re-read once created? Thanks Richard
  22. hey i seems to have a problem of the tracknode. so i used to example from this playground http://babylonjs-playground.com/#1N9RJY#5 and i used VRDeviceOrientationFreeCamera. however upon testing, the trackNode doesnt stay at the position of the mesh instead the position seems very off. any idea how to fix this?
  23. Hi I have spoken to @Nockawa already and he suggested I turn to the forums which I agreed with. When using a bundler such as Webpack, the developer imports the the BabylonJS library rather than including it in a script tag. The problem that arises is that Earcut has been defined in it's own namespace and is available only in the babylon.js file or globally when using script tags. However in Webpack each imported module is treated as an isolated scope and doesn't have access to other modules or global variables unless they have specifically been required/provided. Because Earcut is never exported and in it's own namespace it is literally unreachable for module bundlers: > babylon.js defines Earcut module > babylon.js defines and exports BABYLON module > Webpack provides the BABYLON module from babylon.js to all other libraries > babylon.canvas2d.js extends and exports BABYLON module x babylon.canvas2d.js uses BABYLON and Earcut (but Earcut is not provided nor in the same namespace) This leave 2 solutions as I see it: Add Earcut to the BABYLON namespace so that they get exported together and can both be provided by bundlers. Keep Earcut in it's own namespace and export it so that it can be imported by both babylon.js and babylon.canvas2d.js or provided using a bundler. Ping @Deltakosh, moving forward it might be worth looking into npm more. They offer the for example the option to add @next version tag for alphas/betas of packages. I am sure Babylon.JS would benefit from having more users testing/working with the preview build and finding issues. Kind Regards Swiftwork
  24. is it possible to ray pick a rectangle2d in a worldspacecanvas2D? any1 can enlighten me
  25. Nothing crazy, spend a little time on it, - it's art It crashes at some point, a remainder to take a break from coding. http://babylonjs-playground.com/#9L9HC#0