void initWeapon() { // load texture away::ByteArray* textureBytes = new away::ByteArray(); readFileToByteArray("m_weapon2.atf", *textureBytes); away::ATFTexture* texture = new away::ATFTexture(textureBytes); // load mesh file away::ByteArray kldBytes; readFileToByteArray("m_weapon2.kld", kldBytes); // parse mesh file weapon = new away::Mesh(new away::Geometry()); weapon->setCastsShadows(true); KLDParser parser(weapon); parser.parse(&kldBytes); // build material away::TextureMaterial* material = new away::TextureMaterial(texture); material->setLightPicker(lightPicker); weapon->setMaterial(material); }
void initCharacter() { // load texture away::ByteArray* textureBytes = new away::ByteArray(); readFileToByteArray("mage_m0.atf", *textureBytes); away::ATFTexture* texture = new away::ATFTexture(textureBytes); // load mesh file away::ByteArray kldBytes; readFileToByteArray("mage_m0.kld", kldBytes); // parse mesh file character = new away::Mesh(new away::Geometry()); character->setCastsShadows(true); KLDParser parser(character); parser.parse(&kldBytes); // build material away::TextureMaterial* material = new away::TextureMaterial(texture); material->setLightPicker(lightPicker); character->setMaterial(material); scene->addChild(character); }
void initRide() { // load texture away::ByteArray* textureBytes = new away::ByteArray(); readFileToByteArray("ride22.atf", *textureBytes); away::ATFTexture* texture = new away::ATFTexture(textureBytes); // load mesh file away::ByteArray kldBytes; readFileToByteArray("ride22.kld", kldBytes); // parse mesh file ride = new away::Mesh(new away::Geometry()); ride->setCastsShadows(true); KLDParser parser(ride); parser.parse(&kldBytes); // build material away::TextureMaterial* material = new away::TextureMaterial(texture); material->setAlphaThreshold(0.5f); material->setLightPicker(lightPicker); ride->setMaterial(material); }
void initParticle() { std::vector<away::Geometry*> geometrySet; away::ParticleGeometryTransform transforms[1000]; away::PlaneGeometry* plane = new away::PlaneGeometry(30, 30, 1, 1, false); for (int i = 0; i < 1000; i++) { away::Matrix* uvTransform = new away::Matrix(); uvTransform->scale(0.5f, 0.5f); uvTransform->translate(away::MathUtils::random(0, 1) * 0.5f, away::MathUtils::random(0, 1) * 0.5f); transforms[i].setUVTransform(uvTransform); geometrySet.push_back(plane); } away::ParticleAnimationSet* animationSet = new away::ParticleAnimationSet(true, true, true); animationSet->addAnimation(new away::ParticleBillboardNode()); animationSet->addAnimation(new away::ParticleVelocityNode(away::ParticlePropertiesMode::LOCAL_STATIC)); animationSet->addAnimation(particleFollowNode = new away::ParticleFollowNode(true, false)); animationSet->m_initParticleFunc = [](away::ParticleProperties& prop) { prop.m_startTime = away::MathUtils::random(0.f, 4.1f); prop.m_duration = 4; prop[away::ParticleVelocityNode::VELOCITY_VECTOR3D].setTo(away::MathUtils::random(-50.f, 50.f), away::MathUtils::random(-200.f, -100.f), away::MathUtils::random(-50.f, 50.f)); }; away::ByteArray* textureBytes = new away::ByteArray(); readFileToByteArray("cards_suit.atf", textureBytes); away::TextureMaterial* material = new away::TextureMaterial(new away::ATFTexture(textureBytes)); material->setBlendMode(away::BlendMode::ADD); away::Mesh* particleMesh = new away::Mesh(away::ParticleGeometryHelper::generateGeometry(geometrySet, transforms), material); particleMesh->setY(300); away::ParticleAnimator* animator = new away::ParticleAnimator(animationSet); particleMesh->setAnimator(animator); static_cast<away::ParticleFollowState*>(animator->getAnimationState(particleFollowNode))->setFollowTarget(followTarget); animator->start(); away::AxisAlignedBoundingBox bounds; bounds.fromExtremes(-200, -800, -200, 200, 0, 200); particleMesh->setBounds(&bounds); particleMesh->setShowBounds(true); scene->addChild(particleMesh); }
void initParticle(struct engine* engine) { away::PlaneGeometry* plane = new away::PlaneGeometry(50, 50, 1, 1, false); std::vector<away::Geometry*> geometrySet; for (int i = 0; i < 10; i++) geometrySet.push_back(plane); away::ParticleAnimationSet* animationSet = new away::ParticleAnimationSet(true, true); animationSet->m_initParticleFunc = [](away::ParticleProperties& prop) { prop.m_startTime = away::MathUtils::random(0.f, 5.f); prop.m_duration = away::MathUtils::random(0.1f, 4.1f); float radius = 15; float degree1 = away::MathUtils::random(0.f, away::MathConsts::TWO_PI); float degree2 = away::MathUtils::random(0.f, away::MathConsts::TWO_PI); prop[away::ParticleVelocityNode::VELOCITY_VECTOR3D].setTo(radius * std::sin(degree1) * std::cos(degree2), 80 + radius * std::cos(degree1) * std::cos(degree2), radius * std::sin(degree2)); }; animationSet->addAnimation(new away::ParticleBillboardNode()); animationSet->addAnimation(new away::ParticleScaleNode(away::ParticlePropertiesMode::GLOBAL, false, false, 2.5f, 0.5f)); //animationSet->addAnimation(new away::ParticleColorNode(away::ParticlePropertiesMode::GLOBAL, true, true, false, false, new away::ColorTransform(0, 0, 0, 1, 0xFF, 0x33, 0x01), new away::ColorTransform(0, 0, 0, 1, 0x99))); animationSet->addAnimation(new away::ParticleVelocityNode(away::ParticlePropertiesMode::LOCAL_STATIC)); away::ByteArray* textureBytes = new away::ByteArray(); readFileToByteArray(engine, "TX_n_jyt_bigwave.atf", textureBytes); away::ATFTexture* texture = new away::ATFTexture(textureBytes); away::TextureMaterial* material = new away::TextureMaterial(texture); material->setBlendMode(away::BlendMode::LAYER); // add DistortionMethod material->addMethod(new away::DistortionMethod(texture, engine->m_view->getSceneTexture(), 0, 0, 0.5f)); engine->m_particleMesh = new away::Mesh(away::ParticleGeometryHelper::generateGeometry(geometrySet), material); engine->m_particleMesh->setAnimator(new away::ParticleAnimator(animationSet)); static_cast<away::ParticleAnimator*>(engine->m_particleMesh->getAnimator())->start(); away::AxisAlignedBoundingBox bounds; bounds.fromExtremes(-50, 0, -50, 50, 350, 50); engine->m_particleMesh->setBounds(&bounds); //particleMesh->setShowBounds(true); engine->m_scene->addChild(engine->m_particleMesh); }
void initScene() { // load map.bin away::ByteArray mapBytes; readFileToByteArray("map.bin", &mapBytes); // parse map.bin MapBinParser parser; parser.parse(&mapBytes); // load heightmap away::ByteArray heightBytes; readFileToByteArray("heightmap.dat", &heightBytes); // load blend texture away::ByteArray* blendBytes = new away::ByteArray(); readFileToByteArray("blendmask.atf", blendBytes); away::ATFTexture* blendMap = new away::ATFTexture(blendBytes); // load surface textures std::vector<away::ATFTexture*> surfaceMaps; std::vector<SurfaceData>& surfaces = parser.getSurfaceData(); for (SurfaceData& surface : surfaces) { away::ByteArray* surfaceBytes = new away::ByteArray(); std::string diffuseMapPath = surface.m_diffuseMap + ".atf"; readFileToByteArray(diffuseMapPath.c_str(), surfaceBytes); surfaceMaps.push_back(new away::ATFTexture(surfaceBytes)); } // load lightmap textures std::vector<away::ATFTexture*> lightMaps; std::vector<LightMapData>& terrainLightMaps = parser.getTerrainLightMapData(); for (unsigned int i = 0; i < terrainLightMaps.size(); i++) { char name[16]; sprintf_s(name, 16, "terrain%d.atf", i); away::ByteArray* lightMapBytes = new away::ByteArray(); readFileToByteArray(name, lightMapBytes); lightMaps.push_back(new away::ATFTexture(lightMapBytes)); } // triangle indices unsigned short idx0, idx1; int sectorGrid = parser.getSectorGrid(); int blockGrid = parser.getBlockGrid(); float vertexSpace = parser.getVertexSpace(); float sectorSize = sectorGrid * vertexSpace; int numVertexPerRow = blockGrid + 1; unsigned short* indices = new unsigned short[blockGrid * blockGrid * 6]; for (int row = 0, i = 0; row < blockGrid; row++) { for (int col = 0; col < blockGrid; col++) { idx0 = numVertexPerRow * row + col; idx1 = idx0 + numVertexPerRow; indices[i++] = idx0; indices[i++] = idx1; indices[i++] = idx0 + 1; indices[i++] = idx0 + 1; indices[i++] = idx1; indices[i++] = idx1 + 1; } } // read walkgrid.dat and draw walkgrid to bitmap away::ByteArray walkGridBytes; readFileToByteArray("walkgrid.dat", &walkGridBytes); int gridSize = parser.getWalkGridSize(); int bmdSize = away::TextureUtils::getBestPowerOf2(gridSize); away::BitmapData* walkGridBmd = new away::BitmapData(bmdSize, bmdSize, false); int margin = (bmdSize - gridSize) / 2; for (int y = 0; y < gridSize; y++) { for (int x = 0; x < gridSize; x++) { if (walkGridBytes.readUnsignedByte() & 0x80) walkGridBmd->setPixel(x + margin, y + margin, 0xFF0000); else walkGridBmd->setPixel(x + margin, y + margin, 0x00FF00); } } away::TextureProjector* projector = new away::TextureProjector(new away::BitmapTexture(walkGridBmd, false, false), false); static_cast<away::OrthographicLens*>(projector->getLens())->setProjectionHeight(sectorSize * bmdSize / gridSize); method = new away::ProjectiveTextureMethod(projector, away::ProjectiveMode::MULTIPLY, false); // read walkmesh.dat and build WireframeTriangles away::ByteArray walkMeshBytes; readFileToByteArray("walkmesh.dat", &walkMeshBytes); away::Vector3D point; walkableMesh = new away::WireframeTriangles(0x0000FF); unsigned int numMeshes = walkMeshBytes.readUnsignedInt(); for (unsigned int i = 0; i < numMeshes; i++) { unsigned int numPoints = walkMeshBytes.readUnsignedInt() * 3; walkMeshBytes.setPosition(walkMeshBytes.getPosition() + 24); for (unsigned int j = 0; j < numPoints; j++) { point.m_x = walkMeshBytes.readFloat(); point.m_y = walkMeshBytes.readFloat(); point.m_z = walkMeshBytes.readFloat(); walkableMesh->addPoint(point); } } // build blocks int blockId = 0; int numBlockPerRow = sectorGrid / blockGrid; for (BlockData& blockData : parser.getBlockData()) { // build terrain std::vector<away::ATFTexture*> layerMaps; std::vector<float> layerTilings, distMaskStrengths; for (int index : blockData.m_surfaceIndents) { layerMaps.push_back(surfaceMaps[index]); layerTilings.push_back(surfaces[index].m_textureTiling); distMaskStrengths.push_back(surfaces[index].m_distMaskStrength); } BeastData& beastData = blockData.m_terrainBeast; int frameIndex = beastData.m_frameIndex; TerrainMesh* terrainMesh = new TerrainMesh(blockGrid, vertexSpace); terrainMesh->buildGeometry(heightBytes, sectorGrid, parser.getMinHeight(), parser.getMaxHeight(), indices, blockId); terrainMesh->buildMaterial(blendMap, layerMaps, layerTilings, distMaskStrengths, lightMaps[frameIndex], beastData, terrainLightMaps[frameIndex], numBlockPerRow, blockId++); scene->addChild(terrainMesh); terrainMeshes.push_back(terrainMesh); } // build blockGrid segmentSet = new away::SegmentSet(); float x, z, blockSize = blockGrid * vertexSpace, halfSectorSize = sectorSize * 0.5f; for (int i = 1; i < numBlockPerRow; i++) { x = i * blockSize - halfSectorSize; for (int j = 0; j < sectorGrid; j++) { z = j * vertexSpace - halfSectorSize; away::Vector3D start(x, getTerrainHeight(i, j / blockGrid, numBlockPerRow, x, z), z); z += vertexSpace; away::Vector3D end(x, getTerrainHeight(i, (j + 1) / blockGrid, numBlockPerRow, x, z), z); segmentSet->addSegment(new away::Segment(start, end, 0xffffff, 0xffffff)); } } for (int i = 1; i < numBlockPerRow; i++) { z = i * blockSize - halfSectorSize; for (int j = 0; j < sectorGrid; j++) { x = j * vertexSpace - halfSectorSize; away::Vector3D start(x, getTerrainHeight(j / blockGrid, i, numBlockPerRow, x, z), z); x += vertexSpace; away::Vector3D end(x, getTerrainHeight((j + 1) / blockGrid, i, numBlockPerRow, x, z), z); segmentSet->addSegment(new away::Segment(start, end, 0xffffff, 0xffffff)); } } scene->addChild(segmentSet); }
void initScene(struct engine* engine) { away::ByteArray* textureBytes = new away::ByteArray(); readFileToByteArray(engine, "floor_diffuse.atf", textureBytes); engine->m_scene->addChild(new away::Mesh(new away::PlaneGeometry(1000, 1000), new away::TextureMaterial(new away::ATFTexture(textureBytes)))); }
Shader loadShaderJson(const QString & shaderPath) { QByteArray json = readFileToByteArray(shaderPath); return parseShaderJson(json); }