title category import { OrbitControl } from "@oasis-engine/controls" ; import { AssetType , BlinnPhongMaterial , Camera , Color , DirectLight , Entity , Material , MeshRenderer , ModelMesh , PrimitiveMesh , RenderFace , Script , Texture2D , Vector3 , WebGLEngine } from "oasis-engine" ; init ( ) ; function init ( ) { const engine = new WebGLEngine ( "canvas" ) ; engine . canvas . resizeByClientSize ( ) ; const scene = engine . sceneManager . activeScene ; const rootEntity = scene . createRootEntity ( ) ; scene . ambientLight . diffuseSolidColor = new Color ( 0.6 , 0.6 , 0.6 ) ; const cameraEntity = rootEntity . createChild ( "Camera" ) ; cameraEntity . transform . setPosition ( 0 , 0 , 20 ) ; cameraEntity . addComponent ( Camera ) ; cameraEntity . addComponent ( OrbitControl ) ; const lightEntity = rootEntity . createChild ( "DirectLight" ) ; const light = lightEntity . addComponent ( DirectLight ) ; light . intensity = 0.6 ; engine . resourceManager . load < Texture2D > ( { url : "https://gw.alipayobjects.com/mdn/rms_7c464e/afts/img/A*ArCHTbfVPXUAAAAAAAAAAAAAARQnAQ" , type : AssetType . Texture2D } ) . then ( ( texture ) => { const distanceX = 2.5 ; const distanceY = 2.4 ; const position = new Vector3 ( ) ; const material = new BlinnPhongMaterial ( engine ) ; material . renderFace = RenderFace . Double ; material . baseTexture = texture ; for ( let i = 0 ; i < 3 ; i ++ ) { const posX = ( i - 1 ) * distanceX ; position . setValue ( posX , distanceY * 3 , 0 ) ; generatePrimitiveEntity ( rootEntity , "cuboid" , position , material , PrimitiveMesh . createCuboid ( engine ) ) ; position . setValue ( posX , distanceY * 2 , 0 ) ; generatePrimitiveEntity ( rootEntity , "sphere" , position , material , PrimitiveMesh . createSphere ( engine ) ) ; position . setValue ( posX , distanceY * 1 , 0 ) ; generatePrimitiveEntity ( rootEntity , "plane" , position , material , PrimitiveMesh . createPlane ( engine ) ) ; position . setValue ( posX , - distanceY * 0 , 0 ) ; generatePrimitiveEntity ( rootEntity , "cylinder" , position , material , PrimitiveMesh . createCylinder ( engine ) ) ; position . setValue ( posX , - distanceY * 1 , 0 ) ; generatePrimitiveEntity ( rootEntity , "cone" , position , material , PrimitiveMesh . createCone ( engine ) ) ; position . setValue ( posX , - distanceY * 2 , 0 ) ; generatePrimitiveEntity ( rootEntity , "torus" , position , material , PrimitiveMesh . createTorus ( engine ) ) ; position . setValue ( posX , - distanceY * 3 , 0 ) ; generatePrimitiveEntity ( rootEntity , "capsule" , position , material , PrimitiveMesh . createCapsule ( engine , 0.5 , 1 , 24 , 1 ) ) ; } } ) ; engine . run ( ) ; } /**
 * generate primitive mesh entity.
 */ function generatePrimitiveEntity ( rootEntity , name , position , material , mesh ) { const entity = rootEntity . createChild ( name ) ; entity . transform . setPosition ( position . x , position . y , position . z ) ; entity . addComponent ( RotateScript ) ; const renderer = entity . addComponent ( MeshRenderer ) ; renderer . mesh = mesh ; renderer . setMaterial ( material ) ; return entity ; } /**
 * Script for rotate.
 */ class RotateScript extends Script { @override
     * The main loop, called frame by frame.
     *  param deltaTime onUpdate ( deltaTime ) { this . entity . transform . rotate ( 0.5 , 0.6 , 0 ) ; } }