示例#1
0
文件: r1c.c 项目: ShaneRyanKelly/r1d
//-----------------------------------------
int factorList(int left)
{                   
    int right, temp, termVal, result;
	char temp1[MAX], temp2[MAX];
                    
    switch(currentToken -> kind)
    {
      case TIMES:
        consume(TIMES);
        right = factor();
        if (isConstant(left) && isConstant(right))
		{
			result = atoi(dwValue[left]) * atoi(dwValue[right]);		
			if (result >= 0)
			{
				sprintf(temp1, "@%d", result);
				sprintf(temp2, "%d", result);
				temp = enter(temp1, temp2, FALSE);
			}
			else
			{
				sprintf(temp1, "@_%d", result);
				sprintf(temp2, "%d", result);
				temp = enter(temp1, temp2, FALSE);
			}
		}
		else
		{
			temp = mult(left, right);
		}
        termVal = factorList(temp);
        return termVal;
		break;
      case PLUS:
	  case MINUS:
      case RIGHTPAREN:
      case SEMICOLON:
        ;
        return left;
		break;
      default:
        displayErrorLoc();
        printf("Scanning %s, expecting op, \")\", or \";\"\n",
           currentToken -> image);
        abend();
        return -1;
    }
}
示例#2
0
void Value::toLLVMValue(Builder *builder) {
	if (isConstant()) {
		mValue = builder->llvmValue(constant());
		mConstant = ConstantValue();
		mType = tNormalValue;
	}
}
示例#3
0
void TypeCompiler::visitSimpleTypeSpecifier(SimpleTypeSpecifierAST *node)
{
  if (const ListNode<std::size_t> *it = node->integrals)
    {
      it = it->toFront();
      const ListNode<std::size_t> *end = it;
      do
        {
          std::size_t token = it->element;
          // FIXME
          m_type.push_back(token_name(m_session->token_stream->kind(token)));
          it = it->next;
        }
      while (it != end);
    }
  else if (node->type_of)
    {
      // ### implement me
      m_type.push_back("typeof<...>");
    }

  visit(node->name);
  
  if (node->integrals) {
    m_realType = Type(m_type.join(" "), isConstant(), isVolatile());
    if (m_realType.name() == "unsigned") {
        // implicit int..
        m_realType.setName("unsigned int");
    }
    m_realType.setIsIntegral(true);
  } else {
    setRealType();
  }
}
示例#4
0
文件: r1c.c 项目: ShaneRyanKelly/r1d
//-----------------------------------------
// emit two-operand instruction, string, index args
// function overloading not supported by C
void emitInstructionSI(char *op, int index)
{   if (isConstant(index))
	{
		needsdw[index] = 1;
	}
    emitInstructionSS(op, symbol[index]); 
}
QString TypeInfo::toString() const
{
    QString tmp;

    tmp += m_qualifiedName.join("::");
    if (isConstant())
        tmp += QLatin1String(" const");

    if (isVolatile())
        tmp += QLatin1String(" volatile");

    if (indirections())
        tmp += QString(indirections(), QLatin1Char('*'));

    if (isReference())
        tmp += QLatin1Char('&');

    if (isFunctionPointer()) {
        tmp += QLatin1String(" (*)(");
        for (int i = 0; i < m_arguments.count(); ++i) {
            if (i != 0)
                tmp += QLatin1String(", ");

            tmp += m_arguments.at(i).toString();
        }
        tmp += QLatin1String(")");
    }

    foreach(QString elt, arrayElements()) {
        tmp += QLatin1String("[");
        tmp += elt;
        tmp += QLatin1String("]");
    }
示例#6
0
Func1& newCompositeFunction(Func1& f1, Func1& f2)
{
    if (isZero(f1)) {
        delete &f1;
        delete &f2;
        return *(new Const1(0.0));
    }
    if (isConstant(f1)) {
        delete &f2;
        return f1;
    }
    if (isPow(f1) && f1.c() == 1.0) {
        delete &f1;
        return f2;
    }
    if (isPow(f1) && f1.c() == 0.0) {
        delete &f1;
        delete &f2;
        return *(new Const1(1.0));
    }
    if (isPow(f1) && isPow(f2)) {
        doublereal c1c2 = f1.c() * f2.c();
        delete &f1;
        delete &f2;
        return *(new Pow1(c1c2));
    }
    return *(new Composite1(f1, f2));
}
示例#7
0
void TypeCompiler::setRealType()
{
    QString typeName = m_type.join("::");
    BasicTypeDeclaration* type = m_visitor->resolveType(typeName);
    Class* klass;
    Typedef* tdef;
    Enum* e;
    if ((klass = dynamic_cast<Class*>(type))) {
        m_realType = Type(klass, isConstant(), isVolatile());
    } else if ((tdef = dynamic_cast<Typedef*>(type))) {
        if (!ParserOptions::resolveTypedefs) {
            m_realType = Type(tdef);
        } else {
            m_realType = tdef->resolve();
        }
        if (isConstant()) m_realType.setIsConst(true);
        if (isVolatile()) m_realType.setIsVolatile(true);
    } else if ((e = dynamic_cast<Enum*>(type))) {
        m_realType = Type(e, isConstant(), isVolatile());
    } else {
        if (!m_templateArgs.isEmpty() && m_type.count() > 1) {
            typeName = QString();
            // only go to the one before the last - the rest will be added as template parameters to the type directly
            for (int i = 0; i < m_type.count() - 1; i++) {
                typeName += m_type[i];
                
                // do we have template parameters for this part?
                if (m_templateArgs.contains(i)) {
                    typeName += "< ";
                    for (int j = 0; j < m_templateArgs[i].count(); j++) {
                        if (j > 0) typeName += ", ";
                        typeName += m_templateArgs[i][j].toString();
                    }
                    typeName += " >";
                }
                typeName += "::";
            }
            typeName += m_type.last();
        }
        m_realType = Type(typeName, isConstant(), isVolatile());
    }
    
    // only add template parameters if they belong to the last part of a qualified type
    if (m_templateArgs.contains(m_type.count() - 1) && m_realType.templateArguments().isEmpty())
        m_realType.setTemplateArguments(m_templateArgs[m_type.count() - 1]);
}
示例#8
0
void Value::dump() const {
	if (!isValid()) {
		qDebug("Invalid Value");
		return;
	}
	qDebug() << "Value:" << mValueType->name() << (isReference() ? " (reference)" : "");
	if (isConstant())
		qDebug() << "\t = " << constant().valueInfo();
}
示例#9
0
/**
  * Returns true, if expression contains a variable.
  */
bool Calculator::expressionContainsVariable()
{
 bool result = false;

 for(int pos = 0; pos < m_ExpressionParts.size(); pos ++)
     if(isVariable(m_ExpressionParts[pos]) && !isConstant(m_ExpressionParts[pos]))
             result = true;

 return result;
}
示例#10
0
文件: token.cpp 项目: dvente/exp
bool Token::operator==(const Token &rhs) const {

    if (type == rhs.type) {
        if (type == VARIABLE)
            return variable == rhs.variable;
        else
            return !isConstant() || (number - rhs.number) < PRECISION;
    } else
        return false;
}
示例#11
0
void LinearExpression::print(std::ostream & out) const {
  std::map<RoseVariable, int>::const_iterator it;
  out << "(";
  for (it = map.begin(); it != map.end(); it++) {
    if (it != map.begin()) out << ") + (";

    if (isConstant(it->first)) out << it->second;
    else out << it->second << " * " << it->first.getString();
  } 
  out << ")";
}
示例#12
0
文件: ast.hpp 项目: bsurmanski/wlc
 virtual int64_t asInteger() {
     if(isConstant()) {
         VariableDeclaration *vdecl = id->getDeclaration()->variableDeclaration();
         if(vdecl && vdecl->value) {
             return vdecl->value->asInteger();
         }
     } else {
         emit_message(msg::ERROR, "attempt to convert non-const identifier to int", loc);
     }
     return 0;
 }
示例#13
0
文件: r1c.c 项目: ShaneRyanKelly/r1d
//-----------------------------------------
int isldcConstant(int index)
{
   int value;
   if (isConstant(index))
   {
      value = atoi(dwValue[index]);
      if (value >= 0 && value < 4096)
         return TRUE;
   }
   return FALSE;
}
示例#14
0
 // Increase iterator
 void increment() {
     if (cur != end) {
         _next(cur);
         if (cur != end) {
             for (auto it = begin; it != cur; ++it) {
                 // In order to avoid duplicates, we call increment() again if `cur->base` has already been iterated
                 if ((not it->isConstant()) and it->base == cur->base) {
                     increment();
                     break;
                 }
             }
         }
     }
 }
示例#15
0
void aiPoints::updateSummary()
{
    auto points = m_schema.getPositionsProperty();
    auto velocities = m_schema.getVelocitiesProperty();
    auto ids = m_schema.getIdsProperty();

    m_summary.has_points = points.valid() && points.getNumSamples() > 0;
    if (m_summary.has_points)
        m_summary.constant_points = points.isConstant();

    m_summary.has_velocities = velocities.valid() && velocities.getNumSamples() > 0;
    if (m_summary.has_velocities)
        m_summary.constant_velocities = velocities.isConstant();

    m_summary.has_ids = ids.valid() && ids.getNumSamples() > 0;
    if (m_summary.has_ids) {
        m_summary.constant_ids = ids.isConstant();
        if (m_summary.constant_ids && getConfig().interpolate_samples && !m_summary.constant_points) {
            m_summary.interpolate_points = true;
            m_summary.has_velocities = true;
            m_summary.compute_velocities = true;
        }
    }
}
示例#16
0
Func1& newPlusConstFunction(Func1& f, doublereal c)
{
    if (c == 0.0) {
        return f;
    }
    if (isConstant(f)) {
        doublereal cc = f.c() + c;
        delete &f;
        return *(new Const1(cc));
    }
    if (f.ID() == PlusConstantFuncType) {
        f.setC(f.c() + c);
        return f;
    }
    return *(new PlusConstant1(f, c));
}
示例#17
0
文件: parsetree.cpp 项目: 8l/rose
std::string sageExpToIslAff(SgExpression * exp) {
  std::vector<std::pair<RoseVariable, int> > lin_exp;
  PolyhedricAnnotation::translateLinearExpression(exp, lin_exp);
  std::ostringstream aff;
  std::vector<std::pair<RoseVariable, int> >::iterator it = lin_exp.begin();
  while (it != lin_exp.end()) {
    if (isConstant(it->first))
      aff << it->second;
    else
      aff << it->second << "*" << it->first.getString();
    it++;
    if (it != lin_exp.end())
      aff << " + ";
  }
  return aff.str();
}
示例#18
0
template<class U, class M> void SharedObject<U, M>::decRef()
{
    if (_Payload::getOID() == 0x00FFFFFF || isConstant()) { // object has not been sent yet: it has not been smart pointed by the cache: treat as a normal object.
        _Object::decRef();
    } else {
        int32_t ref_count = --this->refCount;

        switch (ref_count) {
        case 1:
            module::Node::Get()->markUnused(this);
            break;

        case 0:
            delete this;
            break;
        }
    }
}
SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
                                         const SkPaint& paint,
                                         const SkMatrix& ctm,
                                         SkArenaAlloc* alloc) {
    SkColorSpace* dstCS = dst.colorSpace();
    SkPM4f paintColor = SkPM4f_from_SkColor(paint.getColor(), dstCS);
    auto shader = as_SB(paint.getShader());

    SkRasterPipeline_<256> shaderPipeline;
    if (!shader) {
        // Having no shader makes things nice and easy... just use the paint color.
        shaderPipeline.append_uniform_color(alloc, paintColor);
        bool is_opaque    = paintColor.a() == 1.0f,
             is_constant  = true;
        return SkRasterPipelineBlitter::Create(dst, paint, alloc,
                                               shaderPipeline, nullptr,
                                               is_opaque, is_constant);
    }

    bool is_opaque    = shader->isOpaque() && paintColor.a() == 1.0f;
    bool is_constant  = shader->isConstant();

    // Check whether the shader prefers to run in burst mode.
    if (auto* burstCtx = shader->makeBurstPipelineContext(
        SkShaderBase::ContextRec(paint, ctm, nullptr, SkShaderBase::ContextRec::kPM4f_DstType,
                                 dstCS), alloc)) {
        return SkRasterPipelineBlitter::Create(dst, paint, alloc,
                                               shaderPipeline, burstCtx,
                                               is_opaque, is_constant);
    }

    if (shader->appendStages(&shaderPipeline, dstCS, alloc, ctm, paint)) {
        if (paintColor.a() != 1.0f) {
            shaderPipeline.append(SkRasterPipeline::scale_1_float,
                                  alloc->make<float>(paintColor.a()));
        }
        return SkRasterPipelineBlitter::Create(dst, paint, alloc, shaderPipeline, nullptr,
                                               is_opaque, is_constant);
    }

    // The shader has opted out of drawing anything.
    return alloc->make<SkNullBlitter>();
}
示例#20
0
void MLSignal::dump(std::ostream& s, int verbosity) const
{
	s << "signal @ " << std::hex << this << std::dec << " [" << mWidth*mHeight*mDepth << " frames] : sum " << getSum() << "\n";
	
	int w = mWidth;
	int h = mHeight;
	const MLSignal& f = *this;
	if(verbosity > 0)
	{
		if(isConstant())
		{
			s << "constant " << mDataAligned[0] << "\n";
		}
		else if(is2D())
		{
			s << std::setprecision(4);
			for (int j=0; j<h; ++j)
			{
				s << j << " | ";
				for(int i=0; i<w; ++i)
				{
					s << f(i, j) << " ";
				}
				s << "\n";
			}
		}
		else
		{
			s << std::setprecision(5);
			for (int i=0; i<w; ++i)
			{
                if(verbosity > 1)
                {
                    s << "[" << i << "]";
                }
                s << mDataAligned[i] << " ";
			}
			s << "\n";
		}
	}
}
示例#21
0
void File_Creator::print_OperatorOperand(EquationData *equation, char *in, int *operand_count){
	
	if((!equation->getOperands()->contains(in) || isConstant(in)) && (strchr(in,'[')==NULL)){
		if(strcmp(in,LN)==0){
			outCppFile<<"log";
		}
		else if(strcmp(in,LOG10)==0){
			outCppFile<<"log10";
		}
		else if(strcmp(in,"&")==0){
			outCppFile<<"&&";
		}
		else{
			outCppFile<<in;
		}
	}
	else{
		(*operand_count)++;
		outCppFile<<"(*(in_list.getNextItem()))";
	}
}
示例#22
0
文件: absint.c 项目: jkeiren/muCRL
ATerm termAbstraction(ATerm term, ATerm dstSort){
	ATerm newCons;
	AFun singTag;
	ATerm termSort, parSort;
	
	
	if(!(isVariable(term) || isParameter(term) || isConstant(term))){
		term = funcAbstraction(term, dstSort);	
		
	}
	termSort = getTermSort(term);
	
	if(isLifted(dstSort)){
		if(isAbstracted(dstSort)){
			if(!isAbstracted(termSort)){
				if(!isLifted(termSort)){
					termSort = liftSort(termSort);
					term = createSingTerm(term, termSort);
				}
				term = createAlphaTerm(term, termSort);
			}
			else{
				if(!isLifted(termSort)){
					termSort = liftSort(abstractSort(termSort));
					term = createSingTerm(term, termSort);		
				}
			}
		}
		else{
			if(!isLifted(termSort)){
				termSort = liftSort(termSort);
				term = createSingTerm(term, termSort);		
			}
		}		
	}
	
	return term;
}
示例#23
0
void IRGenerator::accept(ArrayExpr& arrayExpr)
{
    FNTRACE();

    std::vector<Value*> values;
    for (size_t i = 0, e = arrayExpr.values().size(); i != e; ++i) {
        Value* element = codegen(arrayExpr.values()[i].get());
        values.push_back(element);
    }

    if (isConstant(values)) {
        std::vector<Constant*> constants;
        for (Value* value: values)
            constants.push_back(static_cast<Constant*>(value));

        result_ = get(constants);
    } else {
        // TODO: print line:col hint where this exact message occured.
        // via: reportError(arrayExpr, "Variable array elements not allowed.");
        reportError("Variable array elements not allowed.");
        result_ = nullptr;
    }
}
示例#24
0
// TODO SSE
void MLSignal::divide(const MLSignal& b)
{
	const bool ka = isConstant();
	const bool kb = b.isConstant();
	if (ka && kb)
	{
		setToConstant(mDataAligned[0] + b.mDataAligned[0]);
	}
	else 
	{
		const int n = min(mSize, b.getSize());
		if (ka && !kb)
		{
			MLSample fa = mDataAligned[0];
			for(int i = 0; i < n; ++i)
			{
				mDataAligned[i] = fa / b[i];
			}
		}
		else if (!ka && kb)
		{
			MLSample fb = b[0];
			for(int i = 0; i < n; ++i)
			{
				mDataAligned[i] /= fb;
			}
		}
		else
		{
			for(int i = 0; i < n; ++i)
			{
				mDataAligned[i] /= b.mDataAligned[i];
			}
		}
		setConstant(false);
	}
}
示例#25
0
BabylonCamera::BabylonCamera(BabylonNode& babnode)
{
	auto node = babnode.fbxNode();
	std::string ansiName = node->GetName();
	name = std::wstring(ansiName.begin(), ansiName.end());
	id = getNodeId(node);
	auto parent = node->GetParent();
	if (parent) {
		parentId = getNodeId(parent);
	}
	auto camera = node->GetCamera();
	if (!camera) {
		return;
	}
	type = L"FreeCamera";
	auto targetNode = node->GetTarget();
	if (targetNode) {
		lockedTargetId = getNodeId(targetNode);
	}
	else {
		target = camera->InterestPosition.Get();
	}
	position = babnode.localTranslate();
	rotationQuaternion = babnode.localRotationQuat();
	
	fov = camera->FieldOfViewY * Euler2Rad;
	minZ = camera->FrontPlaneDistance.Get();
	maxZ = camera->BackPlaneDistance.Get();

	auto hasAnimStack = node->GetScene()->GetSrcObjectCount<FbxAnimStack>() > 0;
	if (!hasAnimStack){
		return;
	}
	auto animStack = node->GetScene()->GetSrcObject<FbxAnimStack>(0);
	FbxString animStackName = animStack->GetName();
	FbxTakeInfo* takeInfo = node->GetScene()->GetTakeInfo(animStackName);
	auto animTimeMode = GlobalSettings::Current().AnimationsTimeMode;
	auto animFrameRate = GlobalSettings::Current().AnimationsFrameRate();
	auto startFrame = takeInfo->mLocalTimeSpan.GetStart().GetFrameCount(animTimeMode);
	auto endFrame = takeInfo->mLocalTimeSpan.GetStop().GetFrameCount(animTimeMode);
	auto animLengthInFrame = endFrame - startFrame + 1;

	auto posAnim = std::make_shared<BabylonAnimation<babylon_vector3>>(BabylonAnimationBase::loopBehavior_Cycle, animFrameRate, L"position", L"position", true, 0, animLengthInFrame, true);
	auto rotAnim = std::make_shared<BabylonAnimation<babylon_vector4>>(BabylonAnimationBase::loopBehavior_Cycle, animFrameRate, L"rotation", L"rotation", true, 0, animLengthInFrame, true);
	auto targetAnim = std::make_shared<BabylonAnimation<babylon_vector3>>(BabylonAnimationBase::loopBehavior_Cycle, animFrameRate, L"target", L"target", true, 0, animLengthInFrame, true);
	
	for (auto ix = 0ll; ix < animLengthInFrame; ix++){
		FbxTime currTime;
		currTime.SetFrame(startFrame + ix, animTimeMode);

		babylon_animation_key<babylon_vector3> poskey;
		babylon_animation_key<babylon_vector4> rotkey;
		poskey.frame = ix;
		rotkey.frame = ix;

		poskey.values = babnode.localTranslate(currTime);
		rotkey.values = babnode.localRotationQuat(currTime);
		posAnim->appendKey(poskey);
		rotAnim->appendKey(rotkey);

		if (lockedTargetId.size() == 0){

			babylon_animation_key<babylon_vector3> targetKey;
			targetKey.frame = ix;
			targetKey.values = camera->InterestPosition.EvaluateValue(currTime);
			targetAnim->appendKey(targetKey);
		}
	}
	if (!posAnim->isConstant()){
		animations.push_back(posAnim);
	}
	if (!rotAnim->isConstant()){
		quatAnimations.push_back(rotAnim);
	}
	if (!targetAnim->isConstant()){
		animations.push_back(targetAnim);
	}
}
示例#26
0
BabylonMesh::BabylonMesh(BabylonNode* node) :
	BabylonAbstractMesh(node),
	_isEnabled(true),
	_isVisible(true),
	_billboardMode(0),
	_visibility(1),
	_skeletonId(-1),
	_pickable(true),
	_hasVertexAlpha(false),
	_checkCollision(false),
	_receiveShadows(false),
	_infiniteDistance(false),
	_autoAnimate(false),
	_autoAnimateFrom(0),
	_autoAnimateTo(0),
	_autoAnimateLoop(false),
	_showBoundingBox(false),
	_showSubMeshesBoundingBox(false),
	_applyFog(false),
	_alphaIndex(0)
{

	pivotMatrix.SetIdentity();
	auto fbxNode = node->fbxNode();
	
	std::string ansiName = fbxNode->GetName();
	name(std::wstring(ansiName.begin(), ansiName.end()));
	id(getNodeId(fbxNode));
	auto parent = fbxNode->GetParent();
	if (parent) {
		parentId(getNodeId(parent));
	}
	pivotMatrix = ConvertToBabylonCoordinateSystem( GetGeometryTransformation(fbxNode));

	auto animStack = fbxNode->GetScene()->GetSrcObject<FbxAnimStack>(0);
	FbxString animStackName = animStack->GetName();
	FbxTakeInfo* takeInfo = fbxNode->GetScene()->GetTakeInfo(animStackName);
	auto animTimeMode = GlobalSettings::Current().AnimationsTimeMode;
	auto animFrameRate = GlobalSettings::Current().AnimationsFrameRate();
	auto startFrame = takeInfo->mLocalTimeSpan.GetStart().GetFrameCount(animTimeMode);
	auto endFrame = takeInfo->mLocalTimeSpan.GetStop().GetFrameCount(animTimeMode);
	auto animLengthInFrame = endFrame - startFrame + 1;
	_visibility = static_cast<float>(node->fbxNode()->Visibility.Get());
	auto posAnim = std::make_shared<BabylonAnimation<babylon_vector3>>(BabylonAnimationBase::loopBehavior_Cycle, static_cast<int>(animFrameRate), L"position", L"position", true, 0, static_cast<int>(animLengthInFrame), true);
	auto rotAnim = std::make_shared<BabylonAnimation<babylon_vector4>>(BabylonAnimationBase::loopBehavior_Cycle, static_cast<int>(animFrameRate), L"rotationQuaternion", L"rotationQuaternion", true, 0, static_cast<int>(animLengthInFrame), true);
	auto scaleAnim = std::make_shared<BabylonAnimation<babylon_vector3>>(BabylonAnimationBase::loopBehavior_Cycle, static_cast<int>(animFrameRate), L"scaling", L"scaling", true, 0, static_cast<int>(animLengthInFrame), true);
	auto visibilityAnim = std::make_shared<BabylonAnimation<float>>(BabylonAnimationBase::loopBehavior_Cycle, static_cast<int>(animFrameRate), L"visibility", L"visibility", true, 0, static_cast<int>(animLengthInFrame), true);
	auto mesh = fbxNode->GetMesh();
	_isVisible = fbxNode->Show.Get();
	
	auto rotCurveNode = fbxNode->LclRotation.GetCurveNode();
	auto translateCurveNode = fbxNode->LclTranslation.GetCurveNode();
	auto scalingCurveNode = fbxNode->LclScaling.GetCurveNode();
	auto visibilityCurveNode = fbxNode->Visibility.GetCurveNode();
	if (rotCurveNode || translateCurveNode || scalingCurveNode) {
		for (auto ix = 0; ix < animLengthInFrame; ix++) {
			FbxTime currTime;
			currTime.SetFrame(startFrame + ix, animTimeMode);

			babylon_animation_key<babylon_vector3> poskey;
			babylon_animation_key<babylon_vector4> rotkey;
			babylon_animation_key<babylon_vector3> scalekey;
			poskey.frame = ix;
			rotkey.frame = ix;
			scalekey.frame = ix;
			auto currTransform = node->GetLocal(currTime);
			poskey.values = currTransform.translation();
			rotkey.values = currTransform.rotationQuaternion();
			scalekey.values = currTransform.scaling();
			posAnim->appendKey(poskey);
			rotAnim->appendKey(rotkey);
			scaleAnim->appendKey(scalekey);


		}
	}
	if (visibilityCurveNode) {
		for (auto ix = 0; ix < animLengthInFrame; ix++) {
			FbxTime currTime;
			currTime.SetFrame(startFrame + ix, animTimeMode);

			babylon_animation_key<float> visibilityKey;

			visibilityKey.frame = ix;

			visibilityKey.values = static_cast<float>(node->fbxNode()->Visibility.EvaluateValue(currTime));

			visibilityAnim->appendKey(visibilityKey);


		}
	}
	
	if (!posAnim->isConstant()){
		animations.push_back(posAnim);
	}
	if (!rotAnim->isConstant()){
		animations.push_back(rotAnim);
	}
	if (!scaleAnim->isConstant()){
		animations.push_back(scaleAnim);
	}
	if (!visibilityAnim->isConstant()) {
		animations.push_back(visibilityAnim);
	}
	if (!mesh) {
		return;
	}
	if (mesh->GetPolygonCount() == 0){
		return;
	}

	_receiveShadows =  mesh->ReceiveShadow.Get();
	FbxGeometryConverter conv(mesh->GetFbxManager());
	conv.ComputePolygonSmoothingFromEdgeSmoothing(mesh);
	if (!mesh->IsTriangleMesh()) {
		mesh = (FbxMesh*) conv.Triangulate(mesh, true);
	}


	mesh->RemoveBadPolygons();
	mesh->GenerateNormals();

	FbxStringList uvSetNameList;
	mesh->GetUVSetNames(uvSetNameList);
	std::vector<std::string> uniqueUVSets;

	int uvCount = uvSetNameList.GetCount();
	for (int i = 0; i < uvCount; ++i) {
		std::string value = uvSetNameList.GetStringAt(i);
		if (std::find(uniqueUVSets.begin(), uniqueUVSets.end(), value) == uniqueUVSets.end()) {
			uniqueUVSets.push_back(value);
		}
	}
	uvsets = uniqueUVSets;
	bool hasUv = uniqueUVSets.size() > 0;
	bool hasUv2 = uniqueUVSets.size() > 1;
	bool hasUv3 = uniqueUVSets.size() > 2;
	bool hasUv4 = uniqueUVSets.size() > 3;
	bool hasUv5 = uniqueUVSets.size() > 4;
	bool hasUv6 = uniqueUVSets.size() > 5;
	std::string uvSetName;
	std::string uv2SetName;
	std::string uv3SetName;
	std::string uv4SetName;
	std::string uv5SetName;
	std::string uv6SetName;
	if (hasUv) {
		uvSetName = uniqueUVSets[0];
	}
	if (hasUv2) {
		uv2SetName = uniqueUVSets[1];
	}
	if (hasUv3) {
		uv3SetName = uniqueUVSets[2];
	}
	if (hasUv4) {
		uv4SetName = uniqueUVSets[3];
	}
	if (hasUv5) {
		uv5SetName = uniqueUVSets[4];
	}
	if (hasUv6) {
		uv6SetName = uniqueUVSets[5];
	}
	auto colors = mesh->GetElementVertexColor();
	FbxLayerElement::EMappingMode colorMappingMode;
	FbxLayerElement::EReferenceMode colorReferenceMode;
	if (colors) {
		colorMappingMode = colors->GetMappingMode();
		colorReferenceMode = colors->GetReferenceMode();
	}
	auto normals = mesh->GetElementNormal();
	FbxGeometryElementUV* uvs = nullptr;
	FbxGeometryElementUV* uvs2 = nullptr;
	FbxGeometryElementUV* uvs3 = nullptr;
	FbxGeometryElementUV* uvs4 = nullptr;
	FbxGeometryElementUV* uvs5 = nullptr;
	FbxGeometryElementUV* uvs6 = nullptr;
	FbxLayerElement::EMappingMode uvsMappingMode;
	FbxLayerElement::EReferenceMode uvsReferenceMode;
	FbxLayerElement::EMappingMode uvs2MappingMode;
	FbxLayerElement::EReferenceMode uvs2ReferenceMode;
	FbxLayerElement::EMappingMode uvs3MappingMode;
	FbxLayerElement::EReferenceMode uvs3ReferenceMode;
	FbxLayerElement::EMappingMode uvs4MappingMode;
	FbxLayerElement::EReferenceMode uvs4ReferenceMode;
	FbxLayerElement::EMappingMode uvs5MappingMode;
	FbxLayerElement::EReferenceMode uvs5ReferenceMode;
	FbxLayerElement::EMappingMode uvs6MappingMode;
	FbxLayerElement::EReferenceMode uvs6ReferenceMode;
	if (hasUv) {
		uvs = mesh->GetElementUV(uvSetName.c_str());
		uvsMappingMode = uvs->GetMappingMode();
		uvsReferenceMode = uvs->GetReferenceMode();
	}
	if (hasUv2) {
		uvs2 = mesh->GetElementUV(uv2SetName.c_str());
		uvs2MappingMode = uvs2->GetMappingMode();
		uvs2ReferenceMode = uvs2->GetReferenceMode();
	}
	if (hasUv3) {
		uvs3 = mesh->GetElementUV(uv3SetName.c_str());
		uvs3MappingMode = uvs3->GetMappingMode();
		uvs3ReferenceMode = uvs3->GetReferenceMode();
	}
	if (hasUv4) {
		uvs4 = mesh->GetElementUV(uv4SetName.c_str());
		uvs4MappingMode = uvs4->GetMappingMode();
		uvs4ReferenceMode = uvs4->GetReferenceMode();
	}
	if (hasUv5) {
		uvs5 = mesh->GetElementUV(uv5SetName.c_str());
		uvs5MappingMode = uvs5->GetMappingMode();
		uvs5ReferenceMode = uvs5->GetReferenceMode();
	}
	if (hasUv6) {
		uvs6 = mesh->GetElementUV(uv6SetName.c_str());
		uvs6MappingMode = uvs6->GetMappingMode();
		uvs6ReferenceMode = uvs6->GetReferenceMode();
	}

	auto normalMappingMode = normals->GetMappingMode();
	auto normalReferenceMode = normals->GetReferenceMode();
	std::vector<SubmeshData> submeshes;

	auto materialCount = node->fbxNode()->GetMaterialCount();
	if (materialCount == 0) {
		materialCount = 1;
	}
	submeshes.resize(materialCount);
	auto baseLayer = mesh->GetLayer(0);
	auto materials = baseLayer->GetMaterials();
	FbxLayerElement::EMappingMode materialMappingMode = materials ?
		materials->GetMappingMode() : FbxLayerElement::eByPolygon;

	// extract deformers
	SkinInfo skinInfo(fbxNode);
	if (skinInfo.hasSkin()){
		associatedSkeleton = std::make_shared<BabylonSkeleton>();
		skinInfo.buildBabylonSkeleton(*associatedSkeleton);
	}

	auto triangleCount = mesh->GetPolygonCount();
	for (int triangleIndex = 0; triangleIndex < triangleCount; ++triangleIndex) {

		int materialIndex = 0;
		if (materialCount > 0 && materials) {
			switch (materialMappingMode) {
			case FbxLayerElement::eAllSame:
				materialIndex = materials->GetIndexArray().GetAt(0);
				break;
			case FbxLayerElement::eByPolygon:
				materialIndex = materials->GetIndexArray().GetAt(triangleIndex);
			}
		}

		auto& submesh = submeshes[materialIndex];
		triangle t;
		for (int cornerIndex = 0; cornerIndex < 3; ++cornerIndex) {
			auto controlPointIndex = mesh->GetPolygonVertex(triangleIndex, cornerIndex);
			auto vertexIndex = triangleIndex * 3 + cornerIndex;
			auto position = mesh->GetControlPoints()[controlPointIndex];
			position[2] = -position[2];

			BabylonVertex v;
			v.position = position;
			if (normals) {
				int normalMapIndex = (normalMappingMode == FbxLayerElement::eByControlPoint) ?
				controlPointIndex : vertexIndex;
				int normalValueIndex = (normalReferenceMode == FbxLayerElement::eDirect) ?
				normalMapIndex : normals->GetIndexArray().GetAt(normalMapIndex);
				v.normal = normals->GetDirectArray().GetAt(normalValueIndex);
				v.normal.z = -v.normal.z;
			}
			if (colors) {
				int mappingIndex = (colorMappingMode == FbxLayerElement::eByControlPoint) ?
				controlPointIndex : vertexIndex;
				int valueIndex = (colorReferenceMode == FbxLayerElement::eDirect) ?
				mappingIndex : colors->GetIndexArray().GetAt(mappingIndex);
				v.color = colors->GetDirectArray().GetAt(valueIndex);
			}
			if (uvs) {
				int mappingIndex = (uvsMappingMode == FbxLayerElement::eByControlPoint) ?
				controlPointIndex : vertexIndex;
				int valueIndex = (uvsReferenceMode == FbxLayerElement::eDirect) ?
				mappingIndex : uvs->GetIndexArray().GetAt(mappingIndex);
				v.uv = uvs->GetDirectArray().GetAt(valueIndex);
				//v.uv.y = 1 - v.uv.y;
			}

			if (uvs2) {
				int mappingIndex = (uvs2MappingMode == FbxLayerElement::eByControlPoint) ?
					controlPointIndex : vertexIndex;
				int valueIndex = (uvs2ReferenceMode == FbxLayerElement::eDirect) ?
					mappingIndex : uvs2->GetIndexArray().GetAt(mappingIndex);
				v.uv2 = uvs2->GetDirectArray().GetAt(valueIndex);
			}
			if (uvs3) {
				int mappingIndex = (uvs3MappingMode == FbxLayerElement::eByControlPoint) ?
					controlPointIndex : vertexIndex;
				int valueIndex = (uvs3ReferenceMode == FbxLayerElement::eDirect) ?
					mappingIndex : uvs3->GetIndexArray().GetAt(mappingIndex);
				v.uv3 = uvs3->GetDirectArray().GetAt(valueIndex);
			}
			if (uvs4) {
				int mappingIndex = (uvs4MappingMode == FbxLayerElement::eByControlPoint) ?
					controlPointIndex : vertexIndex;
				int valueIndex = (uvs4ReferenceMode == FbxLayerElement::eDirect) ?
					mappingIndex : uvs4->GetIndexArray().GetAt(mappingIndex);
				v.uv4 = uvs4->GetDirectArray().GetAt(valueIndex);
			}
			if (uvs5) {
				int mappingIndex = (uvs5MappingMode == FbxLayerElement::eByControlPoint) ?
					controlPointIndex : vertexIndex;
				int valueIndex = (uvs5ReferenceMode == FbxLayerElement::eDirect) ?
					mappingIndex : uvs5->GetIndexArray().GetAt(mappingIndex);
				v.uv5 = uvs5->GetDirectArray().GetAt(valueIndex);
			}
			if (uvs6) {
				int mappingIndex = (uvs6MappingMode == FbxLayerElement::eByControlPoint) ?
					controlPointIndex : vertexIndex;
				int valueIndex = (uvs6ReferenceMode == FbxLayerElement::eDirect) ?
					mappingIndex : uvs6->GetIndexArray().GetAt(mappingIndex);
				v.uv6 = uvs6->GetDirectArray().GetAt(valueIndex);
			}
			if (skinInfo.hasSkin()){
				auto& skinData = skinInfo.controlPointBoneIndicesAndWeights(controlPointIndex);
				for (auto boneix = 0; boneix < skinData.size()&&boneix<4; ++boneix){
					v.boneIndices[boneix] = skinData[boneix].index;
					v.boneWeights[boneix] = static_cast<float>(skinData[boneix].weight);
				}
				for (auto boneix = skinData.size(); boneix < 4; ++boneix){

					v.boneIndices[boneix] = skinInfo.bonesCount();
					v.boneWeights[boneix] = 0;
				}
			}
			auto foundVertex = submesh.knownVertices.find(v);
			if (foundVertex != submesh.knownVertices.end()) {
				//submesh.indices.push_back(foundVertex->second);
				t.indices[cornerIndex] = foundVertex->second;
			}
			else {
				auto index = static_cast<int>(submesh.vertices.size());
				submesh.vertices.push_back(v);
				//submesh.indices.push_back(index);
				submesh.knownVertices[v] = index;
				t.indices[cornerIndex] = index;
			}
		}
		if (submesh.knownTriangles.insert(t).second) {
			submesh.indices.push_back(t.indices[0]);
			submesh.indices.push_back(t.indices[1]);
			submesh.indices.push_back(t.indices[2]);
		}
		else {
			std::cout << "duplicate triangle found (and eliminated) in " << fbxNode->GetName() << std::endl;
		}

	}
	std::uint32_t vertexOffset = 0;

	for (auto matIndex = 0u; matIndex < submeshes.size(); ++matIndex) {
		auto& submesh = submeshes[matIndex];
		BabylonSubmesh babsubmesh;
		babsubmesh.indexCount = static_cast<int>(submesh.indices.size());
		babsubmesh.indexStart = static_cast<int>(_indices.size());
		babsubmesh.materialIndex = matIndex;
		babsubmesh.verticesCount = static_cast<int>(submesh.vertices.size());
		babsubmesh.verticesStart = static_cast<int>(_positions.size());
		for (auto& v : submesh.vertices) {
			_positions.push_back(v.position);
			if (normals) {
				_normals.push_back(v.normal);
			}
			if (colors) {
				_colors.push_back(v.color);
			}
			if (uvs) {
				_uvs.push_back(v.uv);
			}
			if (uvs2) {
				_uvs2.push_back(v.uv2);
			}
			if (uvs3) {
				_uvs3.push_back(v.uv3);
			}
			if (uvs4) {
				_uvs4.push_back(v.uv4);
			}
			if (uvs5) {
				_uvs5.push_back(v.uv5);
			}
			if (uvs6) {
				_uvs6.push_back(v.uv6);
			}
			if (skinInfo.hasSkin()){
				 float weight0 = v.boneWeights[0];
				 float weight1 = v.boneWeights[1];
				 float weight2 = v.boneWeights[2];
				 int bone0 = v.boneIndices[0];
				 int bone1 = v.boneIndices[1];
				 int bone2 = v.boneIndices[2];
				 int bone3 = v.boneIndices[3];
               
				_boneWeights.push_back(babylon_vector4( weight0, weight1, weight2, 1.0f - weight0 - weight1 - weight2));
                _boneIndices.push_back((bone3 << 24) | (bone2 << 16) | (bone1 << 8) | bone0);
			}
		}
		for (auto i : submesh.indices) {
			_indices.push_back(i + vertexOffset);
		}

		vertexOffset = static_cast<int>(_positions.size());
		_submeshes.push_back(babsubmesh);
	}



}
示例#27
0
void my_expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken)
{
	static char buf[20];
	snprintf(buf, sizeof buf, "CHOICE_%d", choice_count);
	choicestring = buf;
	if (!e) {
		fn(data, NULL, "y");
		return;
	}

	if (expr_compare_type(prevtoken, e->type) > 0)
	fn(data, NULL, "(");
	switch (e->type) {
	case E_SYMBOL:
		if (e->left.sym->name){
			if (isConstant(e->left.sym))
				fn(data, NULL, "'");
			fn(data, e->left.sym, e->left.sym->name);
			if (isConstant(e->left.sym))
				fn(data, NULL, "'");
		}else
			fn(data, NULL, choicestring);
		break;
	case E_NOT:
		fn(data, NULL, "!");
		my_expr_print(e->left.expr, fn, data, E_NOT);
		break;
	case E_EQUAL:
		if (e->left.sym->name){
			if (isConstant(e->left.sym))
				fn(data, NULL, "'");
			fn(data, e->left.sym, e->left.sym->name);
			if (isConstant(e->left.sym))
				fn(data, NULL, "'");
		}else
			fn(data, NULL, "<choice>");
		fn(data, NULL, "=");
		if (isConstant(e->right.sym))
			fn(data, NULL, "'");
		fn(data, e->right.sym, e->right.sym->name);
		if (isConstant(e->right.sym))
			fn(data, NULL, "'");
		break;
	case E_UNEQUAL:
		if (e->left.sym->name){
			if (isConstant(e->left.sym))
				fn(data, NULL, "'");
			fn(data, e->left.sym, e->left.sym->name);
			if (isConstant(e->left.sym))
				fn(data, NULL, "'");
		}else
			fn(data, NULL, "<choice>");
		fn(data, NULL, "!=");
		if (isConstant(e->right.sym))
			fn(data, NULL, "'");
		fn(data, e->right.sym, e->right.sym->name);
		if (isConstant(e->right.sym))
			fn(data, NULL, "'");
		break;
	case E_OR:
		my_expr_print(e->left.expr, fn, data, E_OR);
		fn(data, NULL, " || ");
		my_expr_print(e->right.expr, fn, data, E_OR);
		break;
	case E_AND:
		my_expr_print(e->left.expr, fn, data, E_AND);
		fn(data, NULL, " && ");
		my_expr_print(e->right.expr, fn, data, E_AND);
		break;
	case E_LIST:
		fn(data, e->right.sym, e->right.sym->name);
		if (e->left.expr) {
		fn(data, NULL, " ^ ");
		my_expr_print(e->left.expr, fn, data, E_LIST);
		}
		break;
	case E_RANGE:
		fn(data, NULL, "[");
		fn(data, e->left.sym, e->left.sym->name);
		fn(data, NULL, " ");
		fn(data, e->right.sym, e->right.sym->name);
		fn(data, NULL, "]");
		break;
	default:
		{
		char buf[32];
		sprintf(buf, "<unknown type %d>", e->type);
		fn(data, NULL, buf);
		break;
		}
	}
	if (expr_compare_type(prevtoken, e->type) > 0)
	fn(data, NULL, ")");
}
示例#28
0
/**
 * Indicate if this method was defined as a constant method
 * (using ::constant)
 *
 * @return .true if the method is defined as an attribute.
 *         .false otherwise.
 */
RexxObject *MethodClass::isConstantRexx( )
{
    return booleanObject(isConstant());
}
示例#29
0
文件: Value.cpp 项目: scrossuk/locic
		const locic::Constant& Value::constant() const {
			assert(isConstant());
			return impl_->constant;
		}
示例#30
0
bool Value::isValid() const {
	return mValueType != 0 && ((isConstant() ? mConstant.isValid() : false) || mType == tFunctionSelectorValueType || mType == tValueType || mValue);
}