def generateNode(self, name, DB, parentNode): log.debug("Setting up " + name) bodyEntity = sandbox.createEntity() component = CelestialComponent() if DB["type"] == "solid": body = Body(name) elif DB["type"] == "moon": body = Body(name) body.kind = "moon" elif DB["type"] == "star": body = Star(name) body.absoluteM = DB["absolute magnitude"] body.spectral = DB["spectral"] elif DB["type"] == "barycenter": body = BaryCenter(name) component.kind = TYPES[DB["type"]] if DB["type"] != "barycenter": component.mass = DB["mass"] body.radius = DB["radius"] body.rotation = DB["rotation"] if "orbit" in DB: component.orbit = DB["orbit"] body.period = DB["period"] # body.setPos(self.get2DBodyPosition(component, universals.day)) component.truePos = self.get2DBodyPosition(component, universals.day) if name == "Earth": # universals.spawn = component.truePos + LPoint3d(0, 6671, 0) universals.spawn = component.truePos + LPoint3d(6671, 0, 0) if parentNode == universals.solarSystemRoot: universals.defaultSOIid = bodyEntity.id component.soi = 0 elif DB["type"] != "star" or DB["type"] != "barycenter": component.soi = self.getSOI(component.mass, self.bodies[0].mass, component.orbit["a"]) body.type = DB["type"] body.reparentTo(parentNode) component.nodePath = body self.bodies.append(component) bodyEntity.addComponent(component) if universals.runClient and DB["type"] == "star": component = graphicsComponents.RenderComponent() # component.mesh = NodePath(name) # self.sphere.copyTo(component.mesh) # component.mesh = shapeGenerator.Sphere(body.radius, 128, name) component.mesh = shapeGenerator.Sphere(body.radius, 64, name) # component.mesh.setScale(body.radius) component.mesh.reparentTo(sandbox.base.render) sandbox.send("makePickable", [component.mesh]) # texture = sandbox.base.loader.loadTexture('planets/' + DB['texture']) # texture.setMinfilter(Texture.FTLinearMipmapLinear) # ts1 = TextureStage('textures1') # ts1.setMode(TextureStage.MGlow) # component.mesh.setTexture(ts1, texture) # component.mesh.setTexture(texture, 1) component.light = component.mesh.attachNewNode(PointLight("sunPointLight")) component.light.node().setColor(Vec4(1, 1, 1, 1)) sandbox.base.render.setLight(component.light) bodyEntity.addComponent(component) # Shader test componentStar = graphicsComponents.StarRender() componentStar.noise_texture = Texture("noise") componentStar.noise_texture.setup2dTexture() img = PNMImage(1024, 1024) for y in range(1024): for x in range(1024): img.setXel(x, y, componentStar.noise.noise(x, y)) # print componentStar.noise.noise(x, y) componentStar.noise_texture.load(img) # componentStar.noise_texture.write('test.png') # component.mesh.setTexture(componentStar.noise_texture, 1) texture = sandbox.base.loader.loadTexture("planets/" + DB["texture"]) ts1 = TextureStage("textures1") ts1.setMode(TextureStage.MGlow) component.mesh.setTexture(ts1, componentStar.noise_texture) # component.mesh.setTexture(ts1, texture) component.mesh.setShaderInput("time", universals.get_day_in_seconds()) shaders = Shader.load(Shader.SLGLSL, "vortexVertex.glsl", "starFrag.glsl") component.mesh.setShader(shaders) sandbox.send("makePickable", [component.mesh]) if universals.runClient and (DB["type"] == "solid" or DB["type"] == "moon"): component = graphicsComponents.RenderComponent() # component.mesh = shapeGenerator.Sphere(body.radius, 128, name) # component.mesh = shapeGenerator.Sphere(body.radius, 64, name) component.mesh = surface_mesh.make_planet(name=name, scale=body.radius) # sandbox.send('makePickable', [component.mesh]) sandbox.send("makePickable", [component.mesh.node_path]) # component.mesh.setScale(body.radius) component.mesh.reparent_to(sandbox.base.render) # Doing world text text = TextNode("node name") text.setText(name) # textNodePath = component.mesh.attachNewNode(text) textNodePath = component.mesh.node_path.attachNewNode(text) textNodePath.setScale(0.07) component.mesh.set_textures(DB["texture"], night_path=DB["night"], gloss_path=DB["spec"]) component.mesh.set_ambient(1, 1, 1, 1) component.mesh.set_diffuse(1, 1, 1, 1) component.mesh.set_specular(1, 1, 1, 1) component.mesh.set_shininess(100) """if '#' in DB['texture']: component.mesh.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldPosition) component.mesh.setTexProjector(TextureStage.getDefault(), sandbox.base.render, component.mesh) component.mesh.setTexScale(TextureStage.getDefault(), 1, 1, -1) component.mesh.setTexHpr(TextureStage.getDefault(), 90, -18, 90) #self.mesh.setHpr(0, 90, 0) texture = loader.loadCubeMap('planets/' + DB['texture']) else: texture = sandbox.base.loader.loadTexture('planets/' + DB['texture']) #texture.setMinfilter(Texture.FTLinearMipmapLinear) component.mesh.setTexture(texture, 1)""" """if "atmosphere" in DB: component.atmosphere = shapeGenerator.Sphere(-1, 128) component.atmosphere.reparentTo(render) component.atmosphere.setScale(body.radius * 1.025) outerRadius = component.atmosphere.getScale().getX() scale = 1 / (outerRadius - component.body.getScale().getX()) component.atmosphere.setShaderInput("fOuterRadius", outerRadius) component.atmosphere.setShaderInput("fInnerRadius", component.mesh.getScale().getX()) component.atmosphere.setShaderInput("fOuterRadius2", outerRadius * outerRadius) component.atmosphere.setShaderInput("fInnerRadius2", component.mesh.getScale().getX() * component.mesh.getScale().getX()) component.atmosphere.setShaderInput("fKr4PI", 0.000055 * 4 * 3.14159) component.atmosphere.setShaderInput("fKm4PI", 0.000015 * 4 * 3.14159) component.atmosphere.setShaderInput("fScale", scale) component.atmosphere.setShaderInput("fScaleDepth", 0.25) component.atmosphere.setShaderInput("fScaleOverScaleDepth", scale / 0.25) # Currently hard coded in shader component.atmosphere.setShaderInput("fSamples", 10.0) component.atmosphere.setShaderInput("nSamples", 10) # These do sunsets and sky colors # Brightness of sun ESun = 15 # Reyleight Scattering (Main sky colors) component.atmosphere.setShaderInput("fKrESun", 0.000055 * ESun) # Mie Scattering -- Haze and sun halos component.atmosphere.setShaderInput("fKmESun", 0.000015 * ESun) # Color of sun component.atmosphere.setShaderInput("v3InvWavelength", 1.0 / math.pow(0.650, 4), 1.0 / math.pow(0.570, 4), 1.0 / math.pow(0.465, 4)) #component.atmosphere.setShader(Shader.load("atmo.cg"))""" bodyEntity.addComponent(component) log.info(name + " set Up") if "bodies" in DB: for bodyName, bodyDB in DB["bodies"].items(): self.generateNode(bodyName, bodyDB, body)
loadPrcFileData('', "sync-video 0") loadPrcFileData('', 'basic-shaders-only #f') #loadPrcFileData('', 'dump-generated-shaders #t') #loadPrcFileData('', 'pstats-tasks 1') #loadPrcFileData('', 'want-pstats 1') #loadPrcFileData('', 'threading-model Cull/Draw') import direct.directbase.DirectStart #base.setBackgroundColor(0.0, 0.0, 0.0) import surface_mesh from panda3d.core import NodePath empty = NodePath('empty') #planet = surface_mesh.make_planet(debug=True) planet = surface_mesh.make_planet() planet.reparent_to(render) #planet.set_scale(6360) #planet.reparent_to(empty) #planet.set_texture('textures/earth_#.png') planet.set_textures('textures/earth_#.png', night_path='textures/earth_night_#.png', gloss_path='textures/earth_spec_#.png') planet.set_ambient(1, 1, 1, 1) planet.set_diffuse(1, 1, 1, 1) planet.set_specular(1, 1, 1, 1) planet.set_shininess(100) cloud = surface_mesh.make_clouds() cloud.reparent_to(render) cloud.set_shader_input('Randomize', 1, 1)
def generateNode(self, name, DB, parentNode): log.debug("Setting up " + name) bodyEntity = sandbox.createEntity() component = CelestialComponent() if DB['type'] == 'solid': body = Body(name) elif DB['type'] == 'moon': body = Body(name) body.kind = "moon" elif DB['type'] == 'star': body = Star(name) body.absoluteM = DB['absolute magnitude'] body.spectral = DB['spectral'] elif DB['type'] == 'barycenter': body = BaryCenter(name) component.kind = TYPES[DB['type']] if DB['type'] != "barycenter": component.mass = DB['mass'] body.radius = DB['radius'] body.rotation = DB['rotation'] if 'orbit' in DB: component.orbit = DB['orbit'] body.period = DB['period'] #body.setPos(self.get2DBodyPosition(component, universals.day)) component.truePos = self.get2DBodyPosition(component, universals.day) if name == "Earth": #universals.spawn = component.truePos + LPoint3d(0, 6671, 0) universals.spawn = component.truePos + LPoint3d(6671, 0, 0) if parentNode == universals.solarSystemRoot: universals.defaultSOIid = bodyEntity.id component.soi = 0 elif DB['type'] != 'star' or DB['type'] != 'barycenter': component.soi = self.getSOI(component.mass, self.bodies[0].mass, component.orbit['a']) body.type = DB['type'] body.reparentTo(parentNode) component.nodePath = body self.bodies.append(component) bodyEntity.addComponent(component) if universals.runClient and DB['type'] == 'star': component = graphicsComponents.RenderComponent() #component.mesh = NodePath(name) #self.sphere.copyTo(component.mesh) #component.mesh = shapeGenerator.Sphere(body.radius, 128, name) component.mesh = shapeGenerator.Sphere(body.radius, 64, name) #component.mesh.setScale(body.radius) component.mesh.reparentTo(sandbox.base.render) sandbox.send('makePickable', [component.mesh]) #texture = sandbox.base.loader.loadTexture('planets/' + DB['texture']) #texture.setMinfilter(Texture.FTLinearMipmapLinear) #ts1 = TextureStage('textures1') #ts1.setMode(TextureStage.MGlow) #component.mesh.setTexture(ts1, texture) #component.mesh.setTexture(texture, 1) component.light = component.mesh.attachNewNode(PointLight("sunPointLight")) component.light.node().setColor(Vec4(1, 1, 1, 1)) sandbox.base.render.setLight(component.light) bodyEntity.addComponent(component) #Shader test componentStar = graphicsComponents.StarRender() componentStar.noise_texture = Texture('noise') componentStar.noise_texture.setup2dTexture() img = PNMImage(1024, 1024) for y in range(1024): for x in range(1024): img.setXel(x, y, componentStar.noise.noise(x, y)) #print componentStar.noise.noise(x, y) componentStar.noise_texture.load(img) #componentStar.noise_texture.write('test.png') #component.mesh.setTexture(componentStar.noise_texture, 1) texture = sandbox.base.loader.loadTexture('planets/' + DB['texture']) ts1 = TextureStage('textures1') ts1.setMode(TextureStage.MGlow) component.mesh.setTexture(ts1, componentStar.noise_texture) #component.mesh.setTexture(ts1, texture) component.mesh.setShaderInput('time', universals.get_day_in_seconds()) shaders = Shader.load(Shader.SLGLSL, 'vortexVertex.glsl', 'starFrag.glsl') component.mesh.setShader(shaders) sandbox.send('makePickable', [component.mesh]) if universals.runClient and (DB['type'] == 'solid' or DB['type'] == 'moon'): component = graphicsComponents.RenderComponent() #component.mesh = shapeGenerator.Sphere(body.radius, 128, name) #component.mesh = shapeGenerator.Sphere(body.radius, 64, name) component.mesh = surface_mesh.make_planet(name=name, scale=body.radius) #sandbox.send('makePickable', [component.mesh]) sandbox.send('makePickable', [component.mesh.node_path]) #component.mesh.setScale(body.radius) component.mesh.reparent_to(sandbox.base.render) # Doing world text text = TextNode('node name') text.setText(name) #textNodePath = component.mesh.attachNewNode(text) textNodePath = component.mesh.node_path.attachNewNode(text) textNodePath.setScale(0.07) component.mesh.set_textures(DB['texture'], night_path=DB['night'], gloss_path=DB['spec']) component.mesh.set_ambient(1, 1, 1, 1) component.mesh.set_diffuse(1, 1, 1, 1) component.mesh.set_specular(1, 1, 1, 1) component.mesh.set_shininess(100) '''if '#' in DB['texture']: component.mesh.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldPosition) component.mesh.setTexProjector(TextureStage.getDefault(), sandbox.base.render, component.mesh) component.mesh.setTexScale(TextureStage.getDefault(), 1, 1, -1) component.mesh.setTexHpr(TextureStage.getDefault(), 90, -18, 90) #self.mesh.setHpr(0, 90, 0) texture = loader.loadCubeMap('planets/' + DB['texture']) else: texture = sandbox.base.loader.loadTexture('planets/' + DB['texture']) #texture.setMinfilter(Texture.FTLinearMipmapLinear) component.mesh.setTexture(texture, 1)''' '''if "atmosphere" in DB: component.atmosphere = shapeGenerator.Sphere(-1, 128) component.atmosphere.reparentTo(render) component.atmosphere.setScale(body.radius * 1.025) outerRadius = component.atmosphere.getScale().getX() scale = 1 / (outerRadius - component.body.getScale().getX()) component.atmosphere.setShaderInput("fOuterRadius", outerRadius) component.atmosphere.setShaderInput("fInnerRadius", component.mesh.getScale().getX()) component.atmosphere.setShaderInput("fOuterRadius2", outerRadius * outerRadius) component.atmosphere.setShaderInput("fInnerRadius2", component.mesh.getScale().getX() * component.mesh.getScale().getX()) component.atmosphere.setShaderInput("fKr4PI", 0.000055 * 4 * 3.14159) component.atmosphere.setShaderInput("fKm4PI", 0.000015 * 4 * 3.14159) component.atmosphere.setShaderInput("fScale", scale) component.atmosphere.setShaderInput("fScaleDepth", 0.25) component.atmosphere.setShaderInput("fScaleOverScaleDepth", scale / 0.25) # Currently hard coded in shader component.atmosphere.setShaderInput("fSamples", 10.0) component.atmosphere.setShaderInput("nSamples", 10) # These do sunsets and sky colors # Brightness of sun ESun = 15 # Reyleight Scattering (Main sky colors) component.atmosphere.setShaderInput("fKrESun", 0.000055 * ESun) # Mie Scattering -- Haze and sun halos component.atmosphere.setShaderInput("fKmESun", 0.000015 * ESun) # Color of sun component.atmosphere.setShaderInput("v3InvWavelength", 1.0 / math.pow(0.650, 4), 1.0 / math.pow(0.570, 4), 1.0 / math.pow(0.465, 4)) #component.atmosphere.setShader(Shader.load("atmo.cg"))''' bodyEntity.addComponent(component) log.info(name + " set Up") if 'bodies' in DB: for bodyName, bodyDB in DB['bodies'].items(): self.generateNode(bodyName, bodyDB, body)