Skip to content

Commit

Permalink
Implement attribute request
Browse files Browse the repository at this point in the history
  • Loading branch information
eliemichel committed Nov 10, 2020
1 parent 2878ecf commit a6445ef
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 62 deletions.
39 changes: 29 additions & 10 deletions intern/openmesheffect/blender/intern/mfxCallbacks.cpp
Expand Up @@ -211,17 +211,27 @@ OfxStatus Converter::blenderToMfx(OfxMeshHandle ofx_mesh) const

if (0 == blender_loose_edge_count) {
// reuse host buffer, kOfxMeshPropNoLooseEdge optimization
MFX_CHECK(mes->attributeDefine(
ofx_mesh, kOfxMeshAttribVertex, name, 3, kOfxMeshAttribTypeUByte, &vcolor_attrib));
MFX_CHECK(mes->attributeDefine(ofx_mesh,
kOfxMeshAttribVertex,
name,
3,
kOfxMeshAttribTypeUByte,
kOfxMeshAttribSemanticColor,
&vcolor_attrib));
MFX_CHECK(ps->propSetInt(vcolor_attrib, kOfxMeshAttribPropIsOwner, 0, 0));
MFX_CHECK(
ps->propSetPointer(vcolor_attrib, kOfxMeshAttribPropData, 0, (void *)&vcolor_data[0].r));
MFX_CHECK(ps->propSetInt(vcolor_attrib, kOfxMeshAttribPropStride, 0, sizeof(MLoopCol)));
}
else if (blender_loop_count > 0) {
// request new buffer to copy data from existing polys, fill default values for edges
MFX_CHECK(mes->attributeDefine(
ofx_mesh, kOfxMeshAttribVertex, name, 3, kOfxMeshAttribTypeUByte, &vcolor_attrib));
MFX_CHECK(mes->attributeDefine(ofx_mesh,
kOfxMeshAttribVertex,
name,
3,
kOfxMeshAttribTypeUByte,
kOfxMeshAttribSemanticColor,
&vcolor_attrib));
MFX_CHECK(ps->propSetInt(vcolor_attrib, kOfxMeshAttribPropIsOwner, 0, 1));
}
else {
Expand All @@ -243,17 +253,26 @@ OfxStatus Converter::blenderToMfx(OfxMeshHandle ofx_mesh) const

if (0 == blender_loose_edge_count) {
// reuse host buffer, kOfxMeshPropNoLooseEdge optimization
MFX_CHECK(mes->attributeDefine(
ofx_mesh, kOfxMeshAttribVertex, name, 2, kOfxMeshAttribTypeFloat, &uv_attrib));
MFX_CHECK(mes->attributeDefine(ofx_mesh,
kOfxMeshAttribVertex,
name,
2,
kOfxMeshAttribTypeFloat,
kOfxMeshAttribSemanticTextureCoordinate,
&uv_attrib));
MFX_CHECK(ps->propSetInt(uv_attrib, kOfxMeshAttribPropIsOwner, 0, 0));
MFX_CHECK(
ps->propSetPointer(uv_attrib, kOfxMeshAttribPropData, 0, (void *)&uv_data[0].uv[0]));
MFX_CHECK(ps->propSetPointer(uv_attrib, kOfxMeshAttribPropData, 0, (void *)&uv_data[0].uv[0]));
MFX_CHECK(ps->propSetInt(uv_attrib, kOfxMeshAttribPropStride, 0, sizeof(MLoopUV)));
}
else if (blender_loop_count > 0) {
// request new buffer to copy data from existing polys, fill default values for edges
MFX_CHECK(mes->attributeDefine(
ofx_mesh, kOfxMeshAttribVertex, name, 2, kOfxMeshAttribTypeFloat, &uv_attrib));
MFX_CHECK(mes->attributeDefine(ofx_mesh,
kOfxMeshAttribVertex,
name,
2,
kOfxMeshAttribTypeFloat,
kOfxMeshAttribSemanticTextureCoordinate,
&uv_attrib));
MFX_CHECK(ps->propSetInt(uv_attrib, kOfxMeshAttribPropIsOwner, 0, 1));
}
else {
Expand Down
1 change: 1 addition & 0 deletions intern/openmesheffect/host/intern/inputs.h
Expand Up @@ -41,6 +41,7 @@ struct OfxMeshInputStruct {
public:
const char *name;
OfxPropertySetStruct properties;
OfxAttributeSetStruct requested_attributes; // not technically attributes, e.g. data info are not used
OfxMeshStruct mesh;
OfxHost *host; // weak pointer, do not deep copy
};
Expand Down
66 changes: 64 additions & 2 deletions intern/openmesheffect/host/intern/meshEffectSuite.cpp
Expand Up @@ -50,6 +50,7 @@ const OfxMeshEffectSuiteV1 gMeshEffectSuiteV1 = {
/* inputDefine */ inputDefine,
/* inputGetHandle */ inputGetHandle,
/* inputGetPropertySet */ inputGetPropertySet,
/* inputRequestAttribute */ inputRequestAttribute,
/* inputGetMesh */ inputGetMesh,
/* inputReleaseMesh */ inputReleaseMesh,
/* attributeDefine */ attributeDefine,
Expand All @@ -72,14 +73,20 @@ OfxStatus getParamSet(OfxMeshEffectHandle meshEffect, OfxParamSetHandle *paramSe

OfxStatus inputDefine(OfxMeshEffectHandle meshEffect,
const char *name,
OfxMeshInputHandle *input,
OfxPropertySetHandle *propertySet)
{
printf("Defining input '%s' on OfxMeshEffectHandle %p\n", name, meshEffect);
int i = meshEffect->inputs.ensure(name);
meshEffect->inputs.inputs[i]->host = meshEffect->host;
propSetPointer(
&meshEffect->inputs.inputs[i]->mesh.properties, kOfxMeshPropInternalData, 0, NULL);
*propertySet = &(meshEffect->inputs.inputs[i]->properties);
if (NULL != input) {
*input = meshEffect->inputs.inputs[i];
}
if (NULL != propertySet) {
*propertySet = &(meshEffect->inputs.inputs[i]->properties);
}
return kOfxStatOK;
}

Expand All @@ -105,6 +112,46 @@ OfxStatus inputGetPropertySet(OfxMeshInputHandle input, OfxPropertySetHandle *pr
return kOfxStatOK;
}

OfxStatus inputRequestAttribute(OfxMeshInputHandle input,
const char* attachment,
const char* name,
int componentCount,
const char* type,
const char* semantic,
int mandatory)
{
if (componentCount < 1 || componentCount > 4) {
return kOfxStatErrValue;
}
if (0 != strcmp(type, kOfxMeshAttribTypeInt) && 0 != strcmp(type, kOfxMeshAttribTypeFloat) &&
0 != strcmp(type, kOfxMeshAttribTypeUByte)) {
return kOfxStatErrValue;
}

if (0 != strcmp(semantic, kOfxMeshAttribSemanticTextureCoordinate) &&
0 != strcmp(semantic, kOfxMeshAttribSemanticNormal) &&
0 != strcmp(semantic, kOfxMeshAttribSemanticColor) &&
0 != strcmp(semantic, kOfxMeshAttribSemanticWeight)) {
return kOfxStatErrValue;
}

AttributeAttachment intAttachment = mfxToInternalAttribAttachment(attachment);
if (intAttachment == ATTR_ATTACH_INVALID) {
return kOfxStatErrBadIndex;
}

int i = input->requested_attributes.ensure(intAttachment, name);

OfxPropertySetStruct *attributeProperties =
&input->requested_attributes.attributes[i]->properties;
propSetInt(attributeProperties, kOfxMeshAttribPropComponentCount, 0, componentCount);
propSetString(attributeProperties, kOfxMeshAttribPropType, 0, type);
propSetString(attributeProperties, kOfxMeshAttribPropSemantic, 0, semantic);
propSetInt(attributeProperties, kMeshAttribRequestPropMandatory, 0, mandatory);

return kOfxStatOK;
}

OfxStatus inputGetMesh(OfxMeshInputHandle input,
OfxTime time,
OfxMeshHandle *meshHandle,
Expand All @@ -124,18 +171,21 @@ OfxStatus inputGetMesh(OfxMeshInputHandle input,
kOfxMeshAttribPointPosition,
3,
kOfxMeshAttribTypeFloat,
NULL,
NULL);
attributeDefine(inputMeshHandle,
kOfxMeshAttribVertex,
kOfxMeshAttribVertexPoint,
1,
kOfxMeshAttribTypeInt,
NULL,
NULL);
attributeDefine(inputMeshHandle,
kOfxMeshAttribFace,
kOfxMeshAttribFaceCounts,
1,
kOfxMeshAttribTypeInt,
NULL,
NULL);

// Call internal callback before actually getting data
Expand Down Expand Up @@ -195,16 +245,27 @@ OfxStatus attributeDefine(OfxMeshHandle meshHandle,
const char *name,
int componentCount,
const char *type,
const char *semantic,
OfxPropertySetHandle *attributeHandle)
{
if (componentCount < 1 || componentCount > 4) {
return kOfxStatErrValue;
}
if (0 != strcmp(type, kOfxMeshAttribTypeInt) && 0 != strcmp(type, kOfxMeshAttribTypeFloat) &&
if (0 != strcmp(type, kOfxMeshAttribTypeInt) &&
0 != strcmp(type, kOfxMeshAttribTypeFloat) &&
0 != strcmp(type, kOfxMeshAttribTypeUByte)) {
return kOfxStatErrValue;
}

if (NULL != semantic) {
if (0 != strcmp(semantic, kOfxMeshAttribSemanticTextureCoordinate) &&
0 != strcmp(semantic, kOfxMeshAttribSemanticNormal) &&
0 != strcmp(semantic, kOfxMeshAttribSemanticColor) &&
0 != strcmp(semantic, kOfxMeshAttribSemanticWeight)) {
return kOfxStatErrValue;
}
}

AttributeAttachment intAttachment = mfxToInternalAttribAttachment(attachment);
if (intAttachment == ATTR_ATTACH_INVALID) {
return kOfxStatErrBadIndex;
Expand All @@ -216,6 +277,7 @@ OfxStatus attributeDefine(OfxMeshHandle meshHandle,
propSetPointer(attributeProperties, kOfxMeshAttribPropData, 0, NULL);
propSetInt(attributeProperties, kOfxMeshAttribPropComponentCount, 0, componentCount);
propSetString(attributeProperties, kOfxMeshAttribPropType, 0, type);
propSetString(attributeProperties, kOfxMeshAttribPropSemantic, 0, semantic);
propSetInt(attributeProperties, kOfxMeshAttribPropIsOwner, 0, 1);

if (attributeHandle) {
Expand Down
9 changes: 9 additions & 0 deletions intern/openmesheffect/host/intern/meshEffectSuite.h
Expand Up @@ -38,12 +38,20 @@ OfxStatus getPropertySet(OfxMeshEffectHandle meshEffect, OfxPropertySetHandle *p
OfxStatus getParamSet(OfxMeshEffectHandle meshEffect, OfxParamSetHandle *paramSet);
OfxStatus inputDefine(OfxMeshEffectHandle meshEffect,
const char *name,
OfxMeshInputHandle *input,
OfxPropertySetHandle *propertySet);
OfxStatus inputGetHandle(OfxMeshEffectHandle meshEffect,
const char *name,
OfxMeshInputHandle *input,
OfxPropertySetHandle *propertySet);
OfxStatus inputGetPropertySet(OfxMeshInputHandle input, OfxPropertySetHandle *propHandle);
OfxStatus inputRequestAttribute(OfxMeshInputHandle input,
const char *attachment,
const char *name,
int componentCount,
const char *type,
const char *semantic,
int mandatory);
OfxStatus inputGetMesh(OfxMeshInputHandle input,
OfxTime time,
OfxMeshHandle *meshHandle,
Expand All @@ -56,6 +64,7 @@ OfxStatus attributeDefine(OfxMeshHandle meshHandle,
const char *name,
int componentCount,
const char *type,
const char *semantic,
OfxPropertySetHandle *attributeHandle);
OfxStatus meshGetAttribute(OfxMeshHandle meshHandle,
const char *attachment,
Expand Down
2 changes: 2 additions & 0 deletions intern/openmesheffect/host/intern/properties.cpp
Expand Up @@ -185,7 +185,9 @@ bool OfxPropertySetStruct::check_property_context(PropertySetContext context, Pr
(0 == strcmp(property, kOfxMeshAttribPropStride) && type == PROP_TYPE_INT) ||
(0 == strcmp(property, kOfxMeshAttribPropComponentCount) && type == PROP_TYPE_INT) ||
(0 == strcmp(property, kOfxMeshAttribPropType) && type == PROP_TYPE_STRING) ||
(0 == strcmp(property, kOfxMeshAttribPropSemantic) && type == PROP_TYPE_STRING) ||
(0 == strcmp(property, kOfxMeshAttribPropIsOwner) && type == PROP_TYPE_INT) ||
(0 == strcmp(property, kMeshAttribRequestPropMandatory) && type == PROP_TYPE_INT) ||
false);
case PropertySetContext::ActionIdentityIn:
return (
Expand Down
1 change: 1 addition & 0 deletions intern/openmesheffect/host/intern/propertySuite.cpp
Expand Up @@ -69,6 +69,7 @@ OfxStatus propSetString(OfxPropertySetHandle properties,
return kOfxStatErrBadIndex;
}
int i = properties->ensure_property(property);
// FIXME: there is an obvious problem here for prop values that are not global strings...
properties->properties[i]->value[index].as_const_char = value;
return kOfxStatOK;
}
Expand Down
4 changes: 4 additions & 0 deletions intern/openmesheffect/host/ofxExtras.h
Expand Up @@ -65,3 +65,7 @@ typedef OfxStatus (*BeforeMeshReleaseCbFunc)(OfxHost*, OfxMeshHandle);

typedef OfxStatus (*BeforeMeshGetCbFunc)(OfxHost*, OfxMeshHandle);

/**
* Internal property on attributes that are used to store attribute requests
*/
#define kMeshAttribRequestPropMandatory "MeshAttribRequestPropMandatory"

0 comments on commit a6445ef

Please sign in to comment.