Following commands apply both to newly created surfaces (with use of API) and surfaces created within Esquimo editor. Both are the same structure and can be accessed by surfaceId which is an positive integer value. IDs of surfaces created within editor are listed as a group of constants an published from editor as a class file. This way you can access them using friendly names with usage of autocomplete facility in code editors such as FlashDevelop. You just need to import the class in you project. In samples of use presented below this is Esq_scene_el.as class file.
Surface management
var mySurf1_ID:uint = m_esquimo.CreateSurface();
The highest possible ID is returned.
var sphere_1:uint = m_esquimo.GeometryCreateSphere(Esq_scene_el.SURFACE_1, 2, 20, 1); var mySurf1_ID:uint = m_esquimo.CreateSurface(); m_esquimo.SetGeometrySurfaceID(sphere_1, mySurf1_ID); trace(m_esquimo.RemoveSurface(mySurf1_ID) ? "Surface removed" : "Removing failed"); // -> "Removing failed" // The surface wasn't removed because there is still a reference to it - // - mySurf1_ID was applied to sphere_1 which still exists. m_esquimo.RemoveGeometry(sphere_1); // let's try remove the surface now: m_esquimo.SetGeometrySurfaceID(sphere_1, mySurf1_ID); trace(m_esquimo.RemoveSurface(mySurf1_ID) ? "Surface removed" : "Removing failed"); // -> "Surface removed" - the operation successed because there are no references to removing surface
The surface can be only removed when any other geometry object references to it. Otherwise surface will not be removed and the calling RemoveSurface method will return false value.
var mySurfaceSet:Array = new Array(10); var newSurfaceID:uint, randomColor :uint; for (var i:uint = 0; i < mySurfaceSet.length; i++) { newSurfaceID = mySurfaceSet[i] = m_esquimo.SurfaceCopy(Esq_scene_el.SURFACE_1); randomColor = Math.random() * 0xffffff; m_esquimo.SetSurfaceFillShaderColor(newSurfaceID, randomColor); }
The above example creates an array of 10 surfaces. Each of them is a copy of SURFACE_1 with randomly picked color. SURFACE_1 is a const defined within Esq_scene_el.as file which contains all surfaces created in Esquimo editor. Of course you can duplicate surfaces created from a scratch with use of CreateSurface command as well.
private var sphere_1:uint; private var sphere_2:uint; (...) sphere_1 = m_esquimo.GeometryCreateSphere(Esq_scene_el.SURFACE_1, 2, 50, 1); sphere_2 = m_esquimo.GeometryCreateSphere(Esq_scene_el.SURFACE_1, 2, 50, 1); m_esquimo.SetGeometryPosition(sphere_2, 1, 0 , 0); m_esquimo.addEventListener(NEsquimo3D.MOUSE_OVER, m_esquimo_mouseOver); m_esquimo.addEventListener(NEsquimo3D.MOUSE_OUT, m_esquimo_mouseOut); (...) private function m_esquimo_mouseOver(e:MouseEvent):void { if (e.delta == sphere_1){ //if no checking is done, then any object in the scene would cause executing instruction within this event handler m_esquimo.SetGeometrySurfaceID(sphere_1, Esq_scene_el.SURFACE_2); } } private function m_esquimo_mouseOut(e:MouseEvent):void { if (e.delta == sphere_1) { m_esquimo.SetGeometrySurfaceID(sphere_1, Esq_scene_el.SURFACE_1); } }
The above example creates an array of 10 surfaces. Each of them is a copy of SURFACE_1 with randomly picked color. SURFACE_1 is a const defined within Esq_scene_el.as file which contains all surfaces created in Esquimo editor. Of course you can duplicate surfaces created from a scratch with use of CreateSurface command as well.
Surface settings
All the methods listed below return a result of the call as a Boolean value. The returned value is mostly used for seeking errors in case the method seems not working. The most probably reason of false returned is incorrect surfaceId passed as a parameter.
You can see how following parameters affect surface look in the chapter devoted handling surfaces in Esquimo editor.
m_esquimo.SetSurfaceDoubleSided(Esq_scene_el.SURFACE_1, true);
m_esquimo.SetSurfaceTransparent(Esq_scene_el.SURFACE_1, 0.5);
Possible values of type parameter are:
- 0 - "normal" blending mode. The surface is drawn over the objects in the background.
- 1 - "add" blending mode. Color values of pixels of the surface are added to pixel values of the background.
m_esquimo.SetSurfaceBlendingMode(Esq_scene_el.SURFACE_1, 1);
Possible values of type parameter are:
- 0 - Disabled lighting. The surface is not affected by lighting. Surface with "fill" shader takes a solid color and texture if applied retain original pixel values regardless of lights placed in the scene.
- 1 - Smooth. Color changes across faces in a such way the edge of the face takes approximate values of its adjacent triangles. This makes edges looking invisible when mesh is dense enough.
- 2 - Flat. The level of ligthing is the same for each pixels of particular face. At this mode edges of the mesh are clearly visible.
m_esquimo.SetSurfaceLightingType(Esq_scene_el.SURFACE_1, 2);
The higher the parameter the lighter are shadowed parts of the object. Possible values are from 0 to 1 range. Value of 0 means no self illumination. Value of 1 makes object looking like a bulb, but it doesn't light other objects.
m_esquimo.SetSurfaceSelfIllumination(Esq_scene_el.SURFACE_1, 0.3);
m_esquimo.SetSurfaceSpecular(Esq_scene_el.SURFACE_1, 0x0000ff);
m_esquimo.SetSurfaceShininess(Esq_scene_el.SURFACE_1, 4);
m_esquimo.SetSurfaceFillShaderColor(Esq_scene_el.SURFACE_1, 0xffcc00);
Possible values of type parameter are:
- 0 - None
- 1 - Fill
- 2 - Cartoon
- 3 - Texture
m_esquimo.SetSurfaceShaderType(Esq_scene_el.SURFACE_1, 1);
m_esquimo.SetSurfaceCartoonShaderLinesThickness(Esq_scene_el.SURFACE_1, 5);
m_esquimo.SetSurfaceCartoonShaderLinesColor(Esq_scene_el.SURFACE_1, 0xffcc00);
m_esquimo.SetSurfaceCartoonShaderLevels(Esq_scene_el.SURFACE_1, 3);
To see the effect the shader of the surface must be set to "Texture" (see "SetSurfaceShaderType" method). The texture must be also available. It might be either created using API or be included within scene files exported from editor. Textures prepared in Esquimo editor have unique ID. You can reference textures using these IDs. To make it easier all ID numbers are exported with corresponding user friendly names as a set of CONSTs. A name of CONST takes a filename of the picture loaded in Texture Manager.
m_esquimo.SetSurfaceTextureID(mySurface1, texture1);
Check CreateTexture method description below to see example of use.
The new texture is created based on provided BitmapData object. This way you can dynamically load as well as create any texture from scratch. Make graphics using standard drawing API provided with actionscript 3 and then simply cast it to the BitmapData using .draw built in AS3 method. If you haven't heard about it before check Adobe's detailed explanation or search google for some blogs presenting practical use of .draw()
The method returns an integer value which is further used to reference the created texture.
private var texPlane1:uint; private var mySurface1:uint;; private var texture1:uint; (...) { mySurface1 = m_esquimo.CreateSurface(); texPlane1 = m_esquimo.GeometryCreateTexturedPlane(mySurface1, 4, 6, 1, 1, 1); m_esquimo.SetSurfaceShaderType(mySurface1, 3); // shader type set to "Texture" //let's draw something what is going to texture var bd1:BitmapData = new BitmapData(512, 512, true, 0x00000000); var board1:Sprite = new Sprite(); board1.graphics.beginFill(0xffcc00, 0.8); board1.graphics.drawCircle(192, 256, 128); board1.graphics.beginFill(0x88ccff, 0.8); board1.graphics.drawCircle(320, 256, 128); var tf:TextField = new TextField(); var stf:TextFormat = new TextFormat(); tf.autoSize = TextFieldAutoSize.CENTER; tf.x = 256; tf.y = 200; stf.color = 0xffffff; stf.size = 100; tf.text = "Hello !"; tf.setTextFormat(stf); board1.addChild(tf); bd1.draw(board1); texture1 = m_esquimo.CreateTexture(bd1); // make the texture out of BitmapData m_esquimo.SetSurfaceTextureID(mySurface1, texture1); // assign the texture to surface m_esquimo.addEventListener(NEsquimo3D.FRAME_RENDERED, m_esquimo_frameRendered); // and add some motion } private function m_esquimo_frameRendered(e:Event):void { m_esquimo.AppendGeometryRotationMatrixY(texPlane1, 1); m_esquimo.AppendGeometryRotationMatrixX(texPlane1, 2.5); }
m_esquimo.ReplaceTexture(texture1, bd2);
By using this method you can easily achieve "hover" effect. Though this is not the only possible way of accomplishing the "hover". You can also swap textures for given surface (SetSurfaceTextureID) or swap surfaces for the mesh (SetGeometrySurfaceID).
m_esquimo.RemoveTexture(texture1);
var ifSucceed:Boolean = m_esquimo.SetSurfaceLines(Esq_scene_el.SURFACE_1, true);
If the targeted ID cannot be found false value is returned.
m_esquimo.SetSurfaceLinesThickness(Esq_scene_el.SURFACE_1, 3);
m_esquimo.SetSurfaceLinesColor(Esq_scene_el.SURFACE_1, 0x00ff00);
m_esquimo.SetSurfacePoints(Esq_scene_el.SURFACE_1, true);
m_esquimo.SetSurfacePointsSize(Esq_scene_el.SURFACE_1, 3);
m_esquimo.SetSurfacePointsColor(Esq_scene_el.SURFACE_1, 0xeeeeee);