Jump to Main Content
Jump to Main Content

BlinkScript Create Material Code Example



Description


This code example shows how programatically create a material and apply it to an object which in this case is a torus knot. All the code and assets are in the projects Scripts directory. You can download the project using the link above.

PostWorld.js


// Turn on debug so that Chat.printDebug() and Chat.dump() work
Chat.debugOutput = true;

// Display the stats panel in the bottom left corner of screen
Application.statsVisible = true;

// Turn on collisions, but allow the user to turn it off
Actor.setCollisionSetting( true, false );

// Turn on gravity, but allow the user to turn it off
Actor.setGravitySetting( true, false );

// Hide the avatar
Actor.showAvatar  = false;

// Hide the chat panel
Application.chatPaneVisible = false;

// Set ambient light for the scene
Scene.ambientLightColor = Color(0.5, 0.5, 0.5, 0);

// Create a Skydome
oSkyDome = Scene.createSkyDome();
oSkyDome.materialName = "CloudySky";
oSkyDome.curvature = 5;
oSkyDome.tiling = 8;
oSkyDome.distance = 4000;
oSkyDome.enable = true;

// Create a point light
oPointLight = Scene.createPointLight( "SceneLight" );
oPointLight.position = Vector( 20, 300, 50 );

// Create the floor
oGround = Scene.createGround( "MainFloor", "Grass", 3000.0, 3000.0, true );

// Create an entity
oEntity = Scene.createEntity( "Knot", "knot.mesh" );

// Create a scene node and attach the entity to it and position it
oSceneNode = Scene.createSceneNode( "KnotNode" );
oSceneNode.attachObject( oEntity );
oSceneNode.position = Vector( 0,100, -500 );

// Create an empty material
oMaterial = Scene.createMaterial( "TestMat", "General" );

// Enable dynamic lighting for the material
oMaterial.setDynamicLighting( true );

// Get the first technique, new materials always have 1 technique
oTechnique = oMaterial.getTechnique( 0 );

// Get the first pass of the technique,
// new materials always have 1 technique which always has 1 pass
oPass = oTechnique.getPass( 0 );

// Create a texture in the pass
oTexture = oPass.createTexture();

// Set the name of the texture to use
oTexture.setTextureName( "RustySteel.jpg" );

// Set the material for the torus knot entity
oEntity.setMaterialName( "TestMat" );


Related BlinkScript Examples
?????? ?????? ?????? ??????