Transform(const mat4& matrix): mParent(NULL), mAssumeIdentityWorldMatrix(false) { setLocalMatrix(matrix); #ifndef NDEBUG mName = className(); #endif }
SkShader::SkShader(SkFlattenableReadBuffer& buffer) : INHERITED(buffer), fLocalMatrix(NULL) { if (buffer.readBool()) { SkMatrix matrix; SkReadMatrix(&buffer, &matrix); setLocalMatrix(matrix); } SkDEBUGCODE(fInSession = false;) }
std::shared_ptr<gameplay::Node> Room::createSceneNode(gameplay::Game* game, size_t roomId, const level::Level& level, const std::vector<std::shared_ptr<gameplay::Texture>>& textures, const std::map<loader::TextureLayoutProxy::TextureKey, std::shared_ptr<gameplay::Material>>& materials, const std::map<loader::TextureLayoutProxy::TextureKey, std::shared_ptr<gameplay::Material>>& waterMaterials, const std::vector<std::shared_ptr<gameplay::Model>>& staticMeshes, render::TextureAnimator& animator) { RenderModel renderModel; std::map<TextureLayoutProxy::TextureKey, size_t> texBuffers; std::vector<RenderVertex> vbuf; auto mesh = std::make_shared<gameplay::Mesh>(RenderVertex::getFormat(), vbuf.size(), true); for( const QuadFace& quad : rectangles ) { const TextureLayoutProxy& proxy = level.m_textureProxies.at(quad.proxyId); if( texBuffers.find(proxy.textureKey) == texBuffers.end() ) { texBuffers[proxy.textureKey] = renderModel.m_parts.size(); renderModel.m_parts.emplace_back(); auto it = isWaterRoom() ? waterMaterials.find(proxy.textureKey) : materials.find(proxy.textureKey); Expects(it != (isWaterRoom() ? waterMaterials.end() : materials.end())); renderModel.m_parts.back().material = it->second; } const auto partId = texBuffers[proxy.textureKey]; const auto firstVertex = vbuf.size(); for( int i = 0; i < 4; ++i ) { RenderVertex iv; iv.position = vertices[quad.vertices[i]].position.toRenderSystem(); iv.color = vertices[quad.vertices[i]].color; iv.texcoord0 = proxy.uvCoordinates[i].toGl(); vbuf.push_back(iv); } animator.registerVertex(quad.proxyId, {mesh, partId}, 0, firstVertex + 0); renderModel.m_parts[partId].indices.emplace_back(firstVertex + 0); animator.registerVertex(quad.proxyId, {mesh, partId}, 1, firstVertex + 1); renderModel.m_parts[partId].indices.emplace_back(firstVertex + 1); animator.registerVertex(quad.proxyId, {mesh, partId}, 2, firstVertex + 2); renderModel.m_parts[partId].indices.emplace_back(firstVertex + 2); animator.registerVertex(quad.proxyId, {mesh, partId}, 0, firstVertex + 0); renderModel.m_parts[partId].indices.emplace_back(firstVertex + 0); animator.registerVertex(quad.proxyId, {mesh, partId}, 2, firstVertex + 2); renderModel.m_parts[partId].indices.emplace_back(firstVertex + 2); animator.registerVertex(quad.proxyId, {mesh, partId}, 3, firstVertex + 3); renderModel.m_parts[partId].indices.emplace_back(firstVertex + 3); } for( const Triangle& tri : triangles ) { const TextureLayoutProxy& proxy = level.m_textureProxies.at(tri.proxyId); if( texBuffers.find(proxy.textureKey) == texBuffers.end() ) { texBuffers[proxy.textureKey] = renderModel.m_parts.size(); renderModel.m_parts.emplace_back(); auto it = isWaterRoom() ? waterMaterials.find(proxy.textureKey) : materials.find(proxy.textureKey); Expects(it != (isWaterRoom() ? waterMaterials.end() : materials.end())); renderModel.m_parts.back().material = it->second; } const auto partId = texBuffers[proxy.textureKey]; const auto firstVertex = vbuf.size(); for( int i = 0; i < 3; ++i ) { RenderVertex iv; iv.position = vertices[tri.vertices[i]].position.toRenderSystem(); iv.color = vertices[tri.vertices[i]].color; iv.texcoord0 = proxy.uvCoordinates[i].toGl(); vbuf.push_back(iv); } animator.registerVertex(tri.proxyId, {mesh, partId}, 0, firstVertex + 0); renderModel.m_parts[partId].indices.emplace_back(firstVertex + 0); animator.registerVertex(tri.proxyId, {mesh, partId}, 1, firstVertex + 1); renderModel.m_parts[partId].indices.emplace_back(firstVertex + 1); animator.registerVertex(tri.proxyId, {mesh, partId}, 2, firstVertex + 2); renderModel.m_parts[partId].indices.emplace_back(firstVertex + 2); } mesh->rebuild(reinterpret_cast<float*>(vbuf.data()), vbuf.size()); auto resModel = renderModel.toModel(mesh); node = std::make_shared<gameplay::Node>("Room:" + boost::lexical_cast<std::string>(roomId)); node->setDrawable(resModel); for( Light& light : lights ) { const auto f = std::abs(light.specularIntensity) / 8191.0f; BOOST_ASSERT(f >= 0 && f <= 1); switch( light.getLightType() ) { case LightType::Shadow: BOOST_LOG_TRIVIAL(debug) << "Light: Shadow"; light.node = gameplay::Light::createPoint(light.color.r / 255.0f * f, light.color.g / 255.0f * f, light.color.b / 255.0f * f, light.specularFade); break; case LightType::Null: case LightType::Point: BOOST_LOG_TRIVIAL(debug) << "Light: Null/Point"; light.node = gameplay::Light::createPoint(light.color.r / 255.0f * f, light.color.g / 255.0f * f, light.color.b / 255.0f * f, light.specularFade); break; case LightType::Spotlight: BOOST_LOG_TRIVIAL(debug) << "Light: Spot"; light.node = gameplay::Light::createSpot(light.color.r / 255.0f * f, light.color.g / 255.0f * f, light.color.b / 255.0f * f, light.specularFade, light.r_inner, light.r_outer); break; case LightType::Sun: BOOST_LOG_TRIVIAL(debug) << "Light: Sun"; light.node = gameplay::Light::createDirectional(light.color.r / 255.0f * f, light.color.g / 255.0f * f, light.color.b / 255.0f * f); break; } BOOST_LOG_TRIVIAL(debug) << " - Position: " << light.position.X << "/" << light.position.Y << "/" << light.position.Z; BOOST_LOG_TRIVIAL(debug) << " - Length: " << light.length; BOOST_LOG_TRIVIAL(debug) << " - Color: " << light.color.a / 255.0f << "/" << light.color.r / 255.0f << "/" << light.color.g / 255.0f << "/" << light.color.b / 255.0f; BOOST_LOG_TRIVIAL(debug) << " - Specular Fade: " << light.specularFade; BOOST_LOG_TRIVIAL(debug) << " - Specular Intensity: " << light.specularIntensity; BOOST_LOG_TRIVIAL(debug) << " - Inner: " << light.r_inner; BOOST_LOG_TRIVIAL(debug) << " - Outer: " << light.r_outer; BOOST_LOG_TRIVIAL(debug) << " - Intensity: " << light.intensity; } for( const RoomStaticMesh& sm : this->staticMeshes ) { auto idx = level.findStaticMeshIndexById(sm.meshId); BOOST_ASSERT(idx >= 0); BOOST_ASSERT(static_cast<size_t>(idx) < staticMeshes.size()); auto subNode = std::make_shared<gameplay::Node>(""); subNode->setDrawable(staticMeshes[idx]); subNode->setLocalMatrix(glm::translate(glm::mat4{1.0f}, (sm.position - position).toRenderSystem()) * glm::rotate(glm::mat4{1.0f}, util::auToRad(sm.rotation), glm::vec3{0,-1,0})); node->addChild(subNode); } node->setLocalMatrix(glm::translate(glm::mat4{1.0f}, position.toRenderSystem())); for( const Sprite& sprite : sprites ) { BOOST_ASSERT(sprite.vertex < vertices.size()); BOOST_ASSERT(sprite.texture < level.m_spriteTextures.size()); const SpriteTexture& tex = level.m_spriteTextures[sprite.texture]; auto spriteNode = std::make_shared<gameplay::Sprite>(game, textures[tex.texture], tex.right_side - tex.left_side + 1, tex.bottom_side - tex.top_side + 1, tex.buildSourceRectangle()); spriteNode->setBlendMode(gameplay::Sprite::BLEND_ADDITIVE); auto n = std::make_shared<gameplay::Node>(""); n->setDrawable(spriteNode); n->setLocalMatrix(glm::translate(glm::mat4{1.0f}, (vertices[sprite.vertex].position - core::TRCoordinates{0, tex.bottom_side / 2, 0}).toRenderSystem())); node->addChild(n); } // resultNode->addShadowVolumeSceneNode(); return node; }