How do I make a flat shaded mesh? - libgdx

How would one create a flat shaded mesh in libgdx? Most examples of custom meshes(that I could find) are gouraud shaded. I would like my game to have a flat shaded style like the following:
So, how would I generate a flat shaded custom shape?

Related

How to change the color of non-transparent parts of a PNG file with Slider UI in Spark AR

In Spark AR Studio I've set a texture to a rectangle, which is a transparent PNG with some text on it. I've applied this texture to a rectangle and have put it in the scene. What I'm trying to achieve here is to use a native Slider UI element to change the non-transparent parts of this PNG which is the "Hello World" obviously.
The best related article I could find is from their own docs: Adding a Color Filter which does the steps below:
Imports the texture in patch editor
Pipes in the RGB output into a color space patch and converts the color space into HSL mode
Unpacks the HSL values
Modifies the values somehow
Packs them again, converts back the color mode into RGB and adds an alpha value.
And finally pipes in the output (modified color values) into the material texture which is controlled as a patch
Here's my setup which is not working, and makes the whole rectangle black instead of changing the non-transparent parts of the texture.
Any ideas on how to fix this? I know I haven't added the slider UI element to my patch editor yet, at this point I'm playing around with the values in Orange groups. If that works I'm gonna let an slider, control those values.
From what I'm trying to understand, you want to change the "Hello world" to different colors using the Slider UI?
Have the rectangle's material texture in the patch editor by selecting the arrow.
Drag and drop your "Hello World" texture into the patch editor
Import the Adjust colors shader from the AR Library
In your patch editor, right-click and search for "Slider UI" and insert (Only works for Instagram thus go to "project" on your toolbar --> "Edit missing properties" and uncheck "Facebook")
Connect your "Hello world" Texture RGBA output to the texture input in the Adjust Colors Shader
Connect your "Slider UI" output to the "Hue" input in the Adjust Colors Shader
Connect your Adjust Colors Shader Output to the material "Diffuse Texture"
Click to see how your patch editor should look like
Maybe it's just your preference but I would change the "Hello World" to black & white to make it more visible as I change the colors (I use Photoshop to desaturate but any editor that works is fine)

how to create shapes drawing a diagram

I'm new to draw.io and mgraphx. I know how to create a shape 'programmatically' in draw.io using 'extras/create shape'
I'm wondering if it is possible to drag some basic shape to a diagram, 'merge' them to a single shape, then add some connection point and finally drag the new shape to a library.
I tried grouping the basic shapes but a group is not a shape in itself (it cannot have connections points, and it cannot be connected to other shapes, only the contained shapes can).
Is there a way to create a new shape 'diagrammatically' from basic shapes?
if not, ther are some examples that show how to do the merge of basic shapes using the mxgraph library ?
thankyou

How to draw different shapes using pencil on group container and resize and rotate it in flex4?

All operations like moving,rotating,resizing drawn shape can be performed.I'm using as3 and flex4.6.
It seems like you have to use object handles library for moving,rotating, re sizing shapes ..
you can download this library from the below links.
https://github.com/marc-hughes/ObjectHandles
http://www.objecthandles.com/

Flex 4.5 , How to create generic skinning library and dynamically change the theme of my AIR application?

I'm working on enterprise level AIR application, i need to change my application UI for multiple clients,it has a complex UI with more that 250 MXML skin files for all display objects such as buttons, combo box, containers, etc., Is it possible to create a generic skin library for managing skins and assets through CSS or i have to create a separate library for each of the clients?
Currently i'm duplicating the skin files for each client and changing the color values (styles) in CSS (which is the default.css for skin library) and Path data in skins.
Is there any easy way to create a skinning themes in flex 4.5 and managing assets(icons, fxg) in library?
Thanks in advance
Create a custom theme
I suppose you already know this, but creating a custom theme is simply a matter of:
creating a custom skin for every component
creating defaults.css file to assign those skins and perhaps provide some additional styling information
making sure that css file is included in the swc
applying the theme with the --theme compiler flag (or through whatever means your IDE provides)
Applying different colour schemes
You can use chromeColor and some other predefined styles to address this issue, but this approach may prove limiting. I solved this by substituting the Spark skin base classes with my own more elaborate versions. There's too much code to paste here, but it comes down to this:
I created an interface like this:
public interface IColorizedSkin {
function colorizeBorder(color:uint, lowLight:uint, highLight:uint):void;
function colorizeBackground(color:uint, lowLight:uint, highLight:uint):void;
function colorizeShadow(color:uint):void;
}
and I implemented this interface in my custom versions of:
SparkSkin
SparkButtonSkin
ColorizedItemRenderer
These three functions are called from an overridden updateDisplayList and use custom CSS style names like chromeBorderColor (which is an array of colours that expresses the base colour, the lowligth colour and the highlight colour of the border of a component).
All skins that need colorizing extend these base classes.
The defaults.css in the theme library comes with a default colour scheme, but you can override it by adding another css file with different colorizing directives to the client application.
Note that since these custom style names were not added as metadata to the components, you will only be able to assign these colours through CSS or through ActionScript, not through MXML attributes.
Colorizing icons
If you have an icon set that uses sufficiently neutral colours (for instance all icons are dark grey, or perhaps a grey gradient), you can colorize these too.
The simplest approach which works for solid colors is something like this:
if (iconDisplay) {
var colorTrans:ColorTransform = new ColorTransform();
colorTrans.color = getStyle("color");
iconDisplay.transform.colorTransform = colorTrans;
}
If you need something more finegrained, you'll have to work with a transform matrix.
Using different icons
I wouldn't bake icons into the skins, because that would reduce flexibility. I tend to include icons in the library swc, so one can access them from there.
If you need different icon sets for different client applications, simply create a swc including only these assets (i.e. no compiled code) for each set. As long as the names and paths inside those swc's are the same, you should be able to substitute one for the other.

Away3d 4, creating a flat shaded material

I'm currently trying to create a "flat" shaded ColorMaterial inside of Away3d 4 to use as a mesh on a loaded .obj file.
This is a screenshot of what I'm trying to achieve. The flat shaded model is on the left.
I loaded the same .obj file I’m working with in Away into a program called MeshLab. MeshLab has two settings for Render Mode, flat or smooth.
The Flat render mode is on the left and smooth is on the right. When I load my .obj into Away3D the result looks exactly like MeshLab’s smooth render mode.
In order to get a flat result I’ve tried to set the smooth flag on my ColorMaterial to false but that doesn’t seem to change anything.
http://away3d.com/livedocs/away3d/4.0/away3d/materials/MaterialBase.html
I’m now starting to look into the materials shadowMethod because I was able to find a smooth boolean on ShadingMethodBase although I’m honestly not sure if this is where you would handle this.
http://away3d.com/livedocs/away3d/4.0/away3d/materials/DefaultMaterialBase.html#shadowMethod
http://away3d.com/livedocs/away3d/4.0/away3d/materials/methods/ShadingMethodBase.html
Below is the code for creating my light and light picker,
dL = new DirectionalLight();
dL.diffuse = 20;
dL.ambient=.6;
dL.specular=15
scene.addChild(dL);
lightPicker= new StaticLightPicker([dL]);
dL.direction = new Vector3D(0,1,-2);
And this is my material, I've tried playing around with most of it's properties:
primitiveMaterial = new ColorMaterial(0xcccccc);
primitiveMaterial.smooth = false;
primitiveMaterial.bothSides = false;
//primitiveMaterial.gloss = 800;
//primitiveMaterial.diffuseLightSources = LightSources.LIGHTS;
primitiveMaterial.diffuseMethod.alphaThreshold = .3;
primitiveMaterial.ambient =.2;
primitiveMaterial.lightPicker=lightPicker;
Can anyone help point me in the right direction?
Thanks!
ColorMaterial has no smooth attribute because it hasn't texture and smooth indicates whether or not any used textures should use smoothing. Most likely smooth attribute is inherited from MaterialBase and have no affect.
Your problem is in the normal vectors when surface is flat they are normals, when it is smoothed they are blended so it appears smoother.
Im guessing the problem might be in obj file. If it has no normals Away3d might generate them by it self ass well as MeshLab but Away3d apparently doing it only in smoothed mode by default. Or obj file contain smoothed normals and MeshLab overriding them in flat mode.
Open obj file with text editor and look for normals, try another obj file with flat surface.
But i might be wrong.
Here is smoothed obj
And this one is flat
What you are looking for is probably the Explode class.
Call Explode.apply(<your loaded mesh>) to remove the smoothed normals.