Skip to content

Instantly share code, notes, and snippets.

@nakosung
Last active August 10, 2016 13:10
Show Gist options
  • Save nakosung/2466994e78e887d19c2b to your computer and use it in GitHub Desktop.
Save nakosung/2466994e78e887d19c2b to your computer and use it in GitHub Desktop.
unreal.js rotating box
GWorld.GetAllActorsOfClass(Light).OutActors.map(l => l.DestroyActor())
function light(color) {
let actor = new PointLight(GWorld)
actor.LightComponent.SetMobility('Movable')
actor.LightComponent.Intensity = 1000
actor.LightComponent.SetLightColor(color)
return actor
}
function box(p,size,color) {
let actor = new StaticMeshActor(GWorld,p)
let smc = actor.StaticMeshComponent
smc.SetMobility('Movable')
smc.SetStaticMesh(StaticMesh.Load('/Engine/BasicShapes/Cube'))
let mtrl = Material.Load('/Game/Color')
let mi = KismetMaterialLibrary.CreateDynamicMaterialInstance(GWorld,mtrl)
mi.SetVectorParameterValue('color',color)
smc.SetMaterial(0,mi)
actor.SetActorScale3D(size)
return actor
}
function bg(p) {
let size = 1000
let boxsize = 100
let scale = size/boxsize
p = Vector(p)
// back
box(p.Add_VectorVector({X:size / 2,Z:size / 2}),{X:1,Y:scale,Z:scale},{R:0.5,G:0.7})
// left
box(p.Add_VectorVector({Y:-size / 2,Z:size / 2}),{X:scale,Y:1,Z:scale},{B:1})
// floor
box(p,{X:scale,Y:scale,Z:1},{R:1})
const N = 10
const s = 0.04
_.range(N).forEach(y => {
_.range(N).forEach(x => {
let a = box(p.Add_VectorVector({Y:(y - N/2) * 50, Z: x * 50}),{X:s,Y:s,Z:s},{R:1,G:1,B:1})
a.SetActorRotation({Yaw:Math.random() * 360, Pitch:Math.random() * 180})
})
})
}
function skel(p) {
let resource = SkeletalMesh.Load('/Game/Mannequin/Character/Mesh/SK_Mannequin')
let actor = new SkeletalMeshActor(GWorld,Vector(p).Add_VectorVector({Z:50}))
actor.SkeletalMeshComponent.SetSkeletalMesh(resource)
actor.SetActorRotation({Yaw:90})
}
function rotate(actor,opts) {
function tick() {
if (!actor.IsValid()) return
let rad = $time * opts.k
let r = opts.r
let p = Vector({Y:Math.cos(rad) * r, Z:Math.sin(rad) * r}).Add_VectorVector(opts.p)
actor.SetActorLocation(p)
process.nextTick(tick)
}
tick()
}
rotate(light({R:1}),{k:1.8,r:150,p:{X:400,Y:-100,Z:100}})
rotate(light({G:1}),{k:1.5,r:30,p:{X:400,Z:150}})
rotate(light({B:1}),{k:0.1,r:230,p:{X:400,Z:250}})
bg({X:400,Z:-150,Y:-100})
skel({X:400,Z:-150,Y:-100})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment